How To Copy A Block Of Text In Vim
To copy a block of text in vim, there are mainly two ways.
- Using Vim Markers
- Copy using Vim visual mode
Copy Using Vim Markers
- Go to the starting line and press keys "ma" in quick succession
- Go the last line and press keys "mb"
- Now go to command mode by pressing ":" (colon)
- And type 'a,'by (a tick comma tick by)
- Press enter
Now the text is copied. To paste it anywhere in the vim, press key "p"
Copy Block Of Text To Clipboard Using Vim Markers
- Go to the starting line and press keys "ma"
- Go the last line and press keys "mb"
- Now go to command mode by pressing ":"
- And type 'a,'b"+y
- Press enter
Now you can exit out of Vim and paste the block of text anywhere using right mouse click.
Copy Block Of Text Using Vim Visual mode
- Go to the starting line and press keys "Shift+V" to select the whole line. This would highlight the whole line.
- Go the last end of line.
- Now press y
Now you can paste the copied block of text anywhere inside Vim using key "p".
Copy Block Of Text To Clipboard Using Vim Visual mode
- Go to the starting line and press keys "Shift+V" to select the whole line. This would highlight the whole line.
- Go the last end of line.
- Now press "+y (note " is part of command)
Now you can exit out of Vim and paste the block of text anywhere using right mouse click.