I've just made a little snipplet on my keybindings.vim to shift a hole block of code around. It works basically the same way I do it in the old fashioned manual way ( on normal mode, {V} to select the hole block on visual mode, then > and < to move through indentation, and :m+ and :m-2 to move down or up ).
The problem I'm getting is that it works only to move around through indentation (horizontally), but for vertical move, it does not work. I just can't find the reason, as doing exactly the same sequence manually (as I'm used to), it works like a charm.
First of all: I've tested the snipplet on Vim 7.2 (on Linux) and Vim 7.3 (on MacOS). Second: I know If I put a:
vnoremap < <gv
...and a:
vnoremap > >gv
...in my keymaps, I'll be able to move visual-selected blocks without loosing the visual selection... in spite of this, I'd like to get this working so I don't have to take care of the visual selection with a manual ESC {jV}k
Can anybody tell me what am I doing wrong? I thank you all in advance! Regards!
"============================================================================
"Ctrl + Shift + > [normal or insert mode] - move entire block around
"============================================================================
nnoremap <silent> <C-S-Right> :let savecur=getpos(".")<CR>{V}><CR>
\:call setpos('.', savecur)<CR>4l
inoremap <silent> <C-S-Right> <Esc>:let savecur=getpos(".")<CR>{V}><CR>
\:call setpos('.', sa开发者_运维百科vecur)<CR>5li
nnoremap <silent> <C-S-Left> :let savecur=getpos(".")<CR>{V}<<CR>
\:call setpos('.', savecur)<CR>4h
inoremap <silent> <C-S-Left> <Esc>:let savecur=getpos(".")<CR>{V}<<CR>
\:call setpos('.', savecur)<CR>3hi
nnoremap <silent> <C-S-Up> :let savecur=getpos(".")<CR>{V}:m-2<CR>
\:call setpos('.', savecur)<CR>k
inoremap <silent> <C-S-Up> <Esc>:let savecur=getpos(".")<CR>{V}:m-2<CR>
\:call setpos('.', savecur)<CR>ki
nnoremap <silent> <C-S-Down> :let savecur=getpos(".")<CR>{V}:m+<CR>
\:call setpos('.', savecur)<CR>j
inoremap <silent> <C-S-Down> <Esc>:let savecur=getpos(".")<CR>{V}:m+<CR>
\:call setpos('.', savecur)<CR>ji
"============================================================================
Change the :move
commands used in those mappings for moving a paragraph down
from :m+
to :m'>+
.
精彩评论