In Vim, is there a way to move an object / movement (word, character, visual selection, etc.) horizontally in a line by moving characters around it?

For example, I have the following line:

object     => "plaintext",

I want to move the word "object" to the right (so this is one place from "=>"), for example:

    object => "plaintext",

The only way I know this would be (starting at the beginning of the line): i <esc>ea4xor the equivalent from another starting location. I would like to do the same as for moving lines, but horizontally:

" Move lines up/down
nnoremap <Down> :m+<CR>==
nnoremap <Up> :m-2<CR>==
vnoremap <Down> :m '>+1<CR>gv=gv
vnoremap <Up> :m '<-2<CR>gv=gv
+4
source share
2 answers

Another way to simply do horizontal movement is:

  • If you have already selected the text you want to move:

    :vnoremap <A-S-l> xp`[v`]
    :vnoremap <A-S-h> xhhp`[v`]
    
  • , ( ). :

    :nnoremap <A-S-l> viwxp`[v`]
    :nnoremap <A-S-h> viwxhhp`[v`]
    
  • , ( ). :

    :inoremap <A-S-l> <Esc>viwxp`[v`]
    :inoremap <A-S-h> <Esc>viwxhhp`[v`]
    

:

  • : Alt + Shift + l
  • : Alt + Shift + h

, , , , .

, , .

+3

() () . , . , tabular ( Tabular.vim) vim-easy-align.

:

:Tabularize/=>/r1l1l1

exchange.vim, . exchange.vim

+5

Source: https://habr.com/ru/post/1607718/


All Articles