Category:Vim

Using Vim Internal Editor in other Tools
gvim --remote-tab-silent

Scripting
Use Ruby or Python instead of the built-in language, which is a bit un-intuitive.

Quick Reference of Advanced Features
q:       open command-line window (see also :h cmdline-window) :h netrw vim supports URLs like scp://host/path, e.g. :e scp://server.org/dir/file.txt CTRL-]   jump to tag definition (use command 'exuberant-ctags -R .' to generate tags file) CTRL-T   go back after jump /\V      search text (no regular expressions) :e %:h   edit directory of open file CTRL-W,T move window to new tab page

Refactoring in Vim
I was a bit envious of the  functionality in Visual Studio, until I discovered similar functionality in Vim: :args **/*.cs :argdo %s/something/something_else/g or using standard regexs: :argdo rubyd gsub(/something/,'something_else') For all  files in current dir, substitue   with.

Check out: :h argdo :h windo :h tabdo :h bufdo

Disable Autoindenting and Input Mapping
To deactivate autoindenting and input mapping during a copy-paste, use this command before the paste: :set paste and this command after: :set nopaste To toggle between paste/nopaste modes, set a special key for the purpose: :set pastetoggle=

Copy and Paste From and To Clipboard
"*y copy to clipboard "*p  paste from clipboard

Regular Expressions
Vim uses a regular expression dialect, which is annoying, and I recommend using the Ruby or Python extensions in Vim for substitutions, like this:



Vim uses a regular expression dialect, which is like POSIX 1003.2 regular expressions, except that  are escaped (and other stuff)

Metacharacters

. ^ $  \( \) \|   \? \+ * \{ }   [ ] [^ ]

Extensions

global search and replace :%s/sylte/skinke/g - 'g' means global - % means range: whole file

atoms and character classes ^ $        - beginning and end of line \< \>      - beginning and end of word .          - any character [abc]      - a, b or c [^abc]      - not a, b, or c [a-zA-Z0-9] - all characters and numbers [: ? :]    - ? is any of alnum, alpha, ascii, backspace, blank, cntrl, digit, escape, graph, lower, print, punct, return, space, tab, upper, xdigit \a alpha, \A non-alpha, \d digit, \l lowercase char, \p printable, \r return, \s space or tab, \S non-space, \u uppercase char, \w word char [0-9a-zA-Z_], \W non-word char

modifiers *          - 0..inf \+         - 1..inf \=         - 0..1 \|          - or \{a,b}      - between a and b occurences \{a,} \{,b} - at least a, at most b occurences - the above matches as much as possible, to match as little as possible, use \{- something} \{-a}      - at least a, match as little as possible \{-}       - 0..inf match as little as possible

examples find a word with at least 2 danish letters, ignoring case /[Ã¦Ã¸Ã¥]\{2,}/i find the lines with only uppercase letters, spaces and underscores /^upper:][:space:]_]\+$           - search for the beginning of the line, 1 or more uppercase or spaces or '_', end of              the line        remove all [] around words by user confirmation                        %s/\[\([^\[\\+\)\]/\1/gc - search for '[', anything except '[]' 1 or more times, ']' and replace it with the content of the '[]'s (flags global, confirm) remove LaTeX emphasizations, not ignoring case %s/\\emph{\(.\{-}\)}/\1/gI search for all occ. of 'sylte'-words, uppercase them and add the current line nr. :%s/\/\=toupper(submatch(0)).line(".")/gi flags for the substitute command: - see ':h :s_flags'

Window Splitting
split window                   :sp switch between windows         CTRL-W P maximize window                 ctrl-w _

Help
Updating help tags: :helptags $HOME/.vim/doc/

Danish Keyboard and the Help System

 * use Ctrl+Â¨ to follow link
 * and Ctrl+t to go back

Using Vim as an Integrated Development Environment (IDE)

 * make a Makefile for your project
 * - open error list
 * - build project
 * - next error

Debugging in Vim
Use 'clewn' or 'vimgdb'. None of them seems to work without X11.

Syntax Highlighting
"% TODO" og "% FIXME" are highlighted

Cool Tricks
Compile LaTeX file and view PDF in Windows: :silent !pdflatex file.tex&&start /b acrord32 file.pdf

Movement
home / end                     0 / $ word forward / back            W / B sentence forward / back         ) / ( 'token' forward / back         w / b the rest of the line            $ find on this line       f - back: F  find to                  t - back: T  find next / previous char       ; / , find                    / - back: ? find - case insensitive /\c - back: ?\c find next / previous           n / N find n./p. word under cursor   * / *

Advanced Features
copy line to clipboard         "*Y autoindent line                 == autoindent paragraph            =a{ autoindent whole file           gg=G C-make + jump to error          :mak next / previous error           :cn / :cp man [word-under-cursor]         K temporary exit                  Ctrl+z >fg external command > text         :r !  external command                :!  repeat last ext. command        :!! super cvs command               :!cvs ci -m "js";ssh but "cd p2/rapport/;make bib" change to unix fileformat       :set ff=unix autocomplete word               Ctrl+p / Ctrl+n autocomplete line               Ctrl+x Ctrl+l evaluate expressions            "=2+2p

Editing
replace mode                   R change line                     S change 3 words                  c3w change to end of sentence      c) change to 'x'                   rx register cut-paste              " dd, " p visual line cut-paste           V, mark, d, new position, P new line below/above            o / O concatenate lines               J lower/uppercase word            guw / gUw format current paragraph        gqap digraph way of writing 'Ã©'      Ctrl+k e' record macro               q, actions, q play macro                 @ mark                            m goto mark                       ' increment/decrement             Ctrl+a / Ctrl+x

Commenting
commenting lines out - example: 0 CTRL+V jjjI# 