Recent Changes - Search:
Thanks to OZU Thanks to OZU
Linked In

links

Reviews

Admin

edit SideBar

Vi

VI commands

INSERTING TEXT

To leave the Insert mode, press 'Esc'

aAppend after cursor
AAppend after end of current line
iInsert before cursor
IInsert before beginning of current line
oOpen new line below current line and insert
OOpen new line above current line and insert
CTRL-vcharWhile inserting, ignore special meaning of char (e.g., for inserting characters like Esc and control characters)
:r fileRead file, and insert after current line
JJoin next line to end of current line

DELETING TEXT

CTRL-h or BackspaceWhile in Input Mode delete previous character

Typing a number before these commands will delete that amount of characters, words, or lines.

xDeletes current character
dwDelete current word
ddDeletes current line
:n,mdDeletes lines n through m
D or d$Delete from cursor to end of current line
dcursor_cmdDelete text to cursor to cursor_cmd(e.g.,dG deletes from current line to end of file)

UNDOING AND REPEATING COMMANDS

uUndo last command
URestore current line to original state
"npRetrieve last nth delete(last 9 deletes are in a buffer)"
nRepeat last / or ? search command
NRepeat, in reverse direction, last / or ? search command
; (semi-colon)Repeat last f, F, t or T search command
, (comma)Repeat, in reverse direction, last f, F, t or T search command
. (period)Repeat last text change command

MOVING THE CURSOR

k or CTRL-p Up j or CTRL-j or CTRL-n Down h or CTRL-h or Backspace Left l (lower case L) or Spacebar Right w or W Start of next word; W ignores punctuation b or B Start of previous word; B ignores punctuation e or E End of next word; E ignores punctuation 0 (zero) or | (pipe) First column in current line n| Column n in current line ^ (caret) First non-blank character in current line $ Last character in current line + or Return First character in next line - First non-blank character in previous line 1G First line in file G Last line in file G$ Last character in file nG Line n in file ( Back to beginning of sentence ) Forward to beginning of next sentence \{ Back to beginning of paragraph \} Forward to beginning of next paragraph

PATTERN MATCHING

Pattern matching characters help find strings with similar char- acteristics.

:set magic Allow pattern matching with special characters

               (default)

:set nomagic Allow only ^ and $ as special characters ^ (caret) Match beginning of line $ Match end of line . (period) Match any single character \< Match beginning of word \> Match end of word [str] Match any single character in str [^str] Match any character not in str [a-n] Match any character between a and n

  • Match zero or more occurrences of previous character
               in expression

\ Escape meaning of next character(e.g. \$ lets you

               search for $)

\\ Escape the \ character

SAVE TEXT AND EXIT VI

ZZ or :wq or :x Save file and exit vi :w file Save file but do not exit. Omitting file saves current

               file

:w! file Save file overriding normal checking :n,mw file Write lines n through m to file :n,mw>>file Append lines n through m to end of file :q Leave vi, saving changes before last write

               (you may be prompted to save first)

:q! Leave vi without saving any changes since last write Q Escape vi into ex editor with same file; :vi returns :e! File-edit current file, disregarding changes since last

               write.

SEARCHING

f<char>Search forward in current line to <char>
F<char>Search backwards in curretn line to <char>
/<string>Find next occurence of <string>
?<string>Find previous occurence of <string>
:set icIngnore case while searching
:set noicCase sensitive while searching (default)

GLOBAL SEARCH AND REPLACE

:n,m s/<str1>/<str2>/<opt>Search from n to m for <str1> and replace it with <str2> with option <opt>. <opt> can be c - confirm changes g - global replace p - to print changed lines
(Ex- :1,$ s/foo/bar/gReplaces every occurence of "foo" with the string "bar".)
:g/<str>/<cmd>Run <cmd> on all lines that contain <str>
:g/<str1>/s/<str2>/<str3>/Find line containing <str1>, replace <str2> with <str3>
:v/<str>/<cmd>Execute <cmd> on all lines that do not match <str>

COPYING AND PLACING TEXT

( These commands may be preceded by a number to multiply commands )

yy or YYank current line into the buffer ( copy )
nyy or nYYank n amount of line into buffer
pInsert line(s) in buffer after cursor; also prints last deleted text
PInsert line(s) in buffer before cursor

USEFUL OPTIONS

:set allDisplays all options you may "set"
:set showmodeDisplays "INPUT MODE" while in input mode
:set tabstop=nSets the tabwidth of the tab key to n spaces; 8 is default, but 4 may be preferable
:set listDisplays all control characters in document;
Edit - History - Print - Recent Changes - Search
Page last modified on February 05, 2008, at 06:38 PM