8

I am making a complex mapping that requires me to insert angle brackets (<and >) but I do not know how to escape them so Vim does not interpret them as special key-codes.

It seems like escaping them are not required if you do a simple mapping like:

nnoremap <leader>x yi<pppp

But my mapping looks more like this:

nnoremap <leader>x a<?<<cr>lyi</<<cr>a/<c-r>"><esc>

And I become really confused about all angle brackets. I also think that Vim might become confused.

Is there a way to escape angle brackets when making mappings in Vim?

1 Answer 1

11

You can do so with <lt> (see :h <lt>) :

nnoremap <leader>x a<lt>CR>

Will enter <CR> literaly, whereas :

nnoremap <leader>x a<CR>

Will execute <CR>

1
  • Thank you! Seven years later, I was trying to create a mapping to list my custom leader mappings and Vim was expanding <Leader> in the right-hand side of my mapping so it didn't work. Finally put together the right search terms to find this post, and <lt> is the literal I was looking for, I hadn't thought to check for an angle-bracket literal for angle brackets! Jun 13, 2022 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.