Question

I use these keys to move a block of text (or entire line) to the left or the right:

Move block left:

nmap <C-A-Left> <<
vmap <C-A-Left> <gv

Move block right:

nmap <C-A-Right> >>
vmap <C-A-Right> >gv

But these commands can only move blocks or the entire line to the left or to the right.

I often have small selections of two or three words within a line which I want to move to the left or to the right. Does anyone know how to move a selection of text within a line using the Alt - Left and Alt - Right keys?

UPDATE:

As the above commands, I want to move the selection over the actual text p.e.

| | = selection

one |two three| four five six seven
one four |two three| five six seven
one four five |two three| six seven `

Was it helpful?

Solution

If you mean moving around (vs. "indenting within the line"), this is described in this Vim Tips Wiki page; use the following mappings:

:vnoremap <A-Right> lholhxp`[1v<Space>
:vnoremap <A-Left> hlohlxhP`[1v<Space>

Note that these are for :set selection=exclusive; if you use the default (inclusive), remove the trailing <Space> from the RHS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top