2. Getting Around
h/j/k/l
gg and G – start/end of buffer
^ - first non-blank character in current line
$ - last character on current line
CTRL-u / CTRL-d – page up / page down
:n – go to line number n.
H/M/L – go to first/middle/last line on screen*
% - jump to corresponding bracket [] {} ()
3. Marks
m followed by a letter to set a mark
` followed by the letter – jump to that mark
:marks will list current marks
Vim has some special marks (a few examples):
`. - jump to position where the last change occured
`` - jump back to position where you jumped from
lots more found in :help `
4. Making Changes
y/d/c – yank/delete/change
Y/D/C – same as above, but specifies line*
p/P – paste before/after
combine with movements:
dw – delete word
cw – change word
dG – delete from cursor to end of file
c`a – change from cursor to mark a
5. Making Changes
y/d/c – yank/delete/change
Y/D/C – same as above, but specifies line*
p/P – paste after/before
x/r – delete/replace single character
combine with movements:
dw – delete word
cw – change word
dG – delete from cursor to end of file
c`a – change from cursor to mark a
use the . character to repeat last command
6. Visual Mode
v – enter visual mode
V – enter visual mode, but operate on a line
CTRL-v -enter visual mode, operate on a column
Use I to change all columns at once
combine with y/d/c for even more fun
7. Text Objects
used after an operator or visual mode
i – inner / a – ambient
a' / i' – operate on block of ''
a( / i( - operate of block of ()
a{ / i{ - operate of block of {}
at / it – operate of html or xml tags
8. Search
/ or ? - for a basic search (forward or backward)
I recommend :set ignore case, :set smartcase and
:set incsearch
n to repeat search, or N to repeat in opposite
direction
*/# - find next/previous of word under cursor
[I – list lines with word under cursor
set up a map to make this easier:
:map <space>f [I:let nr = input("Which one:
")<Bar>exe "normal " . nr ."[t"<CR>
9. Undos
u – undo, CTRL-R – redo
see also: undo-branches
time travel
:earlier Ns, m, h
:later Ns,m,h
Can't jump to the future when the code is already
done, sorry. Hoping for that feature in Vim 8
10. Splitting Windows
:sp -horizontal split
:vs – vertical split
:new
CTRL-w + movement to move between windows
I remap spacebar for easier commands
11. Configuration
.vimrc – global settings
.vim directory - plugins, color schemes, syntax
definitions, etc
browse github for ideas, or just fork one you like
:set – see your current settings
don't be afraid to consult :help to see what things
do
12. Config Examples
filtype plugin on – recoginize .py as python
filtype indent on – proper indentation (more on
this later)
set nu – turn line numbers on
set ruler – see where you are in the file
set t_Co=256 – 256 colors
cmap w!! %!sudo tee > /dev/null %
made changes to a read-only file? This mapping
allows you to use :w!! to save using sudo
13. More Config Examples
au BufReadPost * if line("'"") > 0 && line("'"") <=
line("$")|execute("normal `"")|endif
jumps cursor to last edited position on file open
set pastetoggle=<F10>
easy way to shift to paste mode to not screw up
indentation
nmap <silent> <F6> :set number!<CR>
turn line numbers on/off
set iskeyword-=-
use dash as a word seperator
14. Indentation
My biggest hang-up when I started with python
Found a python indent file that works pretty well
Found in .vim/after/indent/
Autoindents/unindents around keywords
Various other indent definitions available
(djangohtml is another I use)
= command will re-indent
use > and < to indent keys
15. Autocomplete
<tab> invokes autocomplete
Use options wildmode and wildmenu to change how
this works (I use list:longest,full)
Also work on filenames/directories (:e <tab>)
There are other forms of autocomplete:
Omnicomplete – Heuristics based completion, I
haven't had much luck
pydiction plugin – keyword/modules
16. tags
I map F4 to rebuild tags file using ctags
CTRL-] - jump to tag under cursor
CTRL-T – return to where you came from
:tag <tagname> - jump to a tag
If there are multiple matches, you select from a
list
taglist is another useful plugin to view the tags in
the current file
18. SelectBuf
Similar to a file explorer, but limited to buffers
already open
A must-have if you normally operate many
buffers at once
19. flake-8
wrapper for flake8 (must install seperately)
PyFlakes
PEP8
complexity checker
Can configure to ignore errors
I map to F5, as I also use makeprg for other
languages using the same key
20. Doxygen
Generate comment skeletons
:DoxLic - License
:DoxAuth - Author
:Dox - function/class block headers
Works well out of the box, but config options available
21. Other Plugins to Check Out
vimpdb
commandT
project
vcscommand
OScan
snippets
netrw
scratch