how to move a block or column of text
54,440
Solution 1
You should use blockwise visual mode (Ctrl+v). Then d to delete block, p or P to paste block.
Solution 2
Try the link.
Marking text (visual mode)
- v - start visual mode, mark lines, then do command (such as y-yank)
- V - start Linewise visual mode
- o - move to other end of marked area
- Ctrl+v - start visual block mode
- O - move to Other corner of block
- aw - mark a word
- ab - a () block (with braces)
- aB - a {} block (with brackets)
- ib - inner () block
- iB - inner {} block
- Esc - exit visual mode
Visual commands
- > - shift right
- < - shift left
- y - yank (copy) marked text
- d - delete marked text
- ~ - switch case
Cut and Paste
- yy - yank (copy) a line
- 2yy - yank 2 lines
- yw - yank word
- y$ - yank to end of line
- p - put (paste) the clipboard after cursor
- P - put (paste) before cursor
- dd - delete (cut) a line
- dw - delete (cut) the current word
- x - delete (cut) current character
Solution 3
One of the few useful command I learned at the beginning of learning VIM is :1,3 mo 5 This means move text line 1 through 3 to line 5.
Solution 4
- In VIM, press Ctrl+V to go in Visual Block mode
- Select the required columns with your arrow keys and press x to cut them in the buffer.
- Move cursor to row 1 column 9 and press P (thats capital P) in command mode.
- Press Ctrl+Shift+b to get in and out of it. (source)
Author by
David.Chu.ca
Updated on January 05, 2020Comments
-
David.Chu.ca over 4 years
I have the following text as a simple case:
... abc xxx 123 456 wer xxx 345 678676 ...
what I need to move a block of text xxx to another location:
... abc 123 xxx 456 wer 345 xxx 678676 ...
I think I use visual mode to block a column of text, what are the other commands to move the block to another location?