Wednesday, June 6, 2012

Learn to speak vim


看到了一篇蠻有趣的文章

http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-nouns-and-modifiers/

節錄如下

Using vim is like talking to your editor in ‘verb modifier object’ sentences, turned into acronyms

 learn some verbs: v (visual), c (change), d (delete), y (yank/copy). these are the most important. there are others
 learn some modifiers: i (inside), a (around), t (till..finds a character), f (find..like till except including the char), / (search..find a string/regex)
 learn some text objects: w (word), s (sentence) p (paragraph) b (block/parentheses), t (tag, works for html/xml) there are others

To move efficiently in vim, don’t try to do anything by pressing keys many times, instead speak to the editor in sentences

 delete the current word: diw (delete inside word)
 change current sentence: cis (change inside sentence)
 change a string inside quotes: ci” (change inside quote)
 change until next occurrence of ‘foo’: c/foo (change search foo)
 change everything from here to the letter X: ctX
 visually select this paragraph: vap (visual around paragraph)

If you nderstand the verbs and objects you’re dealing with, you will soon realize that adding a new plugin and learning a new verb or noun exponentially increases your productivity, as you can now apply it in all the sentences you already know. It’s just like learning a language.

No comments:

Post a Comment