Edit: the below is a misunderstanding caused by assuming <cmd>
in nvim is the same as :
, which is not the case. Using :m '>+1<CR>
does work in nvim but <cmd>m '>+1<CR>
does not, likely because of some of the subtle differences in behavior. Please see comments for details.
I would comment on @Khelben's post but I don't have enough reputation to. Came across this post from googling how to move multiple lines in vim (I'm using neovim). Khelben's answer didn't work for me - I'm not sure if this is due to a :move
behavior change from older versions of vim (or to neovim), but :help :move
in neovim now specifies that a [range]
should be pre-pended to the move command specifying the range of lines to move. In a visual selection, this range is '<,'>
('<
start line of visual block selection, '>
end line of visual block selection).
> :[range]m[ove] {address} *:m* *:mo* *:move* *E134*
> Move the lines given by [range] to below the line
> given by {address}.
I was able to get Khelben's answer to work for me by modifying the mapping slightly from
" vnoremap <down> :m '>+1<CR>gv=gv
" vnoremap <up> :m '<-2<CR>gv=gv
" move [range] '<,'> to line at '>+1, then reselect visual block
vnoremap <down> :'<,'>m '>+1<CR>gv=gv
" move [range] '<,'> to line at '<-2, then reselect visual block
vnoremap <up> :'<,'>m '<-2<CR>gv=gv
Hope this helps anybody who would rather have a vanilla mapping set up rather than using a plugin.
]p
or[p
rather thanp
orP
. This way the block that you paste will be autoindented.