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

本文介绍如何使用Vim编辑器通过动词、修饰符和对象的组合来高效地进行文本编辑。文中列举了一些基本操作如删除当前单词(diw)、更改当前句子(cis)等,并介绍了如何安装插件来增加新的文本对象,例如ruby块(r)和包围(s),以及新的动词如注释(gc)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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(:)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值