I suppose everybody knows the basic "ex" and "vi" commands, can yank words and move text with the ex editor? If you don't then go and find other basic cheatsheets for vi on the World Wide Web!
Here are some forgotten ones - the capital commands: A add text to the end of the line I add text to the beginning of the line, the opposite of A X can be used as backspace P pastes before cursor (like on column 1, at the start of the line) Here are some overlooked ones - to jump around: z. position line for easy reading and code editing m<a..z> creates invisible (book)marks '<a..z> move to marker `<a..z> move to [non-whitespace] marker :marks list markers % go to matching parenthesis ctrl f page forward ctrl b page backward Here are some multi window commands: ctrl+W s split window ctrl+W c close window ctrl+W k or up switch to above window ctrl+W j or down switch to above window ctrl+W o no split windows Deletion: d delete u undelete "2p recover from 2nd deletion "xyy yank line in buffer x "xp pase from buffer x Multiple files: :e! re-open the file as it is saved, shorter then :q! end re-open :e x open another file, x=filename :n edit next opened file ctrl+^ or :e# previous file Supersafe mapping for macro's: Letters: g, K, q, V, v Control keys: ? Symbols: _, *, \, = Note: to type control characters type [ctrl]+[v] [ctrl]+[character] Replacement: :%s/... replace in entire file - "%" :1,.s/... replace from line 1 to cursor position - "." :.../c confirm each replacement with y/n - "c"
vim better supports window splitting and editing multiple files!
:ls for file list :b2 for selecting buffer 2 :split horizintal split :vsplit vertical split :qa quit all :cw open new compiler error window :bd buffer delete, close current open file (buffer) :vert res resize to full witdh ( also CTRL-W + | ) :res resize to full height ( also CTRL-W + _ ) ctrl-W = equaly resize windows :help res :Sex Let VIM have Sex with your directory sructure (explore,browse)
See also : http://www.vim.org/htmldoc/usr_08.html
:mksession ~/mysessionfile :q $ vim -S ~/mysessionfile
This is like variables but more elaborate.
:help cmdline-special :help internal-variables
viwU convert word to UPPER case v$U convert line from here to UPPER case vllU convert 3char to UPPER case U(in visual mode) convert to UPPER case u(in visual mode) convert to lower case
Or also: use the "gUgU" command to change the current line to uppercase and the "gugu" command to change the current line to lowercase.
# Search for word currently under the cursor (cool!) :syntax off Turn off syntax coloring
Back to basics...
s=Substitute (regex type) c=Change Line a=Append Text after current line i=Input Text before current line .=Current Line p=Print Line(s) l=Print Line(s) unambiguously d=Delete w=Write q=Quit //=find string and jump to goto line Examples: :1,.d delete from line 1 to the current line
If you want more features or use the vi command mode on the command line or in scripts then use the ex editor (see also WikiScripting):
ex -c"s/xxx/yyy/g" -c"wq" file