vi tips

I'm using vim instead of vi.


Helpful addon scripts to vim

These script files should reside in ~/.vim/plugin:

[john@bender ~]$ mkdir -p .vim/{plugin,doc}
[john@bender ~]$ ls .vim/
doc  plugin


rcs.vim project page

This script allows you to manage rcs files automatically:

  • if the file is checked in and unlocked, and you try to make an edit, the rcs.vim script will prompt you to checkout and lock the file
  • when done editing, when you quit the buffer (type: :qEnter),the rcs.vim script will prompt you to checkin and unlock the file, and type a comment for your changes


vim visual mode explanation

Indent Multiple lines: 1)

The << and >> commands are used to for block indenting.
The >> indents a line right one tab and << indents a line left 
one tab. You can indent a whole bunch of lines by giving a number
the number before the >> or <<. For example, 10>> will indent
ten lines from the current cursor position.


vi/vim syntax 2) 3)

switch to insert/edit mode
command description verified command?
i insert text at cursor yes
o insert new line below cursor yes
a insert text after cursor yes
I Insert text at the beginning of the line yes
O Open line above cursor yes
A Append text at the end of the line yes
switch to command mode
<ESC> switch to command mode (stop editing) yes
cursor movement (command mode)
<CTRL> + b page up 1 screen yes
<CTRL> + u page up 1/2 screen yes
<CTRL> + d page down 1/2 screen yes
<CTRL> + f page down 1 screen yes
G go to last line yes
:n or nG go to line n yes
0 (zero) go to beginning of line yes
$ go to end of line yes
( ) scroll by sentence (f/b) yes
w b scroll by word (f/b) yes
h j k l move left, down, up, right yes
nx move xn characters/lines where x is (h, j, k, or l) yes
Arrow Keys directional movement yes
:set number show line numbers yes
:set nonumber hide line numbers yes
Deleting text (command mode)
cw change word at cursor yes
dw delete word at cursor yes
r replace one character yes
x delete text at cursor yes
D delete current to end of line yes
dd delete entire line yes
ndd delete n lines yes
:m,nd delete lines m-n yes
Editing (command mode)
yy copy line no
nyy copy n lines no
:m,nt o copy lines m-n, paste after o no
P paste above current line no
p paste below current line no
:m,nm o cut lines m-n, paste after o no
J join previous line no
?string search backward for string yes
/string search forward for string yes
:set paste enable paste mode, which pastes without auto-formatting yes
:set nopaste disable paste mode (re-enable auto-format) yes
View Modes new for vim version 7.0 4)
:tabnew filename open filename in a new “tab” no
linux/tips/vi.txt · Last modified: 2012/11/04 12:06 by john
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki