现在的位置: 首页 > 综合 > 正文

Learn to speak vim – verbs, nouns, and modifiers!To move efficiently in vim, don’t try to do anythin

2013年09月01日 ⁄ 综合 ⁄ 共 1522字 ⁄ 字号 评论关闭

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 objects: w (word), s (sentence) p (paragraph) there are others
  • learn some modifiers: i (inside), a (around), t (till..finds a character)

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 everything from here to the letter X: ctX
  • copy this line: yt$ (yank till $ – end), or yy
  • change this line ct$ (change till $) or cc (are you seeing a pattern?)
  • visually select this paragraph: vap (visual around paragraph)

If you understand 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.

  • install surround.vim: vim-surround-
    you get a new noun, the ‘surround’ (s or S)

    • visually select a word and surround it with quotes: viwS”
    • change surround from quote to single quote: cs’”
  • install vim-textobj-rubyblock –
    you get a new noun, the ‘ruby block’ (r)

    • delete current ruby block: dir (delete inside ruby block)
    • visually select a ruby function: var (visual around ruby block)
    • visually select the innards of a function: vir (visual inside ruby block)
  • install tComment –
    new verb: “gc” (go comment)

    • comment the current ruby method: gcar (go comment around ruby)

Now go out and learn a new verb or noun every day!

抱歉!评论已关闭.