Search
The Vim Language (and Motions)
Why are there many users (and many new ones) still using Vim or Neovim, you might ask?
It’s mainly for vim language/motions. Many believe, me included that you need to know 1000 shortcuts. But when I realized that Vim has a language that works like grammar, things changed. I noticed that I only have to remember a couple of modes (Copying (or yanking) in Vim with y
, deleting with d
, pasting with p
, changing with c
) and shortcuts, which I can then combine. This made me want to try it, and I didn’t regret it.
It is surprising to me; I use it even more for writing text than coding, which I think I will use it for. However, the efficiency of editing text with the precision of a surgeon is even more helpful when I edit and rearrange my blogs or books.
# Vim Language
Vim has a terrific language or grammar behind its shortcuts. Instead, remember a thousand shortcuts; you can learn a couple and combine them. These are sometimes called the Vim language or Vim motions for moving around. This has nothing to do with the editor yet; they are universal and available in other editors as well.
For example,
VSVim for VSCode,
IdeaVim for the JetBrains products,
Vintage Mode for Sublime, and so on. But there are also Browser extensions like
Vimium or
Firenvim, and even Gmail adapted some of its
shortcuts for navigation (j
, k
for moving, g
for jumping).
Everyone who types on a computer eight hours a day should learn the Vim language. Yes, it’s hard in the beginning, but that’s everything new and different. getting better every day and having more fun coding or writing should motivate enough. The excuse of being too busy to learn while doing what you always did does not count.
Are you too busy to improve | Image from
steenschledermann
Typical hotkey without vim-motions
Typical hotkey with none-vim setup. They are useful, but very limited as I explain in my Vim write-up, making the case why I have chosen vim years back.
Source Boilerplate see Writing is Thinking
# The Grammar
As grammar has verbs, subjects, and objects, so does the Vim language. The grammar has different verbs to begin with. Copying (or yanking) in Vim with y
, deleting with d
, pasting with p
, changing with c
.
For example, the easiest shortcut is copying a line with yy
. In this case, yank is the verb and the second y
is a synonym for y_
. The y
is doubled up to make it easier to type since a joint operation.
Next, we can add movements. Each verb takes a subject to their movements. There are lots of movements (more in the next chapter); the easiest is with numbers. E.g. to copy three lines, you add three in front, such as 3yy
. You can do that with all verbs, e.g., deleting three lines 3dd
. Another would be {
and }
to move to the beginning or end of the paragraph, respectively.
In addition to verbs and subjects, the Vim language also has objects. E.g., we can save text into different clipboards (called a register in Vim) with "ay
. Here, we copy it into register a, which would be the object. We can paste it again by doing the same but using the verb paste instead of yank "ap
.
If you will, there are even adjectives and adverbs with prefixes. Usually, you use a verb and an object. But instead of going down three lines with 3J
, which joins the following three lines. You could add d5}
, which means “delete from the current line through the end of the fifth paragraph down from here.”,
For me, the most considerable magic and myth about Vim. All of the vim language is how you navigate end edit text, and it still has nothing to do with the editor. Sure Vim was the one that introduced and perfectionized them, but as listed above, you can get them anywhere else. This goes deep into the Vim language, yet we still need to touch the editor. This is important to know.
I hope you start seeing the power of such a pattern. With a couple of verbs and objects, you can already know hundreds of combinations without memorizing them. You can see a video on Mastering the Vim Language on the Vim language or read a full plea for the Vim language on a terrific StackOverflow comment.
# Vim Motions
As touched in the Vim language. Vim motions are how you navigate, whether you navigate to the end of the word or back to the start of the document; these are all motions.
These are the first thing you start learning (and hating) when you start learning. It’s extra hard to know initially, but something you want everywhere when you get used to it. Instead of using arrow keys, Vim uses jk
to move down and up and hl
to move left and right. The main idea is to use the keys that your right hand naturally rests on. You do not need to move any of your hands or even fingers for navigation. Again, this seems like a small thing, but once learned, you know why everyone is telling you that.
Some common ones are:
|
|
You find the most important ones to start in this cheatsheet:
Vim Command Cheat Sheet from Cloud Guru
My own Cheatsheet
# Modes (normal, insert, visual, command)
Modes are what get you confused at the beginning. When you launch Vim, you are not typing what you click on your keyboard as you are not in the “insert” mode that you know. Instead, the normal mode you are in lets you do the commands explained in the above Vim language and motions.
Vim is the only editor that optimizes editing text instead of writing from a blank page.
Three modes illustrated (escape mode being the command mode) | Image from
Geekforgeeks
That’s another reason Vim makes you so efficient: you have different modes for each phase of your task—normal mode for reading code and navigating quickly. Insert mode when you want to add some code or text. Visual mode is unique, the same as highlighting text with the mouse, but with the above Vim motions. The command mode is the powerhouse, where you can type Linux commands such as formatting a JSON file with :%!jq
(whereas
jq is a command line tool installed on your machine) and execute them within Vim. As well as Vim commands such as :sort
for sorting your file.
I could go on here, but I want to dive into the editor itself now and explore why I learned it initially and how to get started if you’re going to. In case you want to read more, I wrote a full article on Why Vim Is More than Just an Editor and also about My vim-verse: The Backbone of My Workflow.
# Vim motions for none-technical people?
I got asked if vim motions worth for none-technical people, especially with a none-admin account at work? Below is my answer I gave.
First, I would focus on the “vim motions” (the shortcuts) rather than the editor itself. You might even be able to use these shortcuts at work, as there are now Vim extensions for almost everything. Unfortunately, not yet for MS Word or other similar programs.
What you can certainly do is write Markdown locally (which works on any operating system) and find an editor where you can install vim extensions (Obsidian, VS Code, Sublime, Notepad++, etc.). There are many tools that you can launch directly from a file (portable version).
Whether it’s worth it is difficult to say. If you write a lot as an author, and this is your profession, then definitely yes. I actually need it more as an author than for programming. It’s absolutely the best way to write or edit text. You could also use an online tool like HackMD, which also has vim motions that you can activate.
Switching between your personal computer and work computer shouldn’t be an issue, because you’ll never forget normal writing (without vim), and whenever vim motions are available, you’ll just be much faster. The only thing is that it will take you longer to learn the shortcuts and the vim language, and for these to become muscle memory.
Another important question is the keyboard layout. Some time ago, I switched to the US layout because vim motions are best designed for it. But if you don’t program, this doesn’t play such a big role, and you probably will have fewer problems if you stay with the Swiss layout.
I would just try it out. There are many cool exercises like Vim Golf or Vimtutor. It will be challenging at the beginning. And you’ll quickly notice whether it doesn’t suit you at all, or if it might be something for you. After 2-3 weeks, I started to enjoy it, and it became really “fun” to edit something with vim, even if the task itself would otherwise be very boring.
# Good Design Matters
As the vim motions has been here for many years, and integrated in any editor, any tool, it’s passed the Lindy Effect, and we can say, it has very ergonomic design.
Like professional StarCraft players don’t use the mouse for not its speed, but also they can just use their muscle memory, the same vim users use vim motions because of its speed, and Thinking in the thought of speed. Interesting how it connects to Thinking, Fast and Slow (Daniel Kahneman), where slow thinking is advocated.
Source by Boilerplate YT Video
More on this very interesting topic also by Boilerplate YT on his video about Writing at the Speed of Thought.
# Further Reads
Article I wrote related to vim motions, and how I use them:
- Why Vim Is More than Just an Editor – Vim Language, Motions, and Modes Explained
- My Vim-Verse: The Backbone of My Workflow
- My Obsidian Note-Taking Workflow
- Personal Knowledge Management Workflow for a Deeper Life — as a Computer Scientist
Origin:
Why Vim Is More than Just an Editor
References:
Created 2023-01-16