Vim
Published: 13:22, Thursday 14 July 2011

Vim is currently my favourite editor.

It took me a while to really start using vim. I used notepad++ earlier on my windows xp, but when I switched to linux I had to find something new. After trying out a few editors (including emacs - probably not enough to really start enjoying it) I decided that I would start using this one. I spent many hours customizing it and experimented with many plugins. I wrote a plugin personally, which I use to edit the pages of this website directly in the database.

Notes
What's this? See my article about Notes.
this document assumes you are using my .vimrc (see dot_vimrc at page bottom).
tabs:
tabe, tabf
switch tab: tabn/tabp, gt/gT
go to tab nr #: #gt
tabpagemax
vim -p files
tabs to spaces: set expandtab
multiple commands: separe by |
command aliases: :Alias alias original
define custom command:
command -nargs=1 Name cmd
<silent>
help:
:h
follow link: <C-]>
include new: :helptags dir
map: help map
options/settings:
toggoption set:
set option
set nooption
set invoptionn
option set:
set option
set nooption
set invoption
echo a setting:
:set setting?
see where it has been set: :verbose set setting?
vim scripting: :help vim-script-intro
prepend in v-mode:
Prepend function
^ string
prepend tab (indent): tab (< is built-in)
prepend #
indent:
normal mode: <<, >>, tab, shift-tab
<,>
tab
gq, =
leader:
default: \
let mapleader = ","
comments:
with NERD_commenter
<leader>:
comment: cc
uncomment: cu
toggle
c<space>
ci individually
sexy: cs
yank: cy
to eol: c$
append: cA
alternative: ca
align delimiters: cl, cb
others: cm
let NERDSpaceDelims=1
/usr/local/share/vim/vim73/ftplugin/html.vim line 17
setlocal comments+=s:<!--,m:\ \ \ \ ,e:-->
added the + so that in php it is still working!
modelines/commands in comments: # vim: command
surrounding:
change: cs12
delete: ds(
word: ysW(
motion: ys
line yss
selected: s( (in visual)
c comments: s*
copypaste clipboard:
vim --version: +xterm_clipboard is needed
"+y or "+p
empty command line: <C-U>
command line command to exec keycomb:
mode keycomb
insert single character: <Space>
save and edit: we filename
save as sudo: :w !sudo tee % > /dev/null
pull/copy to command/paste to command line
<C-R><C-W>
save into register x and pull with <C-R>x
default: <C-R>"
<C-R>=expr
autocompletion:
supertabs
in commandline mode <C-d> to see a list of suggestions
open file:
open file under cursor
gf
<C-w>f, <C-w>gf
open file in a new tab: <C-t>
go to url/go to link/open url under cursor: <leader>w
fast find/file autocompletion/find file:
i prefer command-t
create cache: :FC
find file
:FF
split: :FS
clear cache: :FCC
command-t:
source the vba
:h command-t
CommandTFlush
<leader>t
in the prompt
use C-h/j/k/l
in new tab: <C-t>
exit: <C-c> (<Esc> doesn't work, dunno why)
leg g:CommandTMaxHeight=1
command-line window (clw):
open: from command-line mode <C-F>, from normal q:,q/
can use : for commands. but not q:
exit: <CR> execute, <C-c> go to command-line, :q back to normal,
execute current line in bash/shell
! or ¨ to see results
echo "hello"
key notations (:help shift):
<CR>=<Enter>
line split: <CR>, join: J
insert blank line before/after: <C-k> <C-j>
current:
file %
full path %:p
directory %:p:h
edit file relative to current file:
:edit %:p:h<Tab>...
move line/selection:
up: -, down: +
m command
visual mode:
go to other end: o
don't exit/stay in visual mode:
reselect/select pasted block: gV
registers:
cut to register r: "rdd
append to register r: "Rdd
reload .vimrc: :source ~/.vimrc
insert file contents/include file contents/load contents of file: :read file
reload file: :e
get line content:
getline(lnr)
current: getline('.')
send to .vimrc: Sendtovimrc command
go back
help jumplist
mark: m{char}, back: '{char}
see current marks: :marks
to previous location: Ctrl+O Ctrl+I or `` ''
to previous change: '.
search:
forwards/backwards: /, ?
whole word: \<word\> (I implemented it with \)
repeat: n
backwards: N (see also "previous location")
search words in a line: /words.*separated.*like.*this
using this kind of search is very useful in my notes because I write titles like
a/b/c d/e - searchable with /b.*e for example
in many files
vimgrep /pattern/ * (or ** for recursive)
go to next match with :cn
php:
Phptags: sorrounds file with <?php ?> (uses mark p)
text objects:
i# doesn't select bounds, a# does
word: w, w, W, W
sentence: s, s
paragraph: p, p: (don't confuse with )/} alone!) cool for deleting/indenting
parenthesis/block: ) > } " '
custom: function: f, camelCasePart: ic
indented block
i, l (including line below as well modified from original I)
movements/go to:
t{char}
till before occurrence of char
to quote, parenthesis, semicolon: t", t), t;
f{char}: till occurrence of char
{/}: block/paragraph
(/): sentence
ga: go up one indentation level
macros:
start recording: q{char}
stop recording: q
replay macro: @q
viewports/split:
:sp
C-w C-w
C-w k
same size: C-w =
resize: C-w +/-
swap: C-w r
all:
select all: <C-a>
delete all: dD
select with S-Arrow: does not work. mapped <C-Up> and <C-Down>
file specific setting: autocmd FileType ext cmd
templates
autocmd BufNewFile * silent! 0r ~/.vim/skel/tmpl.%:e
Tpl templatename, Etpl templatename
located in mynotes/templates
regular expressions
wikipedia is cool
or: \|
any order: .*red\&.*blue
compile:
make: F7, :make
jump errors: :clist, :cp F9, F10 :cn, :cfirst, :clast
first error: F8
special maps/custom/personal maps/commands/customizations:
undo from insert mode: <A-u>
undo undo with C-y
arrows exit insert mode
moved Esc to caps-lock
cmapped ö to <CR>
nmapped ö to :
mapped ä to /
pipe to vim: | vim -
rename:
:saveas newname
:!rm oldname
make vim/custom vim
notes:
check what has been installed: vim --version
on changes to configuration: make distclean
install python-dev ruby ruby1.8-dev
install:
hg update v7-3-206
in src/Makefile uncomment:
CONF_OPT_RUBY = --enable-rubyinterp
CONF_OPT_PYTHON = --enable-pythoninterp
CONF_OPT_FEAT = --with-features=huge
make
calls ./configure with the options set
sudo make install
long lines:
:set wrap
:set linebreak
:set textwidth=width
reformat
gq
current par: gqap
current line: gqq
gj, gk instead of j, k
delete before start position of insert:
backspacing=indent,start,eol
scrolling:
scrolling relative to cursor
scroll-cursor, where you want current line:
on top: zt (zw<CR> to start of line)
on center: zz (z.)
at bottom: zb (z-)
scroll and keep cursor where it is <C-j>, <C-k>
repeat last command: @: and then @@
tags:
for now the option to navigate through the files I like most is [[#command-t]]
ctags:
ctags
cscope
:h 29.1
generate
install exuberant-ctags
ctags *.c
ctags -R .
:set tags=maindir/**/tags
jump to tag
:tag, :stag
under cursor

locally: gD
in function: gd
:tags
autotag
update tags on save
note that removed files are not updated -> needs manual update from time to time
taglist
:h taglist.txt
:h taglist-options
:TlistToggle <F11>
if necessary Tlist_Inc_Winwidth=0
add files:
:TlistAddFiles[Recursive] dir
remove: d
update: u
let Tlist_Auto_Update=1
:TlistSessionSave file
:TlistSessionLoad file
jump to tag <CR>
in new tab: t
abbreviations!!!:
abbr striong string
decrement: <C-x>
increment: <C-a> (not in my case)
modeline: help modeline cool!
Write a Comment
Name:
*
Email:
Website:
If you are human write 'h':
*
Title:
*
Your comment:
*
* These fields are mandatory.
© Copyright 2009-2011 Nicola Marcacci Rossi