Part of being effective as a developer is mastering your tools. You should have a good understanding of your editor, version control, language, static analysis tools, unit test tools, etc. You don't have to master them all at once, but you should be improving your skills with these tools all the time. Spending a little time practicing every day can improve you efficiency for the rest of your career.
This talk is going to focus on the editor. Although, vim is my preferred editor, the concepts apply to most proogrammer editors. The actual commands or keystrokes may be different from editor to editor, but many of the concepts remain the same.
Learn the features that help you to edit, rather than write. You will spend much more time changing text than you spend writing it for the first time. vim is optimized for editing.
filetype on
filetype plugin indent on
set nocompatible " not vi compatible
set ignorecase " ignore case on searches
set smartcase " ... unless there is an uppercase character
syntax on
set incsearch " perform an incremental search
set hlsearch " highlight matches when searching
.
command:q[a][!]
- quit without saving:wq[a]
- save and quit:x[a]
- optionally save and quitZZ
/ ZQ
Running joke about people getting in to vim and not being able to get out.
vimtutor
- usually installed with vim:help {command}
h
/j
/k
/l
b
/B
e
/E
w
/W
ge
/gE
0
/^
/$
f
/t
/F
/T ;
/,
H
/M
/L
zt
/zz
/zb
gg
G
{line}G
*
/#
Avoid the arrow keys. The arrow keys require you to move you hands away from the home row, which slows you down. Also, the arrow keys are in different places on different keyboards. This slows you down even more if you work on different computers.
[repeat]{command}{motion}
- apply command over range of motion[repeat]{command}{command}
- apply command to lines{repeat}{command}
- apply a command multiple timesd{motion}
/D
(D => d$)c{motion}
/C
(C => d$a)s{motion}
/S
(s => xi) (S => ^C)y{motion}
p
/P
%
- matching delimiter<
/>
- outdent/indent~
/g~{motion}
/gU{motion}
/gu{motion}
Ctrl-A
/Ctrl-X
- increment/decrement number.
repeats the last edit command{motion}.
most efficient repeatu
- undo most recent editCtrl-r
- redo most recent undone editxp
- transpose two charactersddp
- transpoe two lines/regex
- searchn
/N
- next/previous match:{range}s/regex/replace/[c][g]
- search and replace range:%s/regex/replace/[c][g]
- search and replace file={motion}
/{count}==
- apply indent programCtrl-L
- redraw screen