0

Coming from non-modal editors, I still get confused with e, w, b in Vim.

One feature I like about non-modal editors is jumping words by simply combining Ctrl with arrow. So I thought I just create a Vim equivalent using Ctrl+h instead of b and Ctrl+l instead of e. Both in visual and normal mode. It looks like there are no other shortcuts interfering by default.

Does anyone know how to change .vimrc to map the keys accordingly?

  • 1
    It's working here, can you try with nnoremap and vnoremap and have a look at vi.stackexchange.com/a/7723/1821 and vi.stackexchange.com/a/2004/1821 – nobe4 Jul 22 '16 at 10:22
  • yep, I tried and it is working in both normal/visual modes.. can you tell us how exactly it is going wrong? like what happens when you type them? did you source ~/.vimrc after making changes? you can close and open vim as well for changes to take effect – Sundeep Jul 22 '16 at 10:23
  • I did reload Vim. I also did source ~/.vimrc. When I hit ctrl+h or ctrl+l nothing happens, the cursor stays where it is. I just checked :map and it shows me this: <C-H> <C-W>h and <C-L> <C-W>l and more stuff. @spasic No, I don't need the arrow keys.. – Rotareti Jul 22 '16 at 10:32
  • can you try :nmap <C-h> b from within vim and see if it works? I suspect you'll have to debug using links given by @nobe4 – Sundeep Jul 22 '16 at 10:37
  • @spasic that works. I'll try a restart ;) brb. Edit: restart did not help.. – Rotareti Jul 22 '16 at 10:40
3

Found a solution. This works fine:

nnoremap <C-h> b
nnoremap <C-l> e
vnoremap <C-h> b
vnoremap <C-l> e
  • 1
    Unless you're remapping a <plug> map (often found in plugins) always use nnoremap and vnoremap. Maps (that are not *nore*) are recursive into other maps, and that becomes a mess very quickly. – grochmal Jul 22 '16 at 20:45

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