Site icon TechwithAbhijeet

Vim and vim configuration: A beginners guide

Vim and vim configuration: A beginners guide

Introduction

Vim is an acronym for Vi Improved. It is a free and open-source text editor. Vim is an improved vi clone. Vim is mainly designed to be used on a command-line interface, but it has a GUI version.

If you are a programmer, there is an excellent chance that you know about VIM. For years, the VIM vs. Emacs debate has been a hot topic discussion, b/w programmers, so it’s tough to never hear about VIM.

Out of the box, VIM seems a very regular editor with a steep learning curve, and most of the time, beginners will feel that it’s not worth it. But if you are in the tech field, believe me learning VIM will pay off.

Why should you learn VIM?

The power of VIM is that it’s a straightforward editor but available and easy to use on all *nix-based systems. It is highly programmable and configurable, so your simple Vim editor can be configured for most use cases a programmer needs.

The importance of learning about VIM is that you will always find it(or its predecessor vi, which works similar to Vim, since Vim did start as a clone of vi) on any flavour of UNIX (standard both in SysV and BSD flavors) or UNIX-like system.

The most crucial reason Vim is so widely used in the tech community is that it is always available and will run on most machines. It is a highly optimized text editor, so Vim might still work as a breeze even if your device is not that powerful and has limited resources. So it’s worth knowing how to edit simple files just for programming/scripting/sysadmin tasks.

VIM Basics

When you start using Vim, the first thing which confuses users is Vim modes. Since the idea is not to use a mouse, Vim has different modes for switching between editing/commands. So when you change modes on Vim,  these changes the function of each key on your keyboard (Pressing the W key types w in INSERT mode, but moves your cursor one word forwards in NORMAL mode).

These modes allow your keyboard to do all the editing and navigating in the editor. You don’t need to use your mouse when you are using Vim. If you have always worked on a windows system and not worked much on a Linux server, it might not seem a big deal; why would you not have a mouse? But there are various scenarios when you only have a terminal and no GUI to use the mouse, and that time knowing Vim saves the day.

Modes are great if you have to constantly switch between editing and traversing through text, which is precisely what we programmers usually do.

Once you are used to using Vim for text editing, you will realise how easy it is to use and configure Vim. It saves a lot of time because you are now wasting your time navigating through a mouse anymore. Your simple Vim can be transformed into a beast editor with multiple plugins and programmability options.

Let me very clear that start out of the box Vim is no replacement for your normal IDE like Visual studio code or sublime text. Knowing Vim and right configuration with it will empower you to edit you code faster and is ideal for scripting like shell or python/perl scripts.

Since most of the time Vi/Vim will be available on *nix based system, so you will be able to Program/script fast on most of the syste,s.

Vim Shortcuts

Recommended plugins for VIM

1.    Pathogen

Manage your ‘runtime path’ with ease. In practical terms, pathogen makes installing plugins and runtime files in their private directories super easy.

Follow instructions on https://github.com/tpope/vim-pathogen to know more and install pathogen.

2.    Tabnine

Most missed feature if an IDE on a text editor is auto completion. Same can be achieved by using a code completion plugin with Vim. Tabnine is a code completion extension which can be added to most of the text editors and We will be using Tabnine for adding code completion capability to our Editor.

Tabnine leverages a mnemonic completion engine to autocomplete as you type and saves user from typing long file names and paths with zero configuration needed and high responsiveness

3.    ALE – Asynchronous Lint Engine

ALE (Asynchronous Lint Engine) provides linting (syntax checking and semantic errors). It acts as a Vim Language Server Protocol client and lint your text as type on your editor.

4.    Rainbow brackets for Vim

Rainbow brackets/parentheses are not only a colorful addition to your code editor of choice, but a necessary tool to help to discern nested code. This plugin adds Rainbow brackets to Vim while using the default rainbow colors copied from the gruvbox color scheme.

5.    vim-colors-solarized

There are numerous color schemes out there for Vim. However, Solarized tends to stay popular with users across IDEs and code editing tools. If you’re one of the fans of Solarized, it’s available as a plugin.

6.    NERDTree

NERDTree is a filesystem explorer for Vim that allows you to browse the directory structure, helping you find and manage files and directories directly within Vim’s interface. NERDTree is a replacement for Vim’s native file explorer netrw. NERDTree includes additional features and sensible defaults, making it easier to get started without adding any configuration to your .vimrc file.

7.    Vim Airline

Vim Airline is a plugin that When correctly loaded, there will be a nice status line at the bottom of each vim window.

Vim Airline is convenient and presents useful information about the file you’re working on, including file name and save status, Vim mode, file type, encoding, position, word count, and more.

Vim Airline is fast and lightweight. It displays relevant information without compromising Vim’s performance. Using Vim Airline improves your productivity by providing information that would require additional time to obtain at a glance.

After installation, Vim Airline enables a basic configuration that does not require changes to Vim’s configuration files. Here is the standard status bar with Airline:

After installing, you can use NERDTree by typing the command:NERDTree. It opens up as a side window with the current directory selected. To close it, you can type the command :NERDTreeClose. You can also use :NERDTreeToggle to switch between open and closed windows. You can even map this command to another key to make it easier to open and close NERDTree.

8.    Fzf Vim

NERDTree is a great plugin to help you navigate the directory structure and find files to work in Vim. However, it’s not helpful if you have an extensive directory structure or if you’re looking for a file but you don’t have much idea about its location. For such cases, a fuzzy finder comes in handy.

9.    Syntastic

Syntastic is a syntax checking plugin for Vim which runs files through external syntax checkers and displays resulting errors. You can install Syntastic with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

10. Emmet

Emmet is a powerful completion tool for HTML, CSS, and JavaScript, which allows you to make dynamic completions from a shorthand expression. Emmet is available for popular text editors and also has a plugin available for Vim.

So if you are a web developer and you work on HTML/CSS/JS often, installing Emmet is highly recommended.

Exit mobile version