Vim as Language
Arguably the most brilliant thing about vim is that as you use it you begin to think in it. vim is set up to function like a language, complete with nouns, verbs, and adverbs.
Keep in mind that the terms I’m going to use here are not technically correct, but should help you understand better how vim works. Again, this guide is not meant to replace a full book or the help—it’s mean to help you get what doesn’t come easily from those types of resources.
Verbs: Verbs are the actions we take, and they can be performed on nouns. Here are some examples:
y: yank (copy)
v: visually select (V for line vs. character)
Modifiers: Modifiers are used before nouns to describe the way in which you’re going to do something. Some examples:
NUM: number (e.g.: 1, 2, 10)
t: searches for something and stops before it
f: searches for that thing and lands on it
/: find a string (literal or regex)
Nouns: In English, nouns are objects you do something to. They are objects. With vim it’s the same. Here are some vim nouns:
): sentence (another way of doing it)
}: paragraph (another way of doing it)
t: tag (think HTML/XML)
b: block (think programming)
Nouns as motion: You can also use nouns as motions, meaning you can move around your content using them as the size of your jump. We’ll see examples of this below in the moving section.
Building sentences (commands) using this language
Ok, so we have the various pieces, so how would you build a sentence using them? Well, just like English, you combine the verbs, modifiers, and nouns in (soon to be) intuitive ways.
For the notation below, just remember … VMN (verb, modifier, noun):
# Delete two words: d2w
# Change inside sentence (delete the current one and enter insert mode): cis
# Yank inside paragraph (copy the paragraph you’re in): yip
# Change to open bracket (change text from where you are to next open bracket): ct<
Remember, the “to” here was an open bracket, but it could have been anything. And the syntax for “to” was simply t, so I could have said dt. or yt; for “delete to the next period”, or “copy to the next semicolon”.
Isn’t that beautiful? Using this thought process turns your text editing into an intuitive elegance, and like any other language the more you use it the more naturally it will come to you.
- - - - - - - -
Getting Things Done
Now that we’ve handled some fundamentals, let’s get tangible and functional.
Working With Your File
Some quick basics on working with your file.
vi file: open your file in vim
:w: write your changes to the file
:q!: get out of vim (quit), but without saving your changes (!)
:wq: write your changes and exit vim
:saveas ~/some/path/: save your file to that locationvim
While :wq works I tend to use ZZ, which doesn’t require the “:” and just seems faster to me. You can also use :x
ZZ: a faster way to do :wq
Searching Your Text
One of the first things you need to be able to do with an editor is find text you’re looking for. vim has extremely powerful search capabilities, and we’ll talk about some of them now.
Searching by string
One of most basic and powerful ways to search in vim is to enter the “/” command, which takes you to the bottom of your window, and then type what you’re looking for and press ENTER.
# Search for include
That’ll light up all the hits, …
Once you’ve done your search, you can press “n” to go to the next instance of the result, or “N” to go to the previous one. You can also start by searching backward by using “?” instead of “/”.
EXCERPTS FROM Daniel Messier’s at: https://danielmiessler.com/study/vim/