Table of Contents

How To Copy A Block Of Text In Vim

To copy a block of text in vim, there are mainly two ways.

  1. Using Vim Markers
  2. Copy using Vim visual mode

Copy Using Vim Markers

  1. Go to the starting line and press keys "ma" in quick succession
  2. Go the last line and press keys "mb"
  3. Now go to command mode by pressing ":" (colon)
  4. And type 'a,'by (a tick comma tick by)
  5. 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

  1. Go to the starting line and press keys "ma"
  2. Go the last line and press keys "mb"
  3. Now go to command mode by pressing ":"
  4. And type 'a,'b"+y
  5. 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

  1. Go to the starting line and press keys "Shift+V" to select the whole line. This would highlight the whole line.
  2. Go the last end of line.
  3. 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

  1. Go to the starting line and press keys "Shift+V" to select the whole line. This would highlight the whole line.
  2. Go the last end of line.
  3. 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.

Related Posts

1
2
3
4
5