How do I create a custom key mapping?
Answer
:nnoremap key command
Explanation
The :nnoremap command creates a non-recursive normal mode mapping. It binds a key sequence to a command without allowing the mapping to trigger other mappings.
How it works
:nnoremapcreates a normal mode mapping (non-recursive):inoremapcreates an insert mode mapping:vnoremapcreates a visual mode mappingnoremapprevents the right side from triggering other maps
Example
nnoremap <leader>s :w<CR> " Quick save
nnoremap <C-n> :bnext<CR> " Next buffer
nnoremap <leader>/ :nohlsearch<CR> " Clear search
inoremap jk <Esc> " Exit insert mode
Tips
- Always use
noremapvariants to avoid recursive mapping issues :nmapshows existing normal mode mappings:nunmap keyremoves a mapping<silent>suppresses command echo:nnoremap <silent> ...- Test mappings with
:nnoremap keybefore adding to vimrc