VIM the World's Most Popular Intelligent Text Editor
A Text Editor allows you to write plain text unlike Wordprocessors which add lots of "invisible" formatting. The standard Text Editor on a PC is NotePad. Intelligent text editors such as VIM (see below for others) have hundreds of features to speed up your document writing.
Vim, which stands for Vi IMproved, is an open source, multiplatform text editor extended from vi. It has a steep learning curve, but if you survive that you risk becoming addicted! Bram Moolenaar the developer is probably the only person in the World who understands all its features which appear to be endless. Much of VIM's power derives from its use of regular rexpressions (REGEXP). Download VIM (totally free) from www.vim.org and begin your adventure!
find the excellent Vim Wiki Here
I have create a special Vim Tips Page (for advanced users) here
More useful VIM links below!
Vi was created by Bill Joy he developed a new version which according to urban legend was lost when his briefcase went missing. Vi then remained unchanged for many years without even a basic help function until Bram Moolenaar adapted vi to run on the fabled Amiga and then went on to create Vim.
VIM
Vim is a text editor first released by Bram Moolenaar in 1991 for the Amiga computer. The name "Vim" is an acronym for "Vi IMproved"
comments by Bram Moolenaar here, and many other places. because Vim was created as an extended version of the vi editor, with many additional features designed to be helpful in editing program source code.
Vim is cross-platform. It is the most popular editor amongst Linux Journal readers.; ;
Released under a software license compatible with the GNU General Public License, Vim is free and open source software. The program's license includes some charityware clauses, encouraging users who enjoy the software to consider donating to children in Uganda.Vim documentation: uganda
What Can "Intelligent" Text Editors do?
As an example Notepad is a completely unintelligent editor
Vim would allow you to
1) Move to where you want to edit quickly:-
I want to get to a certain section which was a sentence about a donkey and a cart, I can search for a line containing donkey and cart.
2) Substitution
If I want to change the name of a character all the way through my document, but have to be careful because there is more than one person with same Christian name then I can probably specify a substitution which will only change the correct one
3) Only type something once
There are a dozen ways to remember, recall and repeat text I have already entered else where.
Well that's just the briefest of introductions, see the YouTube videos for more information
Vim Books on Amazon
New Del.icio.us bookmarks
VIM
Vim News Groups
Get help from other users
groups.yahoo.com/group/vim
groups.google.com/group/vim_mac
comp.editors (The historical newgroup)
Other Intelligent/Programmable Text Editors (Editor Wars)
- UltraEdit
- Replacing Notepad or looking for a powerful text editor? UltraEdit is what you're looking for. UltraEdit is the ideal Text, HEX, HTML, PHP, Java, Javascript, Perl, and Programmer's editor. It's versatile and easy to use.
With nearly 2,000,000 users worldwide, UltraEdit is the #1 selling, most powerful, value priced text editor available! - Emacs
- XEmacs is a highly customizable open source text editor and application development system. It is protected under the GNU Public License and related to other versions of Emacs, in particular GNU Emacs. Its emphasis is on modern graphical user interface support and an open software development model, similar to Linux.
- Editor Wars
- In hacker culture, the editor war is an ongoing debate in the computer programming community about which text editor is best for general-purpose editing. The two largest camps are those favoring vi(m) and those favoring Emacs.
- SlickEdit
- SlickEdit started as a source code editor with features such as syntax highlighting, code refactoring, macros, and key bindings (keyboard shortcuts) compatible with many mainstream text editors including Vim (text editor) and Emacs. It has progressively been augmented with more features, such as integrated debugging sessions, to compete with mainstream compilers and source code management systems as an IDE.
In SlickEdit 11, Vi emulation was upgraded to Vim emulation.
SlickEdit is a commercial product - Wikipedias Text Editors
- Introduction to Text Editors, very good article
- List & Comparison of Text Editors
- This article provides a basic feature comparison for several text editors. Additional feature details are available from the Category of text editor features.
- NoteTab (Notepad Replacement)
- NoteTab is notepad on steroids. I recommend this for less techie users
Vim Command Examples
" searching
/joe/e : cursor set to End of match
/joe/e+1 : cursor set to End of match plus 1
/joe/s-2 : cursor set to Start of match minus 2
/joe/+3 : find joe move cursor 3 lines down
/^joe.*fred.*bill/ : find joe AND fred AND Bill (Joe at start of line)
/^[A-J]/ : search for lines beginning with one or more A-J
/begin\_.*end : search over possible multiple lines
/fred\_s*joe/ : any whitespace including newline *C*
/fred\|joe : Search for FRED OR JOE
/.*fred\&.*joe : Search for FRED AND JOE in any ORDER!
/\/ : search for fred but not alfred or frederick *C*
/\<\d\d\d\d\> : Search for exactly 4 digit numbers
/\D\d\d\d\d\D : Search for exactly 4 digit numbers
/\<\d\{4}\> : same thing
/\([^0-9]\|^\)%.*% : Search for absence of a digit or beginning of line
" finding empty lines
/^\n\{3} : find 3 empty lines
/^str.*\nstr : find 2 successive lines starting with str
/\(^str.*\n\)\{2} : find 2 successive lines starting with str
" using rexexp memory in a search
/\(fred\).*\(joe\).*\2.*\1
" Repeating the Regexp (rather than what the Regexp finds)
/^\([^,]*,\)\{8}
" visual searching
:vmap // y/" : search for visually highlighted text
:vmap // y/=escape(@", '\\/.*$^~[]') : with spec chars
" \zs and \ze regex delimiters :h /\zs
/<\zs[^>]*\ze> : search for tag contents, ignoring chevrons
" zero-width :h /\@=
/<\@<=[^>]*>\@= : search for tag contents, ignoring chevrons
/<\@<=\_[^>]*>\@= : search for tags across possible multiple lines
" searching over multiple lines \_ means including newline
/ : search for multiple line comments
/fred\_s*joe/ : any whitespace including newline *C*
/bugs\(\_.\)*bunny : bugs followed by bunny anywhere in file
:h \_ : help
" search for declaration of subroutine/function under cursor
:nmap gx yiw/^\(sub\function\)\s\+"
" multiple file search
:bufdo /searchstr/ : use :rewind to recommence search
" multiple file search better but cheating
:bufdo %s/searchstr/&/gic : say n and then a to stop
" How to search for a URL without backslashing
?http://www.vim.org/ : (first) search BACKWARDS!!! clever huh!
" Specify what you are NOT searching for (vowels)
/\c\v([^aeiou]&\a){4} : search for 4 consecutive consonants
/\%>20l\%<30lgoat : Search for goat between lines 20 and 30 *N*
/^.\{-}home.\{-}\zshome/e : match only the 2nd occurence in a line of "home" *N*
:%s/home.\{-}\zshome/alone : Substitute only the occurrence of home in any line *N*
" find str but not on lines containing tongue
^\(.*tongue.*\)\@!.*nose.*$
\v^((tongue)@!.)*nose((tongue)@!.)*$
.*nose.*\&^\%(\%(tongue\)\@!.\)*$
:v/tongue/s/nose/&/gic
"----------------------------------------
"substitution
:%s/fred/joe/igc : general substitute command
:%s//joe/igc : Substitute what you last searched for *N*
:%s/~/sue/igc : Substitute your last replacement string for *N*
:%s/\r//g : Delete DOS returns ^M
" Is your Text File jumbled onto one line? use following
:%s/\r/\r/g : Turn DOS returns ^M into real returns
:%s= *$== : delete end of line blanks
:%s= \+$== : Same thing
:%s#\s*\r\?$## : Clean both trailing spaces AND DOS returns
:%s#\s*\r*$## : same thing
" deleting empty lines
:%s/^\n\{3}// : delete blocks of 3 empty lines
:%s/^\n\+/\r/ : compressing empty lines
:%s#<[^>]\+>##g : delete html tags, leave text (non-greedy)
:%s#<\_.\{-1,}>##g : delete html tags possibly multi-line (non-greedy)
" VIM Power Substitute
:'a,'bg/fred/s/dick/joe/igc : VERY USEFUL
" duplicating columns
:%s= [^ ]\+$=&&= : duplicate end column
:%s= \f\+$=&&= : same thing
:%s= \S\+$=&& : usually the same
" memory
%s#.*\(tbl_\w\+\).*#\1# : produce a list of all strings tbl_* *N*
:s/\(.*\):\(.*\)/\2 : \1/ : reverse fields separated by :
:%s/^\(.*\)\n\1$/\1/ : delete duplicate lines
" non-greedy matching \{-}
:%s/^.\{-}pdf/new.pdf/ : delete to 1st pdf only
" use of optional atom \?
:%s#\<[zy]\?tbl_[a-z_]\+\>#\L&#gc : lowercase with optional leading characters
" over possibly many lines
:%s/// : delete possibly multi-line comments
:help /\{-} : help non-greedy
" substitute using a register
:s/fred/a/g : sub "fred" with contents of register "a"
:s/fred/asome_texts/g
:s/fred/\=@a/g : better alternative as register not displayed
" multiple commands on one line
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/
:%s/a/but/gie|:update|:next : then use @: to repeat
" ORing
:%s/suck\|buck/loopy/gc : ORing (must break pipe)
:%s/\v(.*\n){5}/&\r : insert a blank line every 5 lines *N*
" Calling a VIM function
:s/__date__/\=strftime("%c")/ : insert datestring
" Working with Columns sub any str1 in col3
:%s:\(\(\w\+\s\+\)\{2}\)str1:\1str2:
" Swapping first & last column (4 columns)
:%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1:
" filter all form elements into paste register
:redir @*|sil exec 'g#<\(input\|select\|textarea\|/\=form\)\>#p'|redir END
:nmap ,z :redir @*sil exec 'g@<\(input\select\textarea\/\=form\)\>@p'redir END
" substitute string in column 30 *N*
:%s/^\(.\{30\}\)xx/\1yy/
" decrement numbers by 3
:%s/\d\+/\=(submatch(0)-3)/
" increment numbers by 6 on certain lines only
:g/loc\|function/s/\d/\=submatch(0)+6/
" better
:%s#txtdev\zs\d#\=submatch(0)+1#g
:h /\zs
" increment only numbers gg\d\d by 6 (another way)
:%s/\(gg\)\@<=\d\+/\=submatch(0)+6/
:h zero-width
" rename a string with an incrementing number
:let i=10 | 'a,'bg/Abc/s/yy/\=i/ |let i=i+1 # convert yy to 10,11,12 etc
" as above but more precise
:let i=10 | 'a,'bg/Abc/s/xx\zsyy\ze/\=i/ |let i=i+1 # convert xxyy to xx11,xx12,xx13
" find replacement text, put in memory, then use \zs to simplify substitute
:%s/"\([^.]\+\).*\zsxx/\1/
" Pull word under cursor into LHS of a substitute
:nmap z :%s#\<=expand("")\>#
" Pull Visually Highlighted text into LHS of a substitute
:vmap z :%s/\<*\>/
" substitute singular or plural
:'a,'bs/bucket\(s\)*/bowl\1/gic *N*
----------------------------------------
" all following performing similar task, substitute within substitution
" Multiple single character substitution in a portion of line only
:%s,\(all/.*\)\@<=/,_,g : replace all / with _ AFTER "all/"
" Same thing
:s#all/\zs.*#\=substitute(submatch(0), '/', '_', 'g')#
" Substitute by splitting line, then re-joining
:s#all/#&^M#|s#/#_#g|-j!
" Substitute inside substitute
:%s/.*/\='cp '.submatch(0).' all/'.substitute(submatch(0),'/','_','g')/
----------------------------------------
" global command display
:g/gladiolli/# : display with line numbers (YOU WANT THIS!)
:g/fred.*joe.*dick/ : display all lines fred,joe & dick
:g/\/ : display all lines fred but not freddy
:g/^\s*$/d : delete all blank lines
:g!/^dd/d : delete lines not containing string
:v/^dd/d : delete lines not containing string
:g/fred/,/joe/d : not line based (very powerfull)
:g/fred/,/joe/j : Join Lines *N*
:g/-------/.-10,.d : Delete string & 10 previous lines
:g/{/ ,/}/- s/\n\+/\r/g : Delete empty lines but only between {...}
:v/\S/d : Delete empty lines (both types)
:v/./,/./-j : compress empty lines
:g/^$/,/./-j : compress empty lines
:g/p : ORing
:g/^/put_ : double space file (pu = put)
:g/^/m0 : Reverse file (m = move)
:'a,'bg/^/m'b : Reverse a section a to b
:g/^/t. : duplicate every line
:g/fred/t$ : copy(transfer) lines matching fred to EOF
:g/stage/t'a : copy (transfer) lines matching stage to marker a (cannot use .) *C*
:g/\(^I[^^I]*\)\{80}/d : delete all lines containing at least 80 tabs
" perform a substitute on every other line
:g/^/ if line('.')%2|s/^/zz /
" match all lines containing "somestr" between markers a & b
" copy after line containing "otherstr"
:'a,'bg/somestr/co/otherstr/ : co(py) or mo(ve)
" as above but also do a substitution
:'a,'bg/str1/s/str1/&&&/|mo/str2/
:%norm jdd : delete every other line
" incrementing numbers (type as 5 characters)
:.,$g/^\d/exe "norm! \": increment numbers
:'a,'bg/\d\+/norm! ^A : increment numbers
" storing glob results (note must use APPEND) you need to empty reg a first with qaq.
"save results to a register/paste buffer
:g/fred/y A : append all lines fred to register a
:g/fred/y A | :let @*=@a : put into paste buffer
:let @a=''|g/Barratt/y A |:let @*=@a
" filter lines to a file (file must already exist)
:'a,'bg/^Error/ . w >> errors.txt
" duplicate every line in a file wrap a print '' around each duplicate
:g/./yank|put|-1s/'/"/g|s/.*/Print '&'/
" replace string with contents of a file, -d deletes the "mark"
:g/^MARK$/r tmp.txt | -d
" display prettily
:g//z#.5 : display with context
:g//z#.5|echo "==========" : display beautifully
" Combining g// with normal mode commands
:g/|/norm 2f|r* : replace 2nd | with a star
"send output of previous global command to a new window
:nmap :redir @a:g//:redir END:new:put! a
-------------
Vim Commands II
" Global combined with substitute (power editing)
:'a,'bg/fred/s/joe/susan/gic : can use memory to extend matching
:/fred/,/joe/s/fred/joe/gic : non-line based (ultra)
:/biz/,/any/g/article/s/wheel/bucket/gic: non-line based *N*
----------------------------------------
" Find fred before beginning search for joe
:/fred/;/joe/-2,/sid/+3s/sally/alley/gIC
----------------------------------------
" create a new file for each line of file eg 1.txt,2.txt,3,txt etc
:g/^/exe ".w ".line(".").".txt"
----------------------------------------
" Summary of editing repeats *N*
. last edit (magic dot)
:& last substitute
:%& last substitute every line
:%&gic last substitute every line confirm
g% normal mode repeat last substitute
g& last substitute on all lines
@@ last recording
@: last command-mode command
:!! last :! command
:~ last substitute
:help repeating
----------------------------------------
" Summary of repeated searches
; last f, t, F or T
, last f, t, F or T in opposite direction
n last / or ? search
N last / or ? search in opposite direction
----------------------------------------
" Absolutely essential
----------------------------------------
* # g* g# : find word under cursor () (forwards/backwards)
% : match brackets {}[]()
. : repeat last modification
@: : repeat last : command (then @@)
matchit.vim : % now matches tags
Vim Commands 3
: Line complete SUPER USEFUL
/ : Pull onto search/command line
/ : Pull onto search/command line
:set ignorecase : you nearly always want this
:set smartcase : overrides ignorecase if uppercase used in search string (cool)
:syntax on : colour syntax in Perl,HTML,PHP etc
:h regexp : type control-D and get a list all help topics containing
regexp (plus use TAB to Step thru list)
----------------------------------------
" MAKE IT EASY TO UPDATE/RELOAD _vimrc
:nmap ,s :source $VIM/_vimrc
:nmap ,v :e $VIM/_vimrc
" How to have a variant in your .vimrc for different PCs *N*
if $COMPUTERNAME == "NEWPC"
ab mypc vista
else
ab mypc dell25
endif
----------------------------------------
"VISUAL MODE (easy to add other HTML Tags)
:vmap sb "zdiz : wrap around VISUALLY selected Text
:vmap st "zdi : wrap around VISUALLY selected Text
----------------------------------------
"vim 7 tabs
vim -p fred.php joe.php : open files in tabs
:tabe fred.php : open fred.php in a new tab
:tab ball : tab open files
" vim 7 forcing use of tabs from .vimrc
:nnoremap gf gf
:cab e tabe
:tab sball : retab all files in buffer (repair) *N*
----------------------------------------
" Exploring
:e . : file explorer
:Exp(lore) : file explorer note capital Ex
:Sex(plore) : file explorer in split window
:browse e : windows style browser
:ls : list of buffers
:cd .. : move to parent directory
:args : list of files
:args *.php : open list of files (you need this!)
:lcd %:p:h : change to directory of current file
:autocmd BufEnter * lcd %:p:h : change to directory of current file automatically (put in _vimrc)
----------------------------------------
" Changing Case
guu : lowercase line
gUU : uppercase line
Vu : lowercase line
VU : uppercase line
g~~ : flip case line
vEU : Upper Case Word
vE~ : Flip Case Word
ggguG : lowercase entire file
" Titlise Visually Selected Text (map for .vimrc)
vmap ,c :s/\<\(.\)\(\k*\)\>/\u\1\L\2/g
" titlise a line
nmap ,t :s/.*/\L&/:s/\<./\u&/g *N*
" Uppercase first letter of sentences
:%s/[.!?]\_s\+\a/\U&\E/g
----------------------------------------
gf : open file name under cursor (SUPER)
:nnoremap gF :view : open file under cursor, create if necessary
ga : display hex,ascii value of char under cursor
ggVGg? : rot13 whole file
ggg?G : rot13 whole file (quicker for large file)
:8 | normal VGg? : rot13 from line 8
:normal 10GVGg? : rot13 from line 8
, : increment,decrement number under cursor
win32 users must remap CNTRL-A
=5*5 : insert 25 into text (mini-calculator)
----------------------------------------
" Make all other tips superfluous
:h 42 : also http://www.google.com/search?q=42
:h holy-grail
:h!
----------------------------------------
" Markers & moving about
'. : jump to last modification line (SUPER)
`. : jump to exact spot in last modification line
g; : cycle thru recent changes (oldest first)
g, : reverse direction
:changes
:h changelist : help for above
: retrace your movements in file (starting from most recent)
: retrace your movements in file (reverse direction)
:ju(mps) : list of your movements
:help jump-motions
:history : list of all your commands
:his c : commandline history
:his s : search history
q/ : Search history Window (puts you in full edit mode) (exit CTRL-C)
q: : commandline history Window (puts you in full edit mode) (exit CTRL-C)
: : history Window (exit CTRL-C)
----------------------------------------
" Abbreviations & Maps
" Following 4 maps enable text transfer between VIM sessions
:map :'a,'bw! c:/aaa/x : save text to file x
:map :r c:/aaa/x : retrieve text
:map :.w! c:/aaa/xr : store current line
:map :r c:/aaa/xr : retrieve current line
:ab php : list of abbreviations beginning php
:map , : list of maps beginning ,
" allow use of F10 for mapping (win32)
set wak=no : :h winaltkeys
" For use in Maps
: carriage Return for maps
: Escape
: normally \
: | pipe
: backspace
: No hanging shell window
#display RGB colour under the cursor eg #445588
:nmap c :hi Normal guibg=#=expand("")
map /price only\\|versus/ :in a map need to backslash the \
# type table,,, to get ### Cool ###
imap ,,, bdwa<pa>pa>kA
----------------------------------------
" Simple PHP debugging display all variables yanked into register a
iab phpdb exit("Debug a ");
----------------------------------------
" Using a register as a map (preload registers in .vimrc)
:let @m=":'a,'bs/"
:let @s=":%!sort -u"
----------------------------------------
" Useful tricks
"ayy@a : execute "Vim command" in a text file
yy@" : same thing using unnamed register
u@. : execute command JUST typed in
"ddw : store what you delete in register d *N*
"ccaw : store what you change in register c *N*
----------------------------------------
" Get output from other commands (requires external programs)
:r!ls : reads in output of ls
:r !grep "^ebay" file.txt : grepping in content *N*
:20,25 !rot13 : rot13 lines 20 to 25 *N*
!!date : same thing (but replaces/filters current line)
" Sorting with external sort
:%!sort -u : use an external program to filter content
:'a,'b!sort -u : use an external program to filter content
!1} sort -u : sorts paragraph (note normal mode!!)
:g/^$/;,/^$/-1!sort : Sort each block (note the crucial ;)
" Sorting with internal sort
:sort /.*\%2v/ : sort all lines on second column *N*
----------------------------------------
" Multiple Files Management (Essential)
:bn : goto next buffer
:bp : goto previous buffer
:wn : save file and move to next (super)
:wp : save file and move to previous
:bd : remove file from buffer list (super)
:bun : Buffer unload (remove window but not from list)
:badd file.c : file from buffer list
:b3 : go to buffer 3 *C*
:b main : go to buffer with main in name eg main.c (ultra)
:sav php.html : Save current file as php.html and "move" to php.html
:sav! %<.bak : Save Current file to alternative extension (old way)
:sav! %:r.cfm : Save Current file to alternative extension
:sav %:s/fred/joe/ : do a substitute on file name
:sav %:s/fred/joe/:r.bak2 : do a substitute on file name & ext.
:!mv % %:r.bak : rename current file (DOS use Rename or DEL)
:help filename-modifiers
:e! : return to unmodified file
:w c:/aaa/% : save file elsewhere
:e # : edit alternative file (also cntrl-^)
:rew : return to beginning of edited files list (:args)
:brew : buffer rewind
:sp fred.txt : open fred.txt into a split
:sball,:sb : Split all buffers (super)
:scrollbind : in each split window
:map :ls:e # : Pressing F5 lists all buffer, just type number
:set hidden : Allows to change buffer w/o saving current buffer
----------------------------------------
" Quick jumping between splits
map j_
map k_
----------------------------------------
" Recording (BEST TIP of ALL)
qq # record to q
your complex series of commands
q # end recording
@q to execute
@@ to Repeat
5@@ to Repeat 5 times
" editing a register/recording
"qp :display contents of register q (normal mode)
q :display contents of register q (insert mode)
" you can now see recording contents, edit as required
"qdd :put changed contacts back into q
@q :execute recording/register q
" Operating a Recording on a Visual BLOCK
1) define recording/register
qq:s/ to/ from/g^Mq
2) Define Visual BLOCK
V}
3) hit : and the following appears
:'<,'>
4)Complete as follows
:'<,'>norm @q
----------------------------------------
"combining a recording with a map (to end up in command mode)
:nnoremap ] @q:updatebd
----------------------------------------
" Visual is the newest and usually the most intuitive editing mode
" Visual basics
v : enter visual mode
V : visual mode whole line
: enter VISUAL BLOCK mode
gv : reselect last visual area (ultra)
o : navigate visual area
"*y : yank visual area into paste buffer
V% : visualise what you match
V}J : Join Visual block (great)
V}gJ : Join Visual block w/o adding spac
Vim Commands 4
----------------------------------------
" Delete first 2 characters of 10 successive lines
010j2ld
----------------------------------------
" how to copy a set of columns using VISUAL BLOCK
" visual block (AKA columnwise selection) (NOT BY ordinary v command)
then select "column(s)" with motion commands (win32 )
then c,d,y,r etc
----------------------------------------
" how to overwrite a visual-block of text with another such block *C*
" move with hjkl etc
Pick the first block: ctrl-v move y
Pick the second block: ctrl-v move P
----------------------------------------
" text objects :h text-objects *C*
daW : delete contiguous non whitespace
di< yi< ci< : Delete/Yank/Change HTML tag contents
da< ya< ca< : Delete/Yank/Change whole HTML tag
dat dit : Delete HTML tag pair
diB daB : Empty a function {}
das : delete a sentence
----------------------------------------
" _vimrc essentials
:set incsearch : jumps to search word as you type (annoying but excellent)
:set wildignore=*.o,*.obj,*.bak,*.exe : tab complete now ignores these
:set shiftwidth=3 : for shift/tabbing
:set vb t_vb=". : set silent (no beep)
:set browsedir=buffer : Maki GUI File Open use current directory
----------------------------------------
" launching Win IE
:nmap ,f :update:silent !start c:\progra~1\intern~1\iexplore.exe file://%:p
:nmap ,i :update: !start c:\progra~1\intern~1\iexplore.exe
----------------------------------------
" FTPing from VIM
cmap ,r :Nread ftp://209.51.134.122/public_html/index.html
cmap ,w :Nwrite ftp://209.51.134.122/public_html/index.html
gvim ftp://www.somedomain.com/index.html # uses netrw.vim
----------------------------------------
" appending to registers (use CAPITAL)
" yank 5 lines into "a" then add a further 5
"a5yy
10j
"A5yy
----------------------------------------
[I : show lines matching word under cursor (super)
----------------------------------------
" Conventional Shifting/Indenting
:'a,'b>>
" visual shifting (builtin-repeat)
:vnoremap < >gv
" Block shifting (magic)
>i{
>a{
" also
>% and
Vim Commands 5
" Redirection & Paste register *
:redir @* : redirect commands to paste buffer
:redir END : end redirect
:redir >> out.txt : redirect to a file
" Working with Paste buffer
"*yy : yank to paste
"*p : insert from paste buffer
" yank to paste buffer (ex mode)
:'a,'by* : Yank range into paste
:%y* : Yank whole buffer into paste
:.y* : Yank Current line to paster
" filter non-printable characters from the paste buffer
" useful when pasting from some gui application
:nmap p :let @* = substitute(@*,'[^[:print:]]','','g')"*p
----------------------------------------
" Re-Formatting text
gq} : Format a paragraph
gqap : Format a paragraph
ggVGgq : Reformat entire file
Vgq : current line
" break lines at 70 chars, if possible after a ;
:s/.\{,69\};\s*\|.\{,69\}\s\+/&\r/g
----------------------------------------
" Operate command over multiple files
:argdo %s/foo/bar/e : operate on all files in :args
:bufdo %s/foo/bar/e
:windo %s/foo/bar/e
:argdo exe '%!sort'|w! : include an external command
:bufdo exe "normal @q" | w : perform a recording on open files
:silent bufdo !zip proj.zip %:p : zip all current files
----------------------------------------
" Command line tricks
gvim -h : help
ls | gvim - : edit a stream!!
cat xx | gvim - -c "v/^\d\d\|^[3-9]/d " : filter a stream
gvim -o file1 file2 : open into a split
" execute one command after opening file
gvim.exe -c "/main" joe.c : Open joe.c & jump to "main"
" execute multiple command on a single file
vim -c "%s/ABC/DEF/ge | update" file1.c
" execute multiple command on a group of files
vim -c "argdo %s/ABC/DEF/ge | update" *.c
" remove blocks of text from a series of files
vim -c "argdo /begin/+1,/end/-1g/^/d | update" *.c
" Automate editing of a file (Ex commands in convert.vim)
vim -s "convert.vim" file.c
#load VIM without .vimrc and plugins (clean VIM)
gvim -u NONE -U NONE -N
" Access paste buffer contents (put in a script/batch file)
gvim -c 'normal ggdG"*p' c:/aaa/xp
" print paste contents to default printer
gvim -c 's/^/\=@*/|hardcopy!|q!'
" gvim's use of external grep (win32 or *nix)
:grep somestring *.php : creates a list of all matching files
" use :cn(ext) :cp(rev) to navigate list
:h grep
----------------------------------------
" GVIM Difference Function (Brilliant)
gvim -d file1 file2 : vimdiff (compare differences)
dp : "put" difference under cursor to other file
do : "get" difference under cursor from other file
" complex diff parts of same file *N*
:1,2yank a | 7,8yank b
:tabedit | put a | vnew | put b
:windo diffthis
----------------------------------------
" Vim traps
In regular expressions you must backslash + (match 1 or more)
In regular expressions you must backslash | (or)
In regular expressions you must backslash ( (group)
In regular expressions you must backslash { (count)
/fred\+/ : matches fred/freddy but not free
/\(fred\)\{2,3}/ : note what you have to break
----------------------------------------
" \v or very magic (usually) reduces backslashing
/codes\(\n\|\s\)*where : normal regexp
/\vcodes(\n|\s)*where : very magic
----------------------------------------
" pulling objects onto command/search line (SUPER)
: pull word under the cursor into a command line or search
: pull WORD under the cursor into a command line or search
- : pull small register (also insert mode)
[0-9a-z] : pull named registers (also insert mode)
% : pull file name (also #) (also insert mode)
=somevar : pull contents of a variable (eg :let sray="ray[0-9]")
----------------------------------------
" List your Registers
:reg : display contents of all registers
:reg a : display content of register a
:reg 12a : display content of registers 1,2 & a *N*
"5p : retrieve 5th "ring"
"1p.... : retrieve numeric registers one by one
:let @y='yy@"' : pre-loading registers (put in .vimrc)
qqq : empty register "q"
qaq : empty register "a"
:reg .-/%:*" : the seven special registers *N*
:reg 0 : what you last yanked, not affected by a delete *N*
"_dd : Delete to blackhole, don't affect any register *N*
----------------------------------------
" manipulating registers
:let @a=@_ : clear register a
:let @a="" : clear register a
:let @a=@" : Save unnamed register *N*
:let @*=@a : copy register a to paste buffer
:let @*=@: : copy last command to paste buffer
:let @*=@/ : copy last search to paste buffer
:let @*=@% : copy current filename to paste buffer
----------------------------------------
" help for help (USE TAB)
:h quickref : VIM Quick Reference Sheet (ultra)
:h tips : Vim's own Tips Help
:h visual : obtain list of all visual help topics
: Then use tab to step thru them
:h ctrl : list help of all control keys
:helpg uganda : grep HELP Files use :cn, :cp to find next
:helpgrep edit.*director: grep help using regexp
:h :r : help for :ex command
:h CTRL-R : normal mode
:h /\r : what's \r in a regexp (matches a )
:h \\zs : double up backslash to find \zs in help
:h i_CTRL-R : help for say in insert mode
:h c_CTRL-R : help for say in command mode
:h v_CTRL-V : visual mode
:h tutor : VIM Tutor
, : Move back & Forth in HELP History
gvim -h : VIM Command Line Help
:cabbrev h tab h : open help in a tab *N*
----------------------------------------
" where was an option set
:scriptnames : list all plugins, _vimrcs loaded (super)
:verbose set history? : reveals value of history and where set
:function : list functions
:func SearchCompl : List particular function
----------------------------------------
" making your own VIM help
:helptags /vim/vim64/doc : rebuild all *.txt help files in /doc
:help add-local-help
----------------------------------------
" running file thru an external program (eg php)
map :w:!c:/php/php.exe %
map :w:!perl -c %
----------------------------------------
" capturing output of current script in a separate buffer
:new | r!perl # : opens new buffer,read other buffer
:new! x.out | r!perl # : same with named file
:new+read!ls
----------------------------------------
" create a new buffer, paste a register "q" into it, then sort new buffer
:new +put q|%!sort
----------------------------------------
" Inserting DOS Carriage Returns
:%s/$/\&/g : that's what you type
:%s/$/\&/g : for Win32
:%s/$/\^M&/g : what you'll see where ^M is ONE character
----------------------------------------
" automatically delete trailing Dos-returns,whitespace
autocmd BufRead * silent! %s/[\r \t]\+$//
autocmd BufEnter *.php :%s/[ \t\r]\+$//e
----------------------------------------
" perform an action on a particular file or file type
autocmd VimEnter c:/intranet/note011.txt normal! ggVGg?
autocmd FileType *.pl exec('set fileformats=unix')
----------------------------------------
" Retrieving last command line command for copy & pasting into text
i:
" Retrieving last Search Command for copy & pasting into text
i/
----------------------------------------
" more completions
:insert name of a file in current directory
----------------------------------------
" Substituting a Visual area
" select visual area as usual (:h visual) then type :s/Emacs/Vim/ etc
:'<,'>s/Emacs/Vim/g : REMEMBER you dont type the '<.'>
gv : Re-select the previous visual area (ULTRA)
----------------------------------------
" inserting line number into file
:g/^/exec "s/^/".strpart(line(".")." ", 0, 4)
:%s/^/\=strpart(line(".")." ", 0, 5)
:%s/^/\=line('.'). ' '
----------------------------------------
#numbering lines VIM way
:set number : show line numbers
:map :set number! : Show linenumbers flip-flop
:%s/^/\=strpart(line('.')." ",0,&ts)
#numbering lines (need Perl on PC) starting from arbitrary number
:'a,'b!perl -pne 'BEGIN{$a=223} substr($_,2,0)=$a++'
#Produce a list of numbers
#Type in number on line say 223 in an empty file
qqmnYP`n^Aq : in recording q repeat with @q
" increment existing numbers to end of file (type as 5 characters)
:.,$g/^\d/exe "normal! \"
" advanced incrementing
http://vim.sourceforge.net/tip_view.php?tip_id=150
----------------------------------------
" advanced incrementing (really useful)
" put following in _vimrc
let g:I=0
function! INC(increment)
let g:I =g:I + a:increment
return g:I
endfunction
" eg create list starting from 223 incrementing by 5 between markers a,b
:let I=223
:'a,'bs/^/\=INC(5)/
" create a map for INC
cab viminc :let I=223 \| 'a,'bs/$/\=INC(5)/
----------------------------------------
" generate a list of numbers 23-64
o23qqYpq40@q
----------------------------------------
" editing/moving within current insert (Really useful)
: delete all entered
: delete last word
: beginning/end of line
: jump one word b
by thesuccess
I am a wanderer of the vast lonely plains of the Internet always looking for something extraordinary, and now by some strange Serendipity we meet!
com... (more)
Fetching new data from eBay now... please stand by

