Your SlideShare is downloading. ×
Effective text editing with vim
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Effective text editing with vim

1,874

Published on

share something about vim skills. …

share something about vim skills.

lots from 《Seven habit

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,874
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
48
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Effective Text EditingWith Vimby Kentwang
  • 2. Effective text editing“Seven habits of effectivetext editing” - Bram Moolenaar
  • 3. ProblemGot lots of text to edit- source code- config file- log- etc.
  • 4. ProblemGot lots of text to edit- source code e!- config file gh tim ou- log have en ’t- etc. Bu td on
  • 5. Tool• Selecting a good editor is the first step towards effective text editing• Obviously, Vim is used here
  • 6. What is vim
  • 7. Comments
  • 8. Lots of people said like this
  • 9. ...
  • 10. TMD
  • 11. But, some in other way
  • 12. Why
  • 13. Different view
  • 14. Different view
  • 15. Different view
  • 16. Vim is a tool, the use ofwhich must be learned
  • 17. How to improve
  • 18. Basic steps1. Detect inefficiency2. Find a quicker way3. Make it a habit
  • 19. Habit 1:Moving around quickly
  • 20. Feature
  • 21. Feature VS
  • 22. Feature VSWho moved my mouse !
  • 23. Detect ineffeciency• Depend on mouse• Use direction keys• One line/column each time• Hard to find match things
  • 24. 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
  • 25. 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
  • 26. Detect ineffeciency• Typical you search like this
  • 27. Detect ineffeciency• Typical you search like this /FuncName
  • 28. Detect ineffeciency• Typical you search like this /FuncName n n n n ...
  • 29. Find a quicker way• The hlsearch option• The * command• Folding with ‘zf’ , ‘zo’ and ‘zc’
  • 30. Make it a habit• Put this in your vimrc file set hlsearch• Use * again and again• Use command completion (using <tab>)• Use fold when needed
  • 31. Habit 2:Don’t type it twice
  • 32. 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
  • 33. Find a quicker way• Insert mode completion• Ctrl - N & Ctrl -P• Omni-completion• Automatic indenting
  • 34. Find a quicker way
  • 35. 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
  • 36. Habit 3:Fix it when it’s wrong
  • 37. 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
  • 38. Find a quicker way• Spell correction macros :iabbrev accnt account :syntax keyword WordError accnt
  • 39. Make it a habit• Add new words if you see them
  • 40. Habit 4:A file seldom comes alone
  • 41. 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
  • 42. A quicker way• Find & grep• ctags & taglist• Quickfix
  • 43. 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
  • 44. Make it a habit• Use quickfix as often as possible• Drop ‘a.vim’ to your plugin directory• Remember to use ‘ctags’ and ‘taglist’
  • 45. Habit 5:Let’s work together
  • 46. 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
  • 47. 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
  • 48. A quicker way
  • 49. More Effective• Integrate with SVN• SVN_EDITOR environment variable• Set vim as diff program for svn diff
  • 50. 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
  • 51. Habit 6:Sharpen the saw
  • 52. 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
  • 53. Sharpen the saw• Replacing• automatic indenting• quickfix• plugins• key-mapping
  • 54. 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
  • 55. Replacing• Replacing in several files• Record / Execute registerSample: 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
  • 56. Encoding• fileencoding• encoding• LC_CTYPE
  • 57. 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
  • 58. 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.
  • 59. 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.
  • 60. Learn it, time rewarded.
  • 61. One more thing
  • 62. :help user-manual
  • 63. Questions?
  • 64. The End

×