5

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?

7

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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