linux vi/vim and gvimPortable for windows
vi ~/.exrc //a default config file in my home directory
:hi normal ctermfg=black ctermbg=white //sets the background color to white and font color to black :set nocompatible //allows the arrow keys to work normally
:set list //shows whitespace characters :set nolist //hides whitespace/nonvisible characters :set nu // :set nu! (or vimrc: set number) line numbers! :set sw=4 // :set shiftwidth 4 , how far to indent or unindent
escape key starts/returns to "command mode" , Use Ctrl-c to abort a command. i = insert mode (type as a normal text editor) j,k and h,l OR arrow keys Ctrl-f , Ctrl-b OR pageup/pagedown
:number = goto line number H = top of screen G = last line of file 0 = beginning of a line $ = end of a line w = forward 1 word b = backwards 1 word e = the end of aword b = beginning of a word
dd = to delete a line (to buffer) dw = delete forward 1 word db = delete backwards 1 word D = delete to end of line (to buffer) x = delete 1 character
yy = COPY = yank a single line into delete buffer p = paste (from buffer) P = paste from buffer before the cursor A = append to end of line
u = undo one change . = repeat the last command
:x = write and save :w = write = save :wq = write = save +quit :q! = quit without saving / = forward search (opens a "line" at the bottom to type in your search) ? = backward search n = repeat search
vi *.txt :w write/save file :n next file
:e = Open a file :w filename = Save As :w! Force Write changes (save)
U changes in current line o for inserting text in new line below cursor O for inserting text in new line above cursor Insert File :r file below current line
SAERCH AND REPLACE
:%s/foo/bar/gc (prompted to enter y Return or Return, if you omit the "c" it will not prompt)
:,$s/string1/string2/gc
remove all trailing whitespace , works well with :set list , :set nolist
:%s/\s+$//
vi -b filename (opens the file in binary mode)
You can now use vi to dw (delete one word forward), right click paste, etc. This is ideal for deleting the ^M (control M) characters at the end of lines created by DOS
:x (will save and quit) versus :q! (which means quit without saving)
Indent line by shiftwidth spaces << Unindent line by shiftwidth spaces 5>> Indent a block of 5 lines 5== Re-indent 5 lines
% Increase indent of a braced or bracketed block (place cursor on brace first) =% Reindent a braced or bracketed block (cursor on brace) <% Decrease indent of a braced or bracketed block (cursor on brace) ]p Paste text, aligning indentation with surroundings
=i{ Re-indent the 'inner block', i.e. the contents of the block =a{ Re-indent 'a block', i.e. block and containing braces =2a{ Re-indent '2 blocks', i.e. this block and containing block
i{ Increase inner block indent <i{ Decrease inner block indent
more info
http://vimdoc.sourceforge.net/htmldoc/options.html#options
UNCONFIRMED
cw = replace a word? + means at the same time - means one after the other
control+r = redo ? control+d = pagedown control+u = pageup
:noh ENTER = clear the highlighted search words
"p = paste from the OS clipboard (e.g. control+v) "yy = copy to the OS clibpard
ggVG = select all
^Wv = control + W + v = Split into explorer window on left :enew = open a new text file ^Wc = Close current Window (tab)
To get into insert mode use (where you can edit the visible text)
* i for inserting text before the cursor
* a for inserting text after the cursor
* A for inserting text at end of line
Then you can enter text, and you can also use Backspace to overwrite previously entered characters. For moving around and other operations you must first change to command mode.
Press Return after all commands starting with :, /, ?.
Open :e file if current file is saved :e! file without saving current file
Join Line with Next Line J
If you want to use dd without losing a previously saved block, then you have to use a named buffer (any letter can be used for z):
Mark Beginning of Block mx set mark x (x may be any letter)
Mark End of Block and Copy'' y`x yank from here to mark x into buffer
Mark End of Block and
Cut'' d`x delete from here to mark x into buffer
Mark End of Block and Copy'' "zy`x yank from here to mark x into buffer z
Mark End of Block and
Cut'' "zd`x delete from here to mark x into buffer z
``Paste'' "zP put buffer z before cursor
"zp put buffer z after cursor