8

What is Vim?

 1 year ago
source link: https://www.codecademy.com/resources/blog/what-is-vim/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
What-is-Vim

What is Vim?

05/03/2023
6 minutes

If you code with multiple languages, you have more than a handful of IDEs (integrated development environments) to choose from. (You can find some of them here in our article about popular IDEs and code editors.) Once you’ve picked one, you can install all sorts of add-ons and plugins to format code for you, give you code hints, and modify the GUI.

Ahead, we will look at a simple code editor called Vim and why many developers prefer it to even the latest, shiniest IDE with all the groundbreaking features that fall just short of writing code for you.

The history of Vim

Vim is a screen-based text editor included by default in most Linux distributions, Mac OS X, and now Windows. It’s also been ported to many other operating systems. “Screen-based” means that it doesn’t have a GUI. You have to access it through the command line.

The first version of Vim came out in 1991. Computer Programmer Bram Moolenaar created it as an improved clone of the vi editor for Unix that was released in 1976. In fact, in Linux and Mac OS X, you can start Vim by typing vi in the terminal.

Vim was originally released for the Amiga and was ported to Unix the following year. It has always been free and open-source and now has been ported to multiple operating systems and comes natively with Linux and Mac OS X.

In 2006, Vim was voted the most popular text editor by Linux Journal readers. A 2015 Stack Overflow developer survey rated it the third most popular text editor, and in 2019, it was still in fifth place.

Getting started with Vim

To use Vim in Linux or MAC OS X, just type “vi” in the terminal. For Windows, as of 2020, just type “Vim” in PowerShell. If you need it for other operating systems, you can find a Vim download here for most of them.

The first thing you need to understand is four of the modes in Vim.

  • Normal. This is the initial or default mode when working in Vim. You can move the cursor around a text file with the arrow (HJKL) keys and use other key combinations for navigation. If you hit the Esc key in any other mode, it will take you back to normal mode.
  • Insert. This mode is for editing the text in the file. To get to insert mode when you are in any other mode, press the “i” key.
  • Command. Command mode is for operations on the file, like saving it or closing it. You can reach this mode by pressing the “:” key when you are in normal mode.
  • Visual. In visual mode, you can highlight and edit specific segments and code snippets.

One of the most asked questions on the internet is “How to quit Vim?” First, you have to be in command mode, and then you type `q!` So the full command to quit without writing from normal mode is `:q!`.

That’s all you need to know to do basic operations with files, but there’s much more to learn. Vim has an incredible catalog of features for working with text, and you can learn more about them at the Vim Tips Wiki.

Why use Vim?

So why would a developer want to use a command-line application for editing code instead of a more modern IDE or, at least, an editor with a GUI?

Vim is ubiquitous

Vim is available on most Linux distributions, Mac OS X, and now even Windows. If your day-to-day work involves logging into remote Linux instances, then all you have is the command line, and Vim is a powerful command-line editor. You can’t use your IDE here. And many developers would prefer to use only one tool for editing code than have to learn a different one for each environment.

Vim is fast and light

Vim doesn’t use a lot of resources because it doesn’t have the overhead of a GUI. This makes it extremely responsive and fast, even when editing large files. Plus, its key binding features allow you to do things quickly without moving your fingers off the keyboard to use a mouse or touchpad.

Vim has portable configurations

Once you set up Vim the way you like it, you can use that configuration for another instance of Vim on even another operating system. This means you can take your customized version of Vim with you wherever you write code.

Vim is customizable and extensible

Who says that you have to have an IDE to customize your coding experience? You can extend Vim with a wide variety of plugins to create your own personal version.

In Linux and Mac OS X, Vim’s configuration is stored in the ~/.vim folder. You install a Vim plugin by putting it in the ~/.vim/pack/vendor/start folder. Most plugins are available via public Git repositories, and you can install them by cloning the repo directly into the folder. Look at the documentation of your specific version of Vim to find the plugins folder for other operating systems. To learn more about using Git, check out our Learn Git course.

Now let’s look at some plugins you can install.

Popular Vim plugins for coding

There are close to 20,000 plugins for Vim and an active community of developers creating more plugins and adding new features to existing plugins every day. Here are some popular Vim plugins:

The NERDTree

The NERDTree plugin lets you explore the hierarchy of your file system in the form of, you guessed it, a tree. With it, you can browse to a file in Vim to open it without having to know and type its full file path.

Tabnine

Tabnine will index your code project and give you a predictive autocomplete tool that suggests code as you type. It requires no configuration and shows suggestions in less than 10 milliseconds.

Syntastic

Syntastic is a Vim plugin that does syntax checking on your code. You can set it to check your code manually or every time you save a file.

Fugitive

Fugitive is a Vim plugin that lets you call any Git command from inside Vim, so you don’t have to switch applications or terminals.

Airline

Airline replaces the standard Vim status line with a status bar that contains information about the file you are working on, including the file name, save status, file type, encoding, position, word count, and more.

Get practice with Vim

It turns out that a simple command-line text editor that can trace its history back over 40 years is still one of the most popular code editors today. Just because its interface is basic doesn’t mean that Vim is not powerful. It’s faster than an IDE, and with close to 20,000 plugins, you can add as many bells and whistles to Vim as you can to a modern IDE. To get some practice with Vim and discover why it is so popular, why not learn to code or try learning a new programming language with one of our coding courses.

Subscribe for news, tips, and more


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK