Skip to content

VIM

Vim is a text editor written by Bram Moolenaar and first released publicly in 1991. Based on the vi editor common to Unix-like systems, Vim is designed for use both from a command line interface and as a standalone application in a graphical user interface.

Cheat Sheet

The Vim Cheat Sheet was done by http://michael.peopleofhonoronly.com/vim/.

Vim Cheatsheet
Figure 1: Vim Cheatsheet

SWP Files

If working remotely Vim generated swap file. If you're sure that your work is safely storey you can get rid of the swapfiles with the following commands:

find . -name ".*.swp"                # find swap files
find . -name ".*.swp" | xargs rm -f  # find and delete

Commands

Edit & Save & Quit

Command Description
:e <filename> Open and edit <filename>
:w write file
:w <filename> write file in <filename>
:wq write and quit
:wq <filename> write file in <filename> and quit
:wq! write and quit

File

Command Description
:ls list current buffers & files
:e Open integrated File explorer
:Sex Split windows and open integrated File exxlorer

Tab

open multiple files as tabs in vim >7.0

vim -p file1 file2 file3
Command Description
:tabe <filepath> tabulator edit (add file as new tab)
:tabn tab next
:tabp tab previous
gt goto next tab
gT goto previous tab

Split screen

Command Description
:sb <filepath> Add file in horizontal split
:vs <filepath> Add file in vertical split
^w <arrow> Jump to screen in the arrow direction

Regex

Command Description
<regex> Search for a Regex pattern
:noh Stop Highlight search results
AltGr + # Search/Highlight current word
/word Search word from top to bottom
?word Search word from bottom to top
/jo[ha]n Search john or joan
/\< the Search the, theatre or then
/the\> Search the or breathe
/\< the\> Search the
/fred\|joe Search fred or joe
/\<\d\d\d\d\> Search exactly 4 digits
/^\n\{3} Find 3 empty lines
:bufdo /searchstr/ Search in all open files

Replace

Command Description
:%s/<regex>/replacer/cmd Replace Regex search with replacer
:%s/foo/bar/g replace foo with bar auto
:%s/foo/bar/gc replace foo with bar ask confirmation

Modes

Command Description
i Insert Mode
R Replace Mode
a Append Mode
v Visual Mode
V Visual Line Mode
Ctrl + v Visual Block Mode
u Undo

Edit

Command Description
d Delete (also used as Cut)
D Delete to eol (also used as Cut to eol)
y Yank (copy)
Y Yank (copy) line
< shift left (marked lines)
> shift right (marked lines)

Macro

Command Description
q <macroname> 1 start recording = lowercase letter
to what you want 2 Perform the repetetive editing
q 3 Stop recording
@ <macroname> 4-1 Play recording = lowercase letter from before
<nbr> @ <macroname> 4-2 Play recording multiple times = number of times

Console

Execute a console command. Vim will be halted and the console from within Vim was opened will execute the program and go back to Vim after execution is complete.

Command Description
:!<console command> Executes command in the console

.vimrc

.vimrc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
set nocp

set autoindent
set backspace=2
set backup
set hidden
set history=500
set hlsearch
set incsearch
set listchars=precedes:$,extends:$,tab:>-,trail:.,eol:<
" Line numbers "
set number
set printheader=%<%F%=Seite\ %N
set ruler
set shiftwidth=2
set showcmd
set showmatch
set showmode
set sidescroll=5
set smartcase
set smartindent
set softtabstop=2
set spelllang=de,en
set spellsuggest=double,10
set statusline=%<%f\ %h%m%r%=%([%{Tlist_Get_Tagname_By_Line()}]%)\ #%n\ %-14.(%l/%L,%c%V%)\ %P
set tabstop=2
" set textwidth=75 "
set title
set wildmenu
set wildmode=list:longest,full

" Use Windows Clipboard "
if has("win32")
    set clipboard=unnamed
endif

" Syntax Highlighting "
syntax on

" Filename Detection
filetype on
filetype indent on
filetype plugin on

" Folding
"syntax sync fromstart
set foldmethod=indent
set nofoldenable

Download my .vimrc