I have some key mappings for the block of code up and down

vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv

So I tried to do the same with H and L

vnoremap H <V
vnoremap L >V

It not actually what I want( Shift the code but still stay in visual mode).

  • You should modify your title to be more specific. By shift, you mean move blocks of text up and down, not left and right.
    – jdhao
    Commented Dec 22, 2021 at 5:18
  • Frankly I find it easier to push < and then . as needed. But I don’t use visual mode as often as perhaps you do
    – D. Ben Knoble
    Commented Dec 22, 2021 at 16:40
  • Possible duplicate: vi.stackexchange.com/q/8433/10604
    – D. Ben Knoble
    Commented Dec 22, 2021 at 16:42

1 Answer 1


If you are about shifting block of text left or right then :h gv you are using for the J and K does what you want: reselects previous visual selection:

xnoremap H <gv
xnoremap L >gv

Note, xnoremap instead of vnoremap is preferred unless you also want those mappings in SELECT mode too.

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