I have always wanted to familiarize myself with vim. Maybe I am interested in open source, maybe I miss the TC environment in the DOS era (my vim theme uses TC ), perhaps I was amazed at the power of VIM. Maybe I hate to touch the mouse when writing code ,:-).
Let's turn to an article about Vim skills. I hope I can learn it in time.
Here's a necessarily cryptic list of "my" Best Vim tips that I 've gleaned
From http://vim.sf.net/; & Comp. Editors
Http://groups.google.com/groups? Safe = off & Group = Comp. Editors
Updated version at http://www.rayninfo.co.uk/vimtips.html
------------------------------------------------------------------------------
# Absolutely essential
------------------------------------------------------------------------------
Vim.sf.net: visit frequently
Comp. Editors: "Vim" dominated newsgroup
* # G * g #: Find word under cursor (forwards/backwards)
%: Match brackets {} [] ()
Matchit. VIM: % Now matches tags <tr> <TD> <SCRIPT> etc
<C-N> <C-P>: Word completion in insert mode
C-X> <C-L>: Line complete super useful
/<C-R> <C-W>: Pull <cword> onto search/command line
: Set ignorecase # You nearly always want this
: Syntax on: Color syntax in Perl, HTML, PHP etc
: H slash <C-D>: Type Control-D and get a list all help topics containing
Slash (plus use tab for help completion)
------------------------------------------------------------------------------
# Make it easy to update/reload_vimrc
: Nmap, S: Source $ Vim/_ vimrc
: Nmap, V: E $ Vim/_ vimrc
------------------------------------------------------------------------------
# Visual mode Mappings
: Vmap Sb "zdi <B> <C-R> Z </B> <ESC>: Wrap <B> </B> around visually selected text
: Vmap ST "zdi <? = C-R> Z?> <ESC>: Wrap <? ==> Around visually selected text
------------------------------------------------------------------------------
# Processing ing
: Ex: file explorer note capital ex
/Be: builtin buffer Explorer
: Ls: List of buffers (eg following)
: CD ..: Move to parent directory
------------------------------------------------------------------------------
# Great
Guu: lowercase line
Guu: uppercase line
GF: open file name under cursor (Super)
GA: Display hex, ASCII value of character under cursor
Ggvgg? : Rot13 whole file
CTRL-A, CTRL-X: increment, decerement number under cursor
Win32 users must remap CNTRL-A
CTRL-R = 5*5: Insert 25 into text
------------------------------------------------------------------------------
# Makes all other tips superfluous
: H 42
: H holy-Grail
: Help!
------------------------------------------------------------------------------
# Markers & moving about
'.: Jump to last modification line (Super)
'.: Jump to exact spot in last modification line
<C-O>: Retrace your movements in file (old)
<C-I>: Retrace your movements in file (new)
: Ju (MPS)
: Help jump-motions
: History: list of all your commands
------------------------------------------------------------------------------
# Abbreviations & maps
: Map <F7>: 'a, 'bw! C:/AAA/x
: Map <F8>: r c:/AAA/x
: Map <F9>: W <CR> :! C:/PHP/php.exe % <CR>
: Map <F11>:. W! C:/AAA/XR <CR>
: Map <F12>: r c:/AAA/XR <CR>
: AB PHP: List of abbreviations beginning PHP
: Map,: List of maps beginning,
# For use in maps
<CR>: carriage return for maps
<ESC>: Escape
<Leader>: Normally/
<Bar >:| Pipe
------------------------------------------------------------------------------
# List your registers
: Reg: display contents of all registers
"1p...: retrieve numeric Buffers
------------------------------------------------------------------------------
# Useful trick
"Ayy @ A: Execute" Vim Command "in a text file
YY @ ": Same thing using unnamed register
------------------------------------------------------------------------------
# Get output from other commands
: R! Ls.exe: reads in output of LS
!! Date: Same thing
: %! Sort-u: use an external program to filter content
------------------------------------------------------------------------------
# Multiple files management
: Wn: Write File and move to next (Super)
: BD: Remove file from buffer list (Super)
: Sav php.html: save current file as php.html and "move" to php.html
: SP fred.txt: Open fred.txt into a split
: E! : Return to unmodified File
: W c:/AAA/%: save file elsewhere
: E #: Edit alternative File
: E %
: Rew: rewwind to first file in ARGs
: BN: Next file
: BP: Next file
: Brew
------------------------------------------------------------------------------
# Recording (Best tip of all)
Qq # record to Q
Your commands
Q
@ Q to execute
@ To repeat
# Editing a register/recording
"AP
<You can now see register contents, edit as required>
"Add
@
------------------------------------------------------------------------------
# _ Vimrc Essentials
: Set incsearch: jumps to search word as you type (annoying but excellent)
: Set wildignore = *. O, *. OBJ, *. Bak, *. exe
: Set shiftwidth = 3
------------------------------------------------------------------------------
# Launching win IE
: Nmap, F: Update <CR>: silent! Start C:/progra ~ 1/intern ~ 1/iexplore.exe file: // %: P <CR>
: Nmap, I: Update <CR> :! Start C:/progra ~ 1/intern ~ 1/iexplore.exe <cword> <CR>
------------------------------------------------------------------------------
# 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: // 209.51.134.122/public_html/index.html
------------------------------------------------------------------------------
# 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 <cword>
------------------------------------------------------------------------------
# Conventional shifting
: 'A, 'B>
# Visual shifting (builtin-repeat)
: Vnoremap <gv
: Vnoremap> gv
------------------------------------------------------------------------------
# Searching
/^ Joe. * Fred. * Bill/: normal
/^ [A-J] //: Search for Lines beginning A-J followed by at leat 1 A-J
/FORUM/(/_./) * pent search over possible multiple lines
/Fred/_ S * Joe/I: Any whitespace including newline
/Fred/| JOE: Search for Fred or Joe
------------------------------------------------------------------------------
# Substitution
: % S/Fred/Joe/IGC: General substitute command
: % S // R // G: delete dos returns ^ m
: 'A, 'bg/Fred/S/dick/Joe/GC: very useful
: S // (. */):/(. */) // 2:/1/: reverse fields separated:
: % S/^./{-} PDF/newbench/non greedy matching (ie to first PDF)
: S/Fred/<c-r> A/G Substitute "Fred" with contents of register ""
: % S/^/(. */)/n/1 // 1 $/delete duplicate lines
# Non-Greedy matching /{-}
: % S/^./{-} PDF/newlinks/
: Help //{-}
: S/Fred/<c-r> A/G Substitute "Fred" with contents of register ""
# Multiple commands
: % S // F/+/. gif/> // R &/R/g | V //. gif $/d | % S/GIF/jpg/
: % S/suck/| buck/loopy/GC: oring
: S/_ date _/= strftime ("% C")/: insert datestring
------------------------------------------------------------------------------
# Global Command
: 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
: V/./,/./-1 Join: compress empty lines
: 'A, 'B g/^ error/. W> errors.txt
: G/cmap/| form/P: oring
------------------------------------------------------------------------------
# Paste register *
: Redir @ *: Redirect commands to paste
: Redir end
"* YY: Yank to paste
"* P: insert paste Buffer
------------------------------------------------------------------------------
# Formatting text
GQ <CR>
Gqap (A is motion p Paragraph (visual mode ))
------------------------------------------------------------------------------
# Operate command over multiple files
: Argdo % S/Foo/BAR/
: Bufdo % S/Foo/BAR/
: Windo % S/Foo/BAR/
------------------------------------------------------------------------------
# Command line tricks
Gvim-H
Ls | gvim-: edit a pipe !!
# VG. ksh (shell script)
# Vi all files in directory containing keyword $1 and jump to $1
Gvim.exe-c "/$1" $ (grep-isl "$1 "*)&
------------------------------------------------------------------------------
# Vim traps
In regular expressions you must backslash + (match 1 or more)
/Fred/+/: matches Fred/Freddy but not free
----------------------------------------
#/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)
CTRL-R CTRL-W pull word under the cursor into a command line or search
CTRL-R-: pull small register
CTRL-R [0-9a-z]: Pull named registers
CTRL-R %: Pull file name (also #)
----------------------------------------
# Manipulating registers
Map <F11> "qyy: Let @ q = @ Q." Zzz"
----------------------------------------
# Help
: H visual <C-D> <tab>: Obtain list of all visual Help topics
: Then use tab to step thru them
----------------------------------------
# Where was an option set
: Verbose set history: reveals value of history and where set
----------------------------------------
# Running file thru an external program (eg PHP)
Map <F9>: W <CR> :! C:/PHP/php.exe % <CR>
----------------------------------------
# Inserting carriage returns
: % S/Nubian/<C-V> <C-M> &/G: That's what you type
: % S/Nubian/<C-Q> <C-M> &/G: for Win32
: % S/Nubian/^ m &/G: What you'll see where ^ m is one character
----------------------------------------
# Retrieving last command line command for Copy & pasting into text
<C-r>:
# Retrieving last SEARCH Command for Copy & pasting into text
<C-r>/
----------------------------------------
# Doing things over multiple lines/_ means including newline
/<! --/_ P/{-} -->: Search for multiple line comments
/Fred/_ S * Joe/I: Any whitespace including newline
/Bugs/(/_./) * BUNNY: Bugs followed by bunny anywhere in file
: H/_: Help
----------------------------------------
# More completions
<C-X> <C-F>: Insert Name of a file in current directory
----------------------------------------
# Help for help
: H visual <C-D> <tab>: Obtain list of all visual Help topics
: Then use tab to step thru them
: H ctrl <C-D>: List help of all control keys
: H: R: Help for: Ex command
: H CTRL-R: Normal Mode
: H/R: What's/R in a Regexp
: H: I _CTRL-R: Help for say <C-R> in insert mode
: H c_CTRL-R: Help for say <C-R> in command mode
: H v_CTRL-V: visual mode
----------------------------------------
This is an extension
# Pulling objects onto command/search line
If you use
CTRL-R CTRL-A
It brings the whole word under the cursor including any special characters.
For ex:
If you are in a HTML page and the cursor is under a keyword <Table>
/CTRL-R CTRL-A brings/<Table>
/CTRL-R CTRL-W brings/table (depending on what the letter under your cursor is... table or <or>
If you want to delete multiple duplicate lines in a sorted file:
: % S/^/(. */)/n/(/1/N/) * // 1 <NL>/
Where <NL> is the character sequence that represents a return in your file type. for Windows, the easiest way to get this is to highlight a return character in another program (open a new notepad, hit return once, select all, and copy) and then use Edit-> paste in VIM to insert it.