Search code examples
vimkeymapping

vim nmap which disables another nmap


In my .vimrc I have these lines

nmap :s :update<cr>
nmap <F5> :set number!<cr>

Without the former mapping, the latter works, otherwise it doesn't. Why is this the case?


Solution

  • The problem is that the second mapping begins in a way, :s in :set, that triggers the previous mapping.

    In general you should use non-recursive mappings, unless you have a reason to use recursive mappings.

    In this case, you have to use

    nnoremap :s :update<cr>
    nnoremap <F5> :set number!<cr>
    

    More info at