What if you could talk to your editor?

The vim text editor is something different from what people are used to. It is not a blank sheet of paper where you type some text and then try to make it look nice. It is more like a assistant that take notes of what you type and than do stuff with it.

For you to use vim the first thing you should know is that you can open a terminal and type vimtutor so that you can learn the basics about vim. Do not expect that you will learn vim by using it. It is not that kind of tool. You learn it by studying or at least by using its help system.

Once you've grasped concepts like vim's modes, motions and operations, you'll wish many other tools to act like vim. That's because vim does not have a set of shortcut commands, it has a language and each new expression in this language you learn enables you to do a whole lot of things.

Do it again

Lot's of programs have repeat commands. Office suites do have such commands but I usually don't use them. Actually, it is not really a common thing for someone to want to repeat the previous action. But vim's repeat command is different. The thing is that a vim command resembles a sentence: it tells vim to do a specific action a number of times with a given part of the content. An example will make things more clear: let's imagine you created a list of three items, something like:

    1 - beans
    2 - rice
    3 - chocolate
    

but then, you created two new items before those, and want to update the numbers. You may delete 1 and write 3, then delete 2 and write 4 and so on. With vim, you can tell it to add 2 to the number (do something x times to some content) and then ask it to repeat the operation with the other numbers. In vim you do that with the following commands, starting at the char "1":

2Ctrl+aj.j.

It may seem weird at first, but bear with me. The number 2 says: "do the following action 2 times". Ctr+a means increase this number by one. "j" means "down a line" and "." means "do it again".

I know this is awkward, but it helps a lot that for any command you may use a number before it to repeat it that number of times. If you want to delete 3 characters you may type 3x, since "x" means "delete a char".

Cheatsheet

Actions
CommandMeaning
cChange
dDelete (cut)
yYank (copy)
pPut (paste)
mSet Mark
qRecord
iInsert under the cursor
IInsert in the beginning of the line
aAppend after the cursor
AAppend in the end of the line
xDelete under the cursor

These actions are pretty straight forward and most of them will be found in any good text editor. Now, enters the motions. An action needs something to act upon. Delete needs to know what to delete. Think of it as a parameter to a function. Any motion you know in vim will do. Thus, if you type "dj", you will delete until the line bellow. Here is a table with some motions

Motions
MotionMeaning
jOne line down
kOne line up
lOne character left
hOne character left
ctrl+oTo where I was backwards
ctrl+iTo where I was forward
iInside
aAround
iwInside a word
iWInside a word, with symbols
ipInside a Paragraph
isInside a Sentence
itInside a Inside Tag

Integration

Use any command line tool you are already used to, and learn some others. You can invoke them using :!tool where tool is the tool you want to use

Use :wa|!git add -p to save all files and start an interactive session of git add. This is quite useful. You can also map a key combination to :!git so that it is easier to invoke git.

Use vip:!sort to select a paragraph and sort it's lines using the sort tool.

Integration examples
CommandMeaning
vip:!sortSort the lines in the current paragraph using the external sort utility.
vip:!grep marsFilter the lines in the current paragraph using the external grep utility.
vip:!awk -F ':' '{print $2}'Filter the lines in the current paragraph using the external awk utility.

This ease of integration with any tool that can read from std input and write to external output gives you complete freedom to write utilities that you'd like to use in whatever language you choose. Better yet, you can use your utility directly from the terminal and use it in Vim without making any changes to it.

Ex commands

Use vim's command line to issue "ex" commands.

Use a simple syntax start-line,end-line command

Ex commands
CommandMeaning
:5t.Copy the line 5 here
:-5t.Copy the line 5 lines above this to here
:-5,-3t.Copy the lines from -5 to -3 to here
:-5,-3t10Copy the lines from -5 to -3 to line 10
:5m.Move the line 5 here
:-5m.Move the line 5 lines above this to here
:-5,-3m.Move the lines from -5 to -3 to here
:-5,-3m10Move the lines from -5 to -3 to line 10

Reuse your history

Any command you issued in Vim's command line can be reused from history simply by entering the command line with : and pressing the up arrow key until you find the command.

You can also start typing and then press tab to autocomplete or press the up arrow to find the previous command in history that conforms to what you've typed so far.

You can also open a window with your editable command history. Edit any line to conform to your needs and press Enter to issue the edited command.

Using q
q:Open the history of commands to edit and redo
q/Open the history of searches to edit and redo
CommandMeaning

References

Making Vim your own

I think there's a case for avoiding to install many plugins to extend Vim. The beauty of Vim lies in that its features integrate really well and each provide very small pieces of functionality which you can easily extend.

But there are some awesome plugins out there.

ALE

https://github.com/dense-analysis/ale

So far I've created a single mapping that basically does a :ALE so that I can complete the command.