User Tools

Site Tools




Vim is vi improved!

1. Install on Centos

yum install vim-enhanced

2. Do the vim tutorial. Only takes around 30mins.


3. Summaries from vimtutor

Format for a change command

operator   [number]   motion

     operator - is what to do, such as  d  for delete
     [number] - is an optional count to repeat the motion
     motion   - moves over the text to operate on, such as  w (word),
                $ (to the end of line), etc.

Moving cursor and Motions

h (left)  j (down)  k (up)   l (right)
0         move to the start of the line use a zero

G            moves to the end of the file
number G     moves to that line number
gg           moves to the first line

w            moves to the next word
e            moves to the end of a word

$            moves the the end of the line

CTRL-O       go to older positions
CTRL-I       go to newer positions

%            while the cursor is on a (,),[,],{, or } goes to its match

Exiting vim

:q!    quit without saving
:wq    write and quit

Insert or Append

i      insert before the cursor
o      open a line BELOW the cursor and start Insert mode
O      open a line ABOVE the cursor
a      insert text AFTER the cursor
A      insert text after the end of the line


x          delete character at the cursor type
dw         delete from the cursor up to the next word
d$         delete from the cursor to the end of a line
dd         delete a whole line

Change (Delete and insert)

c [number] motion       change operator allows you to change from the cursor to motion

ce        to change from the cursor to the end of the word
c$        to change to the end of a line.


r         replace the character under the cursor
R         enters Replace mode until  <ESC>  is pressed

Copy and Paste

y         operator yanks (copies) text
p         put back text that has just been deleted or yanks (copied)


u (lowercase u)         undo previous actions
U (capital U)           undo all the changes on a line 
CTRL-R                  undo the undo's


CTRL-G      displays your location in the file and the file status.


/ phrase    searches FORWARD for the phrase
? phrase    searches BACKWARD for the phrase

n           find next occurrence in same direction
N           find next in opposite direction


:s/old/new        substitute new for the first old in a line
:s/old/new/g      substitute new for all 'old's on a line
:#,#s/old/new/g   substitute phrases between two line #'s
:%s/old/new/g     substitute all occurrences in the file
:%s/old/new/gc    add 'c' to ask for confirmation each time

Execute External Command

:!command         executes an external command

Read and Write to File

:w FILENAME               writes the current Vim file to disk with name FILENAME
v  motion  :w FILENAME    saves the Visually selected lines in file FILENAME
:r FILENAME               retrieves disk file FILENAME and puts it below the cursor position
:r !dir                   reads the output of the dir command and puts it below the cursor position


:set xxx     sets the option "xxx"

Some options are:
      'ic' 'ignorecase'       ignore upper/lower case when searching
      'is' 'incsearch'        show partial matches for a search phrase
      'hls' 'hlsearch'        highlight all matching phrases
You can either use the long or the short option name.
Prepend "no" to switch an option off. e.g.   :set noic


:help  or press <F1> or <Help>  to open a help window
:help cmd  to find help on  cmd


CTRL-W CTRL-W  to jump to another window
:q  to close the window


When typing a : command

CTRL-D     to see possible command completions
<TAB>      to use command completion
guides/editors/vim.txt · Last modified: 2010/09/13 01:00 by michaelc