vi
Basic VI editing commands
Note: meta-x means ESC, then x, M-C-x means ESC, then C-x (bash man page)
core commands
q! = quit vi no matter what, get me out of this hell hole!
w = write, save file.
i = insert at cursor
A = add at end of line
o = add line below current
J = join lines (current and one below)
dd = delete whole {n} line (each invocation clear the anon. buffer)
Y = yank current line to anonymous buffer (used by y and d)
P = paste before cursor (linewise if buffer contain whole line)
other oft use commands
a = add after current char
I = insert at beginning of line
O = add line above current and edit it
{n}J = join lines (current and one below)
D = delete from cursor till end of line
{n}dd = delete whole {n} line (each invocation clear the anon. buffer)
dw = delete word
{n}Y = yank current line to anonymous buffer (used by y and d)
p = paste after cursor (from anonymous buffer)
P = paste before cursor (linewise if buffer contain whole line)
{n}x = delete the character {n chars, default = 1}
{n}X = backspace
r = replace char ( {n}r = replaces next n char with a new single char )
R = infinite replacement
C = change remaining of the line
cc= change the whole line (ie rewrite the line)
cw= change word
u = undo
:x = exit and save
:q! = quit w/o save
:w FILENAME = write (note, vi continue work on current file)
/ = serch
Navigation control while in INSERT mode
^F = scroll fwd (down) 1 screen
^B = back 1
^D = fwd 1/2
^U = back 1/2
^E = down 1 line
^Y = up 1 line
H = go to top of screen
M = middle
L = bottom
G = end of file
w = move to next word
b = move back 1 word
) = next sentence ( = previous sentence
} = next paragraph { = previous paragraph
(most usable in bash interactive cli too)
^W = previous word erase
^U = erase from cursor till begin of line
^E = go to end of line
^A = go to beginning of line
^D = undo 1 level of auto indent
Search and Replace
/findme serch for word "findme"
n find next hit
search PATTERN1 and replace it with PATTERN2
:/PATTERN1/s//PATTERN2/
this only replace 1 instance
:s/PATTERN1/PATTERN2/gc
g= global. ie replace all instance on the current line
c = confirm each replacement
from line 1 till last line ($)
substitute PATTERN1 with PATTERN2
globally (all apperearance in the line)
:1,$s/PATTERN1/PATTERN2/g
:%s/PATTERN1/PATTERN2/g
NOTE: can use %s instead of 1,$ for entire file search and replace
vim flags:
g= global
c= confirm (interactive prompt)
I= case sensitive (even if ignore case flag is set)
environment settings
:set nu enable line numbering
:set nonu turn off line numbering
:set ic = insenstive case, for case insenstive searching
:set showmode | noshowmode = show mode or not in status bar
:set beautify = remove some ugly control char
:set noerrorbell = no beeps
:set tabstop=4 = set tab to 4 spaces (default = 8)
:set ai | noai = auto indent ^D = back one indent
O^D = cancel all indent
hat^D = tmp suspend indent
slightly more advanced commands
:syntax on = (VIM only), use color highlight syntax
:set list = show all control char, tab as ^I. newline as $, etc
:r FILE = read FILE into current doc (after current cursor pos)
:r !CMD = run unix CMD and write the output after current cursor pos
eg ':r !date' will write the current date into the document
press control-v, then the control char to save a control char in doc
^G (in command mode) = show status of file
VIM Split Windows commands
:sp = SPlit open file in new window frame
^W s = split into two horizontal windows
^W _ = maximize current windwow frame
^W + = make current window frame bigger
^W v = split into two vertical windows (vim 6.0)
^W < = reduce number of columns in current window
^W > = increate columns
VIM visual mode (cut-n-paste)
v = enter visual mode
use arrow to highlight blocks
y = copy block to memory (subsequent paste with p)
x = cut block (remove from text and place into memory)
> = indent (shift) block 1 "tab"
< = back indent block 1 "tab"
VI etc
keyboar arrow keys, good for my sgi drug-adic keyboard!
h j k l
lf dn up rt
+----+
| k |
+---+----+---+
| h | j | l |
+---+----+---+
vim is Vi clone, more features: vim -g or gvim = X based vim 5.3
^R = redo, after some undo (in command mode)
^T = go Back in help, etc. ^O = go forward. bookmark stuff.
^] = get into help topic.
compatible = vi compatible mode (only 1 level undo, etc)
default on unless there is .vimrc file
:help (or :h) online help
-X : no X server connection, always textt mode (vim 6 only?)
:e = (Edit) open a new file in the current window (closing current file)
:sp = (SPlit) open a new file in a separate (new) window (:q in the window to close it)
:vs = (Vertical Split) vim 6.0 only.
^W+arrow = jumpt to next window
:syntax on = to get syntax highlight (those that come with distribution)
source external syntax hightlight definition file:
source ~/perl.vim
** Features of vim **
- multi level undo
- supposedly better keyboard map!!
- ctrl+arrow works as meta word moving iin edit mode!!
- HOME, END, PgUp, PgDn, INS and DEL keyy all works too!!
- one anonying feature of vim 4.2, it iss like pico, auto cr at end of line
(don't think it is true in vim 5.3, or else find way to disable this!)
- wider terminal support. vi can handlee only up to 163 columns (inclusive).
************************************************************
.vimrc
************************************************************
" (quote) is used to delimiter comment.
" can use
:set ignorecase
" or
set ignorecase
" ie, : in front don't matter.
" eg of .vimrc:
set number
set textwidth=0
:set tw:0
:set ignorecase
:set wrapscan
" but somehow the god damened textwidth is ignored, and vim always default to 78. :(
" so that probably need to be done manually
************************************************************
************************************************************
command ref:
http://www.vim.org/html/
ref:
http://www.vim.org/html/version6.html
vim 6.0 has a vimdiff program to do diff.
also a evim thing that behave more like notepad (no cmd/edit mode).
Also see
vi reference (don't remember where I got the cache from)
"LYS on the outside, LKS in the inside"
"AUHAUH on the outside, LAPPLAPP in the inside"