All of these are from command mode
. Hit the Esc
key if you are in
insert mode before trying any of these.
shift v
for visual selection; use arrow keys to select more lines>
or <
to indent or unindent a visually-selected blockdd
deletes one line (5dd
deletes 5 lines)yy
yanks (copies) one line (5yy
yanks 5 lines)p
pastes below the current lineHere's an easy way to select multiple lines, delete or copy them, then paste them somewhere else:
ESC # make sure I'm not in insert mode
shift v # visually select
use arrow keys # to move up or down with selection
d # delete selected block (y to yank/copy)
p # paste selected block (below where cursor is)
If I want to copy something from one file to another, I often use tabs
in vim to open both files at the same time. Using gt
you can switch
back and forth between tabs, and copy/paste commands work from one file
to the other (i.e., copy some lines from one file, switch tabs, then
paste those lines in the other file).
Try the following with two files:
vim file1 # open one file in vim
:tabe file2 # open second file as a tab (tabe means tab edit)
yy # copy a line (or use 5yy to copy 5 lines, etc)
gt # switch tabs (gt means go to tab)
p # paste the line(s) you copied into this file
If I just want to pull a whole file into the current file I am editing,
I use :r filename
(the r
is for read filename).
Try the following with two files:
vim file1 # open one file in vim
:r file2 # read in second file (pastes below cursor position)