3 ms·
This is one of the biggest strengths of Vim imho. Defining new keybindings is so intuitive and flexible you wonder why it's usually done differently. With Vim
by alpaca128 5y ago
This is one of the biggest strengths of Vim imho. Defining new keybindings is so intuitive and flexible you wonder why it's usually done differently.
With Vim you basically just tell it to map any sequence of inputs to any other sequence of inputs. If you know how to do something in Vim you can define a keybinding for it. And because Vim is 100% controllable via the keyboard you can bind anything to a shortcut.
- ponyous 5y agoI can never remember what all those different maps do: ':map', ':map!', ':nmap', ':vmap', ':imap', ':cmap', ':smap', ':xmap', ':omap', ':lmap', etc. do. There are bunch of questions on StackOverflow about different mapping options so I wouldn't say it's intuitive at all.
- alpaca128 5y agoThe differences that actually matter are self explanatory: map is for all modes, imap for insert mode, nmap for normal mode and vmap for visual mode (& tmap for terminal mode in NeoVim). The rest can be safely ignored as far as I can tell. Little confession: I have no idea what e.g. the difference between "nmap" and "nnoremap" is. But after years of randomly mixing them in hundreds of bindings without a noticeable difference it doesn't seem to matter. Just use map, nmap, imap and vmap, avoid duplicates and everything will be fine imho.
- Omni5cience 5y agoYou're right, for most simple use cases it doesn't matter. But I once spent an hour on a weird bug that turned out to just be some plugin applying a map that I didn't know about and that I didn't know about map expansion. So I might be biased, but I think a loose understanding is helpful. The default behavior is to recursively expand and apply your mappings and "noremap" disables this recursion. For example if you do something like :map j k :map q j :noremap w j q is expanded to k, but w is expanded to j
- alpaca128 5y agoThanks for this example, now I get it. It never really clicked for me when I read explanations on SO etc.
- apocolyps6 5y agonnoremap is "non-recursive remap" since I think its possible to chain nmaps (`nmap A B, nmap B C` will map A to C)
- ptato 5y agoI find that I never want "map" functionality, so I do the opposite, always use "noremap".