I have some movement utilities in my vim rc which helps me navigate in the file faster, but I would also like to use them when visual selecting. Here is the current key binding that I have: in ~/.vimrc

nnoremap <C-h> b
nnoremap <C-l> w
nnoremap <C-j> 5j
nnoremap <C-k> 5k
nnoremap <Tab> :call Tab() <CR>

function! Tab()
    let col = col(".")
    let line = line(".")
        normal! %
    if (col == col(".") && line == line("."))
        normal! $

Is there a way to visual select with these utilities?


Just add corresponding visual mode mappings:

vnoremap <C-h> b
vnoremap <C-l> w
vnoremap <C-j> 5j
vnoremap <C-k> 5k
vnoremap <Tab> :<c-u>call Tab()<CR>gv

Note that some extra work is needed for the <Tab> mapping in visual mode. Namely, clear the automatic visual boundary markers when entering :-command mode, then re-select the visual area after the function has been called.

  • :%s/vnore/xnore – romainl Aug 6 '16 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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