DEV Community

Cover image for Vim Basics
Matthew S.
Matthew S.

Posted on

Vim Basics

If you're like me, you've probably used Vim in the past and didn't even realize it. Today I'm going to go over a basic overview of Vim, why it is used, some basic commands, and show you an easy way to try Vim out for yourself.

Brief Overview

Okay, so let's start off with what Vim is. Vim is a popular text editor that was first released in 1991 as a successor to the Unix editor, vi. Vim is also a modal editor, which means that it has different modes for navigating and editing text. The two most common modes are normal and insert mode. In normal mode, Vim allows you to move around and make edits to your document using a variety of keyboard shortcuts and commands. In insert mode, you have the ability to type text directly into your document. Vim also has other modes for performing tasks like searching and replacing text.

Why Is Vim Used

One of the main reasons people use Vim is for its efficiency. It has many built-in shortcuts and commands that allow you to navigate and edit text without having to take your hands off the keyboard or move your cursor around the screen. This can save you a lot of time and make you more productive.

Another great feature of Vim is its extensibility. There are many plugins available that can be used to extend Vim's functionality and make it even more powerful. For example, there are plugins for syntax highlighting, auto-completion, and integration with other tools like Git.

Vim is also highly customizable. You can customize its appearance, behavior, and keybindings to suit your own preferences.

Some Basic Commands

Vim gives you a large library of commands to use, but here I list what I think are probably the best basic commands to get started with.

esc:q!        Discards changes
esc:wq        Write/quit
x             Delete
dw            Remove word
d$            Delete to end of line
dd            Delete 1 line, can also use 2dd for 2 lines
p             Place deleted line
u             Undo
Ctrl g        Show file you are in
0             Start of line
gg            Start of file
g             Bottom of file
/+'word'      Search by word
n             Move to next word of search
=s/old/new/g  Substitute old word for new one globally
i             Insert mode

Enter fullscreen mode Exit fullscreen mode

Where You Will See It

As I mentioned above in my opening paragraph, I had used Vim a few times before without even knowing it. Those time included when dealing with merge conflicts in my VS Code and also when having to edit a deployed instances code.

When it comes to resolving merge conflicts, you open a file that has merge conflicts in Vim, you can then type in comments in the command-line mode. You can then use Vim's editing commands to resolve the conflicts and save the file.

Vim can also be used to edit configuration files that are used for deployment, such as YAML files, JSON files, or script files. Vim's syntax highlighting and auto-indentation features can make it easier to edit these files and catch errors before they cause issues during deployment. Also, Vim's plugins can be used to integrate with deployment tools such as Git or other version control systems.

How To Try It Out

It is pretty easy to get started learning about Vim, due to their tutorial. If you want to check it out, simply type vimtutor in your terminal and the image below will pop up. From there the tutorial will guide you through some of the basic commands to get you started and that's it.

Image description

Conclusion

Vim has many features that make it popular due to its efficiency, simplicity, and availability. If you have the time, I do recommend trying out the tutorial and see if you like it. Besides, I'm sure you will eventually see Vim in the future if you are ever working with deployment or possibly merge conflicts like myself.

Sources

https://en.wikipedia.org/wiki/Vim_(text_editor)
https://www.vim.org/docs.php

Top comments (0)