www.robotz.com - your personal web presence provider

 

Vi short command reference

(Learn or review your Vi commands with this concise reference)
by: Krissy J. krissyj@robotz.com

                

Operation

iinput mode
esccommand mode
:se numberdisplay line numbers
:se nonumberdon't display line numbers
:eopen file
:wsave (write) file to disk
:wqsave and quit
:q!quit but don't save
number,commandapply command number times (e.g. 4,x = delete 4 characters)
.repeat last effective cmd
esc,uundo it
ctrl-rredo it

Navigation and movement

-go to beginning of previous line
0 (zero) or ^go to beginning of this line
$go to end of this line
ret or + = go to beginning of next line (NOT THE SAME AS INPUT RETURN)
wgo to beginning of next word
bgo to beginning of this word
ego to end of this word
sft-hgo to first line onscreen
sft-lgo to last line onscreen
ctrl-fforward (down) one screen
ctrl-bbackward (up) one screen
1,sft-gtop of the buffer
sft-gbottom of the buffer (i.e. EOF)
line,sft-ggo to line (e.g. 3,5,sft-g = line 35)
column,|go to column (e.g. 4,| = column 4)
sft-JJoin / bring next line up (append next line to end)

Deletion

deleted text is put to the general purpose buffer; use the p cmd to retrieve it you can also use yanks to not delete it but still put it in the GPB basically delete = cut and yank = copy in your OS's Edit menu
xdelete this character
d,wdelete word
d,ddelete line
sft-ddelete to end of line (same as emacs ctrl-k)
y,wyank to beginning of next word
sft-y or y,$yank to end of line
y,yyank entire line
buffer"lines"y,yyank lines number of lines into buffer buffer (a-z)
ppaste contents of general-purpose buffer

Replacement

To use replacers type the sequence and then type the string of characters to replace with, e.g. 2,c,w,"Bored Zo" to replace from the cursor to the end of the next word to "Bored Zo"
rreplace a single character
shift-rreplace characters from the cursor(e.g. if | is the cursor and your text is "I AM the |Entertained Zo!" shift-r,"Bored" will give you "I AM the Boredtained Zo!")
c,w or c,echange from cursor to end of word
c,bchange from beginning of word to before cursor
c,$ or sft-cchange from cursor to end of line
c,cchange the ENTIRE line
:x,ys/oldstring/newstring/substitute one occurrence of newstring for oldstring from line x to line y (if y = $ then to EOF)
:x,ys/oldstr/newstr/gsubstitute all occurrences per line of newstring for oldstring
:%s/oldstr/newstr/gsubstitution from start of document to end of document all lines, all occurrences per line.
~toggle a character's case

Searching

/search forward from cursor for a pattern
?search backward from cursor for a pattern
nnext result
sft-nprevious result

Insertion

oinsert a blank line below this one
sft-o...above this one
:r fileinsert file at cursor

 
Customizing Vim: Vim is an editor designed to work like the traditional UNIX vi. Vim extends the features of vi and supports syntax coloring. You can control vim's default behavior by creating a custom .vimrc file in your home directory (or move .exrc to .vimrc). The table below shows some common options you can include in your custom .vimrc file. You may also type these interactively within vim by preceding with a colon.
 

Vim Custom Options

set incsearchincremental searching
set ignorecasedisregards upper and lowercase distinctions
set smartcaseignore case of search if pattern is lower-case
set scrolloff=2two lines of context visible around cursor
set wildmode=longest,listTab, Enter, Esc filename completion
set cindentC code indentation
set nocindentdisable C code indentation
set compatiblebehave more like old vi
set nowrapdisable line wrap for long lines
set textwidth=72supplement to line wrap annoyance
filetype offdisable file type recognition and behavior
set uc=0No swap file will be used
set numberdisplay line numbers in editor
set nonumberdisable display line numbers in editor

 
Vim command line history: (Thu Nov 10 18:12:47 CST 2005) The command-lines that you enter are remembered in a history table. You can recall them with the up and down cursor keys. Example, .viminfo in the user profile. When this doesn't work you might see :<Up> appear in the editor instead of the last command. Reason: You have invoked vim-minimal (/bin/vi) rather than vim-enhanced (/usr/bin/bim). The vim-minimal package doesn't seem to support cmd-line history. The libgpm.so.1 console mouse library is required to use vim-enhanced. Applies when: Linux OS, Linux Terminal Emulation correct, also relates to command complete <Tab>.
 
about the author: Krissy is an enthusiastic member in a growing trend of linux geek girls. The females place in computer technology is not well defined and very few are exploring this realm. Krissy specializes in documentation for various linux related projects and her contributions are highly valued. Krissy has a linux related web site and is a member of lazygirl.net.


Trans American Software
Robotz.com Developer's Project
developer@robotz.com