29. Detect ineffeciency
• Depend on mouse
• Use direction keys
• One line/column each time
• Hard to find match things
30. Find a quicker way
• Edit without mouse
• Use ‘h j k l’ instead of direction keys
• Move multi-line each time
• Use ‘%’ to find match things
31. Find a quicker way
• Edit without mouse
• Use ‘h j k l’ instead of direction keys
• Move multi-line each time
• Use ‘%’ to find match things
Samples:
20G jump to line 20
^ jump to first non blank of line
$ jump to end of line
% jump to match ( #if #endif etc.)
10j jump to 10 lines below
5w jump to 5 words after
38. Detect ineffeciency
• Long class names
- TiXmlAttributeSet
• Long function names
- QueryDoubleAttribute
• Hard to type and often type it wrong
• Lots of time on indenting and code style
39. Find a quicker way
• Insert mode completion
• Ctrl - N & Ctrl -P
• Omni-completion
• Automatic indenting
41. Make it a habit
• Use Ctrl + P and Ctrl + N again and again
• Use omni-completion if needed
• Add these lines in vimrc:
filetype plugin on
filetype indent on
“ auto indent
set ai
set smarttab
43. Detect ineffeciency
• Often misspell English words
• Have to check text carefully
• Need a sequence of actions to correct tem
• After correct you misspell again and again
44. Find a quicker way
• Spell correction macros
:iabbrev accnt account
:syntax keyword WordError accnt
45. Make it a habit
• Add new words if you see them
47. Detect ineffeciency
• When working on a new project you have a
hard time finding your way in the files
• You have to jump between files all the time
• Edit in an editor but compile in terminal
• Hard to find declaration of symbol
49. Many other ways
• use ‘gf’ to goto header file
• Use ‘[I’ to find the word under the cursor
in include files. Or ‘[<Tab>’ to jump there
• Use a.vim to switch between .c and .h
50. Make it a habit
• Use quickfix as often as possible
• Drop ‘a.vim’ to your plugin directory
• Remember to use ‘ctags’ and ‘taglist’
52. Detect ineffeciency
• Often need to compare files
• Switch out of terminal and use windows
compare tools
• Sometimes have to transfer file from IDC
server to local first, just because can’t use
windows compare tools there and diff
command is not so readable
53. A quicker way
• vimdiff or vim -d
• Works well in both terminal and GUI
• Pretty result and convenient interactive
• Use ‘[c’ ‘]c’ to jump to changes, ‘do’ ‘dg’ to
copy text from one to another
55. More Effective
• Integrate with SVN
• SVN_EDITOR environment variable
• Set vim as diff program for svn diff
56. Make it a habit
• Use vimdiff instead of windows compare
tools
• Add this line to your bashrc:
export SVN_EDITOR=vim
• Edit ~/.subversion/config, set vim as the
diff-cmd
• If you are a big fan, try Vimperator / Vimium
60. Replacing
• Replace a word
• Use < and > to match the start/end of
word
Samples:
10, 20s/Old/New/g
%s/Old/New/g
%s/<Old/New/g
%s/<Old>/New/g
61. Replacing
• Replacing in several files
• Record / Execute register
Sample:
vim *.cpp // start vim
qq // start recording into the q register
:%s/<OldFunc>/NewFunc/ge // replacing
:wnext // write and goto next file
q // stop recording
@q // execute
63. Summary
• Step 1: Detect inefficiency
- Find out what you waste time on
• Step 2: Find a quicker way
- read the online help & quick reference
- ask friends & google
- do it yourself
• Step 3: Make it a habit
- do it
- keep on improving
64. How NOT to effectively
• No time to read documents or new
commands. keep on using primitive
commands.
• Want to learn every feature and use the
most efficient command all the time.
65. How NOT to effectively
• No time to read documents or new
commands. keep on using primitive
commands.
• Want to learn every feature and use the
most efficient command all the time.