Tuesday, December 1, 2020

Fundamental concepts of Vim

When learning Vim, it's important to understand its most fundamental concepts: Commands, Buffers, Modes and Motions.
Photo by Alex Knight on Unsplash

Once you installed Vim on MacWindows or Linux, learned how to get started with Vim and mastered your first Vim tutorial, the next thing you should learn about Vim is its fundamental concepts: Commands, Buffers, Modes and Motions.

Commands

Most of the examples you'll see and learn are commands. Commands are operations you run in Vim that can pretty much do everything. For example, the command below, lists the open files:

:ls

Commands can also modify text. For example, the command below would replace all occurrences of the word hello by world in the current buffer:

:%s/hello/world/g

Buffers

Buffers are another essential concept of Vim. You may not have realized it yet but buffers is one of the things in Vim that differs it from traditional text editors.

Every file opened in Vim is opened in a buffer. During that process, Vim copies the contents of that file to memory and uses that until you save your modifications to disk. That way Vim can perform really quick operations on the content you need without reaching the filesystem.

Modes

Modes are another feature that differentiates Vim from traditional text editors and something that's important to comprehend. The most common modes are:

  • Normal: Vim's primary mode and the one we use to run commands:
  • Insert: the mode where you edit the contents of your files
  • Visual: visual selection of contents
  • Replace: allows you to type over the text, replacing it
  • Command-line: allows you to execute commands via its own command-line prompt
  • Visual-block: allows you to make block-level changes (vertical selections and modifications)
  • Ex: in this mode Vim emulates the Ex editor and is used mainly for batch processing
  • Select: like the visual mode but with more CUA like behavior.

Since there's a lot there to learn, try to stick with Normal and Insert for now. We'll see in detail in future posts how each of the mode works but feel free to use the help as explained on a previous post.

Motions

Another fundamental aspect of Vim is the concept of Motions. Motions are parameters that you pass into your commands or actions moving the cursor around (fore or backwards). Motions is another phenomenal feature of Vim's making it way more powerful than  traditional editors. 

Motions can also be combined with operators (we'll learn more about them in the future) so you can run powerful commands like:

dap

which runs a command that can be read as "delete all paragraph".

Conclusion

On this post we introduced three of the fundamental concepts of Vim: Commands, Buffers, Modes and Motions. If it seems complicated, don't be concerned. It takes years to master Vim but be sure that the more you learn, the more you realize that time is that secret ingredient in getting comfortable, becoming proficient and efficient with Vim.

Learning Vim is like learning a musical instrument. It takes time, effort and discipline but once you master it, the gains are endless. You definitely won't regret.

See Also

    Any comment about this page? Please contact us on Twitter

    Featured Article

    Vim - Ex Mode

    When learning Vim, it's important to understand its modes, including the  Ex Mode  where you can continually type your commands u...

    Popular Posts