I started to use vim recently, but I miss the character/line selection methods from other text editors. By default vim maps
,
I've written this to be able to navigate using Alt+hjkl
(and friends) and select using Alt+HJLK
when both in insert, visual and normal mode.
So the same can be applied to normal arrow keys as well
let hjklfriends = ['h','j','k','l','w','e','b','W','E','B', 'n', 'N', 'y', 'Y', 'p', 'P']
" define if using alt (it works in neovim) or Escape key.
function! Meta(key)
if has('nvim')
return ""
else
return "" . a:key
endif
endfunction
execute 'noremap! ' . Meta('h') . ' '
execute 'noremap! ' . Meta('j') . ' '
execute 'noremap! ' . Meta('k') . ' '
execute 'noremap! ' . Meta('l') . ' '
execute 'noremap! ' . Meta('b') . ' '
execute 'noremap! ' . Meta('w') . ' '
execute 'noremap! ' . Meta('e') . ' '
for k in hjklfriends
execute 'imap ' . Meta(k) . ' ' . k
if k =~ '[a-z]'
execute 'imap ' . Meta(toupper(k)) . ' v' . k
execute 'vmap ' . Meta(toupper(k)) . ' ' . k
execute 'nmap ' . Meta(toupper(k)) . ' v' . k
endif
endfor