Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim nmap which disables another nmap

Tags:

vim

keymapping

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?

like image 739
pksimba Avatar asked Jul 07 '26 10:07

pksimba


1 Answers

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

  • :help recursive_mapping
  • What is the difference between the remap, noremap, nnoremap and vnoremap mapping commands in Vim?
  • Recursive mappings - Vim Tips Wiki
  • Learn Vimscript the Hard Way - Chapter 5
like image 166
Enlico Avatar answered Jul 09 '26 04:07

Enlico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!