Effective text editing with vim
-
Upload
xprayc -
Category
Technology
-
view
1.911 -
download
0
description
Transcript of Effective text editing with vim
![Page 1: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/1.jpg)
Effective Text Editing With Vim by Kentwang
11年3月7日星期一
![Page 2: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/2.jpg)
Effective text editing
“Seven habits of effective text editing”
- Bram Moolenaar
11年3月7日星期一
![Page 3: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/3.jpg)
Problem
Got lots of text to edit
- source code
- config file
- log
- etc.
11年3月7日星期一
![Page 4: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/4.jpg)
Problem
Got lots of text to edit
- source code
- config file
- log
- etc.But don’t h
ave enough tim
e!
11年3月7日星期一
![Page 5: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/5.jpg)
Tool
• Selecting a good editor is the first step towards effective text editing
• Obviously, Vim is used here
11年3月7日星期一
![Page 6: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/6.jpg)
What is vim
11年3月7日星期一
![Page 7: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/7.jpg)
Comments
11年3月7日星期一
![Page 8: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/8.jpg)
Lots of people said like this
11年3月7日星期一
![Page 9: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/9.jpg)
11年3月7日星期一
![Page 10: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/10.jpg)
难用
11年3月7日星期一
![Page 11: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/11.jpg)
其实心里往往这么想...
11年3月7日星期一
![Page 12: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/12.jpg)
11年3月7日星期一
![Page 13: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/13.jpg)
真TMD难用
11年3月7日星期一
![Page 14: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/14.jpg)
But, some in other way
11年3月7日星期一
![Page 15: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/15.jpg)
11年3月7日星期一
![Page 16: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/16.jpg)
爽11年3月7日星期一
![Page 17: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/17.jpg)
爽爽11年3月7日星期一
![Page 18: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/18.jpg)
Why
11年3月7日星期一
![Page 19: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/19.jpg)
Different view
11年3月7日星期一
![Page 20: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/20.jpg)
Different view
11年3月7日星期一
![Page 21: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/21.jpg)
Different view
11年3月7日星期一
![Page 22: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/22.jpg)
Vim is a tool, the use of which must be learned
11年3月7日星期一
![Page 23: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/23.jpg)
How to improve
11年3月7日星期一
![Page 24: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/24.jpg)
Basic steps
1. Detect inefficiency
2. Find a quicker way
3. Make it a habit
11年3月7日星期一
![Page 25: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/25.jpg)
Habit 1:Moving around quickly
11年3月7日星期一
![Page 26: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/26.jpg)
Feature
11年3月7日星期一
![Page 27: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/27.jpg)
Feature
VS
11年3月7日星期一
![Page 28: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/28.jpg)
Feature
Who moved my mouse !
VS
11年3月7日星期一
![Page 29: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/29.jpg)
Detect ineffeciency
• Depend on mouse
• Use direction keys
• One line/column each time
• Hard to find match things
11年3月7日星期一
![Page 30: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/30.jpg)
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
11年3月7日星期一
![Page 31: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/31.jpg)
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
11年3月7日星期一
![Page 32: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/32.jpg)
Detect ineffeciency
• Typical you search like this
11年3月7日星期一
![Page 33: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/33.jpg)
Detect ineffeciency
• Typical you search like this
/FuncName
11年3月7日星期一
![Page 34: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/34.jpg)
Detect ineffeciency
• Typical you search like this
/FuncNamennnn...
11年3月7日星期一
![Page 35: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/35.jpg)
Find a quicker way
• The hlsearch option
• The * command
• Folding with ‘zf ’ , ‘zo’ and ‘zc’
11年3月7日星期一
![Page 36: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/36.jpg)
Make it a habit
• Put this in your vimrc file
• Use * again and again
• Use command completion (using <tab>)
• Use fold when needed
set hlsearch
11年3月7日星期一
![Page 37: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/37.jpg)
Habit 2:Don’t type it twice
11年3月7日星期一
![Page 38: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/38.jpg)
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
11年3月7日星期一
![Page 39: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/39.jpg)
Find a quicker way
• Insert mode completion
• Ctrl - N & Ctrl -P
• Omni-completion
• Automatic indenting
11年3月7日星期一
![Page 40: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/40.jpg)
Find a quicker way
11年3月7日星期一
![Page 41: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/41.jpg)
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
11年3月7日星期一
![Page 42: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/42.jpg)
Habit 3:Fix it when it’s wrong
11年3月7日星期一
![Page 43: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/43.jpg)
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
11年3月7日星期一
![Page 44: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/44.jpg)
Find a quicker way
• Spell correction macros
:iabbrev accnt account
:syntax keyword WordError accnt
11年3月7日星期一
![Page 45: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/45.jpg)
Make it a habit• Add new words if you see them
11年3月7日星期一
![Page 46: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/46.jpg)
Habit 4:A file seldom comes
alone
11年3月7日星期一
![Page 47: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/47.jpg)
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
11年3月7日星期一
![Page 48: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/48.jpg)
A quicker way
• Find & grep
• ctags & taglist
• Quickfix
11年3月7日星期一
![Page 49: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/49.jpg)
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
11年3月7日星期一
![Page 50: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/50.jpg)
Make it a habit
• Use quickfix as often as possible
• Drop ‘a.vim’ to your plugin directory
• Remember to use ‘ctags’ and ‘taglist’
11年3月7日星期一
![Page 51: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/51.jpg)
Habit 5:Let’s work together
11年3月7日星期一
![Page 52: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/52.jpg)
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
11年3月7日星期一
![Page 53: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/53.jpg)
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
11年3月7日星期一
![Page 54: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/54.jpg)
A quicker way
11年3月7日星期一
![Page 55: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/55.jpg)
More Effective
• Integrate with SVN
• SVN_EDITOR environment variable
• Set vim as diff program for svn diff
11年3月7日星期一
![Page 56: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/56.jpg)
Make it a habit
• Use vimdiff instead of windows compare tools
• Add this line to your bashrc:
• Edit ~/.subversion/config, set vim as the diff-cmd
• If you are a big fan, try Vimperator / Vimium
export SVN_EDITOR=vim
11年3月7日星期一
![Page 57: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/57.jpg)
Habit 6:Sharpen the saw
11年3月7日星期一
![Page 58: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/58.jpg)
Sharpen the saw
• Keep on tuning the set of commands you use for your needs
• Learn from what you did
• Type :help command when you need help
11年3月7日星期一
![Page 59: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/59.jpg)
Sharpen the saw
• Replacing
• automatic indenting
• quickfix
• plugins
• key-mapping
11年3月7日星期一
![Page 60: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/60.jpg)
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
11年3月7日星期一
![Page 61: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/61.jpg)
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
11年3月7日星期一
![Page 62: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/62.jpg)
Encoding
• fileencoding
• encoding
• LC_CTYPE
11年3月7日星期一
![Page 63: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/63.jpg)
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 improving11年3月7日星期一
![Page 64: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/64.jpg)
How 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.
NOT
11年3月7日星期一
![Page 65: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/65.jpg)
How 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.
NOT
11年3月7日星期一
![Page 66: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/66.jpg)
Learn it, time rewarded.
11年3月7日星期一
![Page 67: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/67.jpg)
One more thing
11年3月7日星期一
![Page 68: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/68.jpg)
:help user-manual
11年3月7日星期一
![Page 69: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/69.jpg)
Questions?
11年3月7日星期一
![Page 70: Effective text editing with vim](https://reader036.fdocuments.us/reader036/viewer/2022062405/555f1085d8b42a5c388b517e/html5/thumbnails/70.jpg)
The End
11年3月7日星期一