Jump to: navigation, search


Vim Configuration

Vim and Windows

Certain plugins need Python support. On Windows, make sure that the 32/64-bitness of the installed version of Python and Vim match up. The default Vim installer on the website is currently 32-bit, which crashes if your installed Python is 64-bit.

Tested versions: Vim 7.4 , Python 2.7.9


Using Vim Internal Editor in other Tools

gvim --remote-tab-silent


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://
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 Refactor->Rename 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 *.cs files in current dir, substitue something with something_else.

Check out:

:h argdo
:h windo
:h tabdo
:h bufdo

Copying and Pasting

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=<F2>

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:

:[range]rubyd gsub!(/regex/,"substitution")

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


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


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


*           - 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


       find a word with at least 2 danish letters, ignoring case
       find the lines with only uppercase letters, spaces and underscores
           - 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
           - 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
       search for all occ. of 'sylte'-words, uppercase them and add the current line nr.

flags for the substitute command: - see ':h :s_flags' </pre>

Window Splitting

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


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
  • :copen - open error list
  • :make - build project
  • :cn - next error

Debugging in Vim

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

Syntax Highlighting

"% TODO" og "% FIXME" are highlighted

Key Commands

Cool Tricks

Compile LaTeX file and view PDF in Windows:

:silent !pdflatex file.tex&&start /b acrord32 file.pdf


home / end                      0 / $
word forward / back             W / B
sentence forward / back         ) / (
'token' forward / back          w / b

the rest of the line            $
find <char> on this line        f<char> - back: F<char>
find to <char>                  t<char> - back: T<char>
find next / previous char       ; / ,
find <word>                     /<word> - back: ?<word>
find <word> - case insensitive  /\c<word> - back: ?\c<word>
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 !<cmd>
external command                :!<cmd>
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+2<Enter>p


replace mode                    R
change line                     S
change 3 words                  c3w
change to end of sentence       c)
change to 'x'                   rx
register cut-paste              "<char>dd, "<char>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 <a-z>              q<a-z>, actions, q
play macro <a-z>                @<a-z>

mark                            m<a-z>
goto mark                       '<a-z>

increment/decrement             Ctrl+a / Ctrl+x


commenting lines out - example:

0 CTRL+V jjjI# <Esc>

Pages in category "Vim"

The following 10 pages are in this category, out of 10 total.