2

Once in visual line mode I'm looking for a way to move the selected area up and down in the file. Note I'm not looking to actually modify the content of the file in any way just moved the shaded (selected) region up and down one line.

1

You can move one side of the visual range using j and k as normal and use o to switch from one side to the other.

Thus, if you would like to move the whole range up or down in one key press, you can make mappings as follows:

xnoremap <up> koko
xnoremap <down> jojo

A slight refinement would be to respect the bottom and top of the buffer;

xnoremap <expr> <up> min([line('.'),line('v')]) > 1 ? 'koko' : ''
xnoremap <expr> <down> max([line('.'),line('v')]) < line('$') ? 'jojo' : ''

Further, if you would like to use counts,

xnoremap <expr> <up> min([line('.'),line('v')])
                 \ > v:count1 ? 'ko'.v:count1.'ko' : ''
xnoremap <expr> <down> max([line('.'),line('v')])
                 \ <= line('$')-v:count1 ? 'jo'.v:count1.'jo' : ''
  • Didn't know about the "o" command, thanks a bunch! – Sauhaarda Chowdhuri Jun 25 '18 at 3:31

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.