当前位置: 首页 > 工具软件 > Speak It > 使用案例 >

Learn to speak vim – verbs, nouns, and modifiers!

杜正奇
2023-12-01

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 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.

Let’s add some new text object plugins!

  • 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 single quote to double 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!

Love this article? Here are some more you might like :)

Want an exceptionally curated collection of vim plugins and shortcuts?

Check out an early beta preview of my fully modularized vim/dotfile setup called YADR (Yet Another Dotfile Repo) which includes text object plugins for ruby blocks(r), indents(i), dates(da/df), function arguments(a), and ruby symbols(:)

 类似资料:

相关阅读

相关文章

相关问答