Yan Pritzker photographer, entrepreneur, software engineer, musician, skier

Blog :: Git Workflows Book :: Dotfiles :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

I am a photographer, entrepreneur, software engineer, guitarist, climber, and telemark skier

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Enterprise intelligence with prediction markets

Find out what your team, colleagues and partners really know about the future — and leverage their knowledge to improve business decisions.

I'm the founder of Planypus, the place to share your plans!

Archives

Contact

Reach me at yan at pritzker.ws

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

Posted 16 December 2011 @ 12pm | Tagged vim


Submit to HN

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!

Resources and Further Reading

20 Comments

Posted by
ales
16 December 2011 @ 5pm

I have been using vim for a couple of years now, but never thought about it like this. Thanks for the interesting insight!


Posted by
Kris
16 December 2011 @ 6pm

Holy… wow, this is quite the improvement I just got. I learn much better when I understand the idea behind something, and while I knew the verb-modifier-object structure, the ‘in’ and ‘around’, as well as combining them with quotes, parenthesis, sentences – those will improve my workflow quite a bit. Cheers!


Posted by
Matt
16 December 2011 @ 8pm

ct$ does not “change till end”, it “changes till dollar sign” (as in, an actual dollar sign in your text). If ct$ did “change till end”, it would not be equivalent to cc, which is “change the entire current line”, it would be equivalent to C, which is “change from current location to end of current line”


Posted by
Victor
16 December 2011 @ 9pm

@Matt

There are exceptions too :) But I like the whole idea. It’s good to see Vim commands put that way.


Posted by
Yan
16 December 2011 @ 10pm

oops thanks Matt! should have double checked myself :)
@Kris thanks. I made a monumental leap in vim once I got the verb/noun understanding. It should be stated much more clearly in the tutorial!


Posted by
Pet
17 December 2011 @ 4am

Realy nice idea how to learn/teach vim. Big thanks.


Posted by
googya
18 December 2011 @ 6am

nice article! after It’s so important to understand the verb and object! thank you!


Posted by
Elliot Smith
19 December 2011 @ 1am

Really helpful post. I sort of know in the back of my mind that the commands all stood for something useful I just hadn’t taken the time to look into it. It’s always nice when seemingly complex things turn out to be simple like this.

Thanks, Elliot


[...] http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-nouns-and-modifiers/ A great clever way to use and learn Vim: speak to him! [...]


Posted by
Eric
19 December 2011 @ 9pm

Thanks for pointing out some extensions I haven’t heard of. Here’s my contribution:

Install argtextobj: you get a new object, the argument or ‘a’

http://www.vim.org/scripts/script.php?script_id=2699


Posted by
Yan
20 December 2011 @ 3am

@Eric awesome thanks for pointing that one out. I am adding it to my setup, which I’m tweaking for a 1.0 release slated sometime in January probably. I already have textobj plugins for ruby and indent blocks in there. If you aren’t already following, check out https://github.com/skwp/dotfiles – I would love feedback


Posted by
‘Speaking’ vim « 0ddn1x: tricks with *nix
20 December 2011 @ 11am


Posted by
Infovore » Links for December 21st
21 December 2011 @ 12pm

[...] Learn to speak vim – verbs, nouns, and modifiers! – Yan Pritzker "Using vim is like talking to your editor in ‘verb modifier object’ sentences, turned into acronyms." Which is a good way of thinking of it. (tags: vim editor text ) [...]


Posted by
Speak Vim | fozbaca’s WordPress
23 December 2011 @ 10am

[...] Yan Pritzker: “To move efficiently in vim, don’t try to do anything by pressing keys many times, instead speak to the editor in sentences.” [...]


Posted by
tony
29 December 2011 @ 8pm

But “i” is “insert” and “a” is “append” and “r” is “replace”.
To move efficiently, is just a matter of knowing built-in stuff like 2{ (up 2 paragraphs), f5t (forward to the 5th “t”), 5j (down 5 lines), etc.


Posted by
landmark mumbai
21 March 2012 @ 6am

I have been using vim for many years now, but never thought about it like this.Really thanks for the interesting insight.


Posted by
Why Vim? | Terminally Incoherent
21 March 2012 @ 9am

[...] Pritzker apptly explained it like this: vim commands are like a language you can [...]


[...] “Smash Into Vim” video (which I highly recommend) likened it to “text surgery    http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-nouns-and-modifiers/  [...]


[...] I’ve just come across this excellent article on learning to speak vim, to get a more in depth [...]


Posted by
Quora
13 May 2012 @ 5pm

What are some good resources for learning Vim?…

Okay, this iis going to be a complete hodgepodge of blag posts, command sheets, and Vim 101 posts, and editorials. Look at a whole variety of you’re just starting out, so you can be exposed to a huge variety of views. First thing: Learn about the sema…


Leave a Comment