5 Must-Have Vim Plugins That Will Change Your Workflow

One thing Vim users love about their favorite text editor is it’s seemingly endless extensibility. On top of configuring basic mappings, settings, and behaviors in your .vimrc, there are a ton of awesome plugins that extend Vim’s functionality. As someone who has been using Vim as his primary editor for about 7 years now, I’m going to share some of the ones that I think are important for any Vim user.

Installing and Managing Plugins

Before moving onto the plugins I want to cover, let’s talk about how to actually install and manage plugins in Vim. There are multiple ways to do this.

Native Package Support in Vim 8

As of the release of Vim 8, Vim now has built in support for packages, which you can use to install these plugins. In this post, I will be linking a GitHub repository for each plugin I talk about. With Vim 8 packages, you can clone most of these and add them that way.

Vim will consider any directory under ~/.vim/pack to be a package. These packages can have a start directory in which plugins are loaded on startup, and an opt directory with plugins that need to be loaded manually with the command :packadd.

For most plugins, you can git clone their repository directly to ~/.vim/pack/start or ~/.vim/pack/opt to add them. You can also use Git submodules to manage them, as described in this blog post.

Using a Plugin Manager such as Vundle

There are also automated plugin managers for Vim like Vundle or vim-plug which are developed by the community. You’ll need one of these if you are using an older version of Vim, but even as a Vim 8 user they are still useful in that they provide extra features and might make things easier if you are going to be using a lot of plugins.

I have personally used Vundle a lot over the years, so let’s walk through how to set that up. You can think of this as the zero index in the array of awesome Vim plugins covered in this post.

Vundle requires Git to function, so make sure you have that installed on your machine. If you are a Windows user, the maintainers wrote a detailed guide for installing it on Windows. On Unix based systems, you can install it by running the following command:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

And then adding the following lines to your .vimrc:

set nocompatible " be iMproved, required
filetype off " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

You can install plugins by launching Vim and running :PluginInstall. If you want to automate the installation of Vundle in your .vimrc, for example when setting up on a fresh machine, you can add something like the following script, found in this blog post:

" Setting up Vundle - the vim plugin bundler
    let iCanHazVundle=1
    let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
    if !filereadable(vundle_readme)
        echo "Installing Vundle.."
        echo ""
        silent !mkdir -p ~/.vim/bundle
        silent !git clone https://github.com/VundleVim/Vundle.vim ~/.vim/bundle/vundle
        let iCanHazVundle=0
    endif

    set nocompatible              " be iMproved, required
    filetype off                  " required
    set rtp+=~/.vim/bundle/vundle/

    call vundle#begin()
    Plugin 'VundleVim/Vundle.vim'

    "Add your bundles here

    if iCanHazVundle == 0
        echo "Installing Vundles, please ignore key map error messages"
        echo ""
        :PluginInstall
    endif

    call vundle#end()

    "must be last
    filetype plugin indent on " load filetype plugins/indent settings
    colorscheme solarized
    syntax on                      " enable syntax
 
" Setting up Vundle - the vim plugin bundler end

This will automatically make sure you have Vundle, and all of your plugins, set up whenever you run Vim. Now let’s get to the good stuff!

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:

Plugin 'Syntastic'

Syntastic displaying errors

As you can see here when I make a typo, in this case spelling Flask as Flaks, Syntastic will pick up on this and point out the errors when I write the file. If there is an actual syntax error, such as a missing colon for an if statement, this will also be flagged. It will even add an underscore at the end of the line to point out where the problem is.

Syntastic with cursor highlighting

You can configure Syntastic’s settings quite a bit. Try entering the command :help syntastic for more info on that. Here are some basic default settings I’d recommend adding to your .vimrc to get you started:

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_enable_signs=1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1

With these enabled, here’s what it looks like when you open a file with an error in it. Another buffer is opened in a horizontal split with information on the error, and goes away once you fix it.

Syntastic errors in their own buffer

Here is a manual of what syntax checkers Syntastic is compatible with, so make sure you have the appropriate one installed for the language you are using. For Python I use flake8, which also has its own Vim plugin. You can install flake8 by running pip install flake8 with the pip that corresponds to whatever version of Python you are using.

Fugitive

Fugitive is a Git wrapper for Vim that is self-described as “so awesome, it should be illegal.” You can install Fugitive with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'https://github.com/tpope/vim-fugitive'

With Fugitive you can run :Git, or even just :G followed by an arbitrary Git command to run that command directly from Vim and have the output echoed in a stream. This works particularly well with commands that don’t have a lot of output.

For example, here is the simple functionality of adding the changes of the file you’re currently working on to prepare for a commit.

"git add" from Vim with Fugitive

One of my favorite features is that when you use the :Gblame command it will open a buffer in a vertical split with all of the git blame annotations side by side with the lines of the file you are working on. And the scrolling is even bound between them!

Fugitive "Gblame" command

Looks like I only have myself to blame for that one. If you want to see more, this VimCast is an excellent demo that covers a lot of cool aspects of Fugitive.

NERDTree

The NERDTree is a file system explorer for Vim that can be used to visually browse complex directory hierarchies, quickly open files for reading or editing, and perform basic file system operations.

NERDTree directory display

You can install NERDTree with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'scrooloose/nerdtree'

By running the :NERDTree command, you open up another buffer that is vertically split to the side of your current file, displaying the current directory and allowing you to navigate the filesystem in general and open other files.

NERDTree doesn’t create any shortcuts itself outside its own window, so it doesn’t interfere with any other shortcuts you already have. But you can add some keyboard shortcuts to your .vimrc for some NERDTree commands. For example:

nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>

Here are some things you can add to your .vimrc to customize the behavior of how NERDTree works:

" Start NERDTree when Vim is opened and leave the cursor in it.
autocmd VimEnter * NERDTree

" Start NERDTree when Vim is opened and put the cursor back in the other window.
autocmd VimEnter * NERDTree | wincmd p


" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * silent NERDTreeMirror

" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
    \ quit | endif

There are even NERDTree plugins such as this one that adds icons next to files based on their filetype. In Vim, even the plugins have plugins that are customizable.

Emmet

Emmet is an extremely useful plugin for web developers. It makes writing and editing HTML, and any language with tags, much easier. You can install Emmet with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'mattn/emmet-vim'

You can expand any tags you want, and even use some built in common commands, like html:5,  by typing <c-y>, (Ctrl+y+,).

Emmet HTML demo

Here’s a quick tutorial showing various things you can use Emmet to do. As with any Vim plugin, you can customize its behavior in your .vimrc. Here are some examples:

let g:user_emmet_mode='n'    "only enable normal mode functions.
let g:user_emmet_mode='inv'  "enable all functions, which is equal to
let g:user_emmet_mode='a'    "enable all function in all mode.

" only enable Emmet for certain file types
let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall

" redefine the trigger key (you still need to enter the trailing ,)
let g:user_emmet_leader_key='<C-Z>'

Airline

Airline is a “lean & mean status/tabline for vim that’s light as air” and it has already been demonstrated in the screenshots from all of the other examples in this post. You can see here how the status line changes as I enter different modes, and provides a lot of contextual information as well.

Airline display demo

This line consists of several sections, each one displaying some piece of information. By default (without configuration) it will have this layout:

+-----------------------------------------------------------------------------+
| A | B |                     C                            X | Y | Z |  [...] |
+-----------------------------------------------------------------------------+
  • A: displays the mode + additional flags like crypt/spell/paste (INSERT)
  • B: Environment status (VCS information – branch, hunk summary (master), battery level)
  • C: filename + read-only flag (~/.vim/vimrc RO)
  • X: filetype
  • Y: file encoding[fileformat] (utf-8[unix])
  • Z: current position in the file
  • […]: additional sections (warning/errors/statistics) from external plugins (e.g. YCM, syntastic, …)

You can install Airline with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'bling/vim-airline'

:wq!

Hopefully you’ve found some of these interesting or helpful. A lot of these are well known in the Vim community, but they are some of the plugins that I think are must-haves for any Vim user. In the future I am going to write another post on some lesser known plugins.

As a Vim enthusiast, I am always looking forward to hearing about more things I can add to my .vimrc. I don’t consider myself an expert so there is a whole world of Vim sorcery to discover! Feel free to contact me about some Vim tricks that you think are cool, ask questions about any of these, or want to express your undying anger at any of my suggestions:


This content originally appeared on Twilio Blog and was authored by Sam Agnew

One thing Vim users love about their favorite text editor is it's seemingly endless extensibility. On top of configuring basic mappings, settings, and behaviors in your .vimrc, there are a ton of awesome plugins that extend Vim's functionality. As someone who has been using Vim as his primary editor for about 7 years now, I'm going to share some of the ones that I think are important for any Vim user.

Installing and Managing Plugins

Before moving onto the plugins I want to cover, let's talk about how to actually install and manage plugins in Vim. There are multiple ways to do this.

Native Package Support in Vim 8

As of the release of Vim 8, Vim now has built in support for packages, which you can use to install these plugins. In this post, I will be linking a GitHub repository for each plugin I talk about. With Vim 8 packages, you can clone most of these and add them that way.

Vim will consider any directory under ~/.vim/pack to be a package. These packages can have a start directory in which plugins are loaded on startup, and an opt directory with plugins that need to be loaded manually with the command :packadd.

For most plugins, you can git clone their repository directly to ~/.vim/pack/start or ~/.vim/pack/opt to add them. You can also use Git submodules to manage them, as described in this blog post.

Using a Plugin Manager such as Vundle

There are also automated plugin managers for Vim like Vundle or vim-plug which are developed by the community. You'll need one of these if you are using an older version of Vim, but even as a Vim 8 user they are still useful in that they provide extra features and might make things easier if you are going to be using a lot of plugins.

I have personally used Vundle a lot over the years, so let's walk through how to set that up. You can think of this as the zero index in the array of awesome Vim plugins covered in this post.

Vundle requires Git to function, so make sure you have that installed on your machine. If you are a Windows user, the maintainers wrote a detailed guide for installing it on Windows. On Unix based systems, you can install it by running the following command:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

And then adding the following lines to your .vimrc:

set nocompatible " be iMproved, required
filetype off " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

You can install plugins by launching Vim and running :PluginInstall. If you want to automate the installation of Vundle in your .vimrc, for example when setting up on a fresh machine, you can add something like the following script, found in this blog post:

" Setting up Vundle - the vim plugin bundler
    let iCanHazVundle=1
    let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
    if !filereadable(vundle_readme)
        echo "Installing Vundle.."
        echo ""
        silent !mkdir -p ~/.vim/bundle
        silent !git clone https://github.com/VundleVim/Vundle.vim ~/.vim/bundle/vundle
        let iCanHazVundle=0
    endif

    set nocompatible              " be iMproved, required
    filetype off                  " required
    set rtp+=~/.vim/bundle/vundle/

    call vundle#begin()
    Plugin 'VundleVim/Vundle.vim'

    "Add your bundles here

    if iCanHazVundle == 0
        echo "Installing Vundles, please ignore key map error messages"
        echo ""
        :PluginInstall
    endif

    call vundle#end()

    "must be last
    filetype plugin indent on " load filetype plugins/indent settings
    colorscheme solarized
    syntax on                      " enable syntax
 
" Setting up Vundle - the vim plugin bundler end

This will automatically make sure you have Vundle, and all of your plugins, set up whenever you run Vim. Now let's get to the good stuff!

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:

Plugin 'Syntastic'

Syntastic displaying errors

As you can see here when I make a typo, in this case spelling Flask as Flaks, Syntastic will pick up on this and point out the errors when I write the file. If there is an actual syntax error, such as a missing colon for an if statement, this will also be flagged. It will even add an underscore at the end of the line to point out where the problem is.

Syntastic with cursor highlighting

You can configure Syntastic's settings quite a bit. Try entering the command :help syntastic for more info on that. Here are some basic default settings I'd recommend adding to your .vimrc to get you started:

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_enable_signs=1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1

With these enabled, here's what it looks like when you open a file with an error in it. Another buffer is opened in a horizontal split with information on the error, and goes away once you fix it.

Syntastic errors in their own buffer

Here is a manual of what syntax checkers Syntastic is compatible with, so make sure you have the appropriate one installed for the language you are using. For Python I use flake8, which also has its own Vim plugin. You can install flake8 by running pip install flake8 with the pip that corresponds to whatever version of Python you are using.

Fugitive

Fugitive is a Git wrapper for Vim that is self-described as "so awesome, it should be illegal." You can install Fugitive with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'https://github.com/tpope/vim-fugitive'

With Fugitive you can run :Git, or even just :G followed by an arbitrary Git command to run that command directly from Vim and have the output echoed in a stream. This works particularly well with commands that don't have a lot of output.

For example, here is the simple functionality of adding the changes of the file you're currently working on to prepare for a commit.

"git add" from Vim with Fugitive

One of my favorite features is that when you use the :Gblame command it will open a buffer in a vertical split with all of the git blame annotations side by side with the lines of the file you are working on. And the scrolling is even bound between them!

Fugitive "Gblame" command

Looks like I only have myself to blame for that one. If you want to see more, this VimCast is an excellent demo that covers a lot of cool aspects of Fugitive.

NERDTree

The NERDTree is a file system explorer for Vim that can be used to visually browse complex directory hierarchies, quickly open files for reading or editing, and perform basic file system operations.

NERDTree directory display

You can install NERDTree with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'scrooloose/nerdtree'

By running the :NERDTree command, you open up another buffer that is vertically split to the side of your current file, displaying the current directory and allowing you to navigate the filesystem in general and open other files.

NERDTree doesn't create any shortcuts itself outside its own window, so it doesn't interfere with any other shortcuts you already have. But you can add some keyboard shortcuts to your .vimrc for some NERDTree commands. For example:

nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>

Here are some things you can add to your .vimrc to customize the behavior of how NERDTree works:

" Start NERDTree when Vim is opened and leave the cursor in it.
autocmd VimEnter * NERDTree

" Start NERDTree when Vim is opened and put the cursor back in the other window.
autocmd VimEnter * NERDTree | wincmd p


" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * silent NERDTreeMirror

" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
    \ quit | endif

There are even NERDTree plugins such as this one that adds icons next to files based on their filetype. In Vim, even the plugins have plugins that are customizable.

Emmet

Emmet is an extremely useful plugin for web developers. It makes writing and editing HTML, and any language with tags, much easier. You can install Emmet with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'mattn/emmet-vim'

You can expand any tags you want, and even use some built in common commands, like html:5,  by typing <c-y>, (Ctrl+y+,).

Emmet HTML demo

Here's a quick tutorial showing various things you can use Emmet to do. As with any Vim plugin, you can customize its behavior in your .vimrc. Here are some examples:

let g:user_emmet_mode='n'    "only enable normal mode functions.
let g:user_emmet_mode='inv'  "enable all functions, which is equal to
let g:user_emmet_mode='a'    "enable all function in all mode.

" only enable Emmet for certain file types
let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall

" redefine the trigger key (you still need to enter the trailing ,)
let g:user_emmet_leader_key='<C-Z>'

Airline

Airline is a "lean & mean status/tabline for vim that's light as air" and it has already been demonstrated in the screenshots from all of the other examples in this post. You can see here how the status line changes as I enter different modes, and provides a lot of contextual information as well.

Airline display demo

This line consists of several sections, each one displaying some piece of information. By default (without configuration) it will have this layout:

+-----------------------------------------------------------------------------+
| A | B |                     C                            X | Y | Z |  [...] |
+-----------------------------------------------------------------------------+
  • A: displays the mode + additional flags like crypt/spell/paste (INSERT)
  • B: Environment status (VCS information - branch, hunk summary (master), battery level)
  • C: filename + read-only flag (~/.vim/vimrc RO)
  • X: filetype
  • Y: file encoding[fileformat] (utf-8[unix])
  • Z: current position in the file
  • [...]: additional sections (warning/errors/statistics) from external plugins (e.g. YCM, syntastic, ...)

You can install Airline with Vundle by adding the following line to your .vimrc in the #begin and #end Vundle calls:

Plugin 'bling/vim-airline'

:wq!

Hopefully you've found some of these interesting or helpful. A lot of these are well known in the Vim community, but they are some of the plugins that I think are must-haves for any Vim user. In the future I am going to write another post on some lesser known plugins.

As a Vim enthusiast, I am always looking forward to hearing about more things I can add to my .vimrc. I don't consider myself an expert so there is a whole world of Vim sorcery to discover! Feel free to contact me about some Vim tricks that you think are cool, ask questions about any of these, or want to express your undying anger at any of my suggestions:


This content originally appeared on Twilio Blog and was authored by Sam Agnew


Print Share Comment Cite Upload Translate Updates
APA

Sam Agnew | Sciencx (2021-03-09T23:58:36+00:00) 5 Must-Have Vim Plugins That Will Change Your Workflow. Retrieved from https://www.scien.cx/2021/03/09/5-must-have-vim-plugins-that-will-change-your-workflow/

MLA
" » 5 Must-Have Vim Plugins That Will Change Your Workflow." Sam Agnew | Sciencx - Tuesday March 9, 2021, https://www.scien.cx/2021/03/09/5-must-have-vim-plugins-that-will-change-your-workflow/
HARVARD
Sam Agnew | Sciencx Tuesday March 9, 2021 » 5 Must-Have Vim Plugins That Will Change Your Workflow., viewed ,<https://www.scien.cx/2021/03/09/5-must-have-vim-plugins-that-will-change-your-workflow/>
VANCOUVER
Sam Agnew | Sciencx - » 5 Must-Have Vim Plugins That Will Change Your Workflow. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/09/5-must-have-vim-plugins-that-will-change-your-workflow/
CHICAGO
" » 5 Must-Have Vim Plugins That Will Change Your Workflow." Sam Agnew | Sciencx - Accessed . https://www.scien.cx/2021/03/09/5-must-have-vim-plugins-that-will-change-your-workflow/
IEEE
" » 5 Must-Have Vim Plugins That Will Change Your Workflow." Sam Agnew | Sciencx [Online]. Available: https://www.scien.cx/2021/03/09/5-must-have-vim-plugins-that-will-change-your-workflow/. [Accessed: ]
rf:citation
» 5 Must-Have Vim Plugins That Will Change Your Workflow | Sam Agnew | Sciencx | https://www.scien.cx/2021/03/09/5-must-have-vim-plugins-that-will-change-your-workflow/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.