Vim for normal people

Vim, the steroids powered *nix text editor, is a must for geek, power users, and programmers, but what about the normal people. Vim isn’t easy and it’s really basic, no frills, no deep functionalities, but Vim has a world of plugins behind. Let’s see which plugins fit the needs of the normal people and how is Vim for dummies.

Vim – Simple and minimal configuration

Vim plugins. Welcome to the jungle

A Vim plugin is a set of Vimscript files that are laid out in a certain directory structure. Before plugin managers became popular, Vim plugins were usually distributed as tarballs. Users would manually download the file and extract it in a single directory called ~/.vim, and Vim would load the files under the directory during startup.

To push Vim out of the basic text editor mode, we need to get some plugins. A lot of people (so high skilled people I mean) use too many plugins and transform Vim in a complete IDE or OS. This is the GNU Emacs way, but I don’t want this, I prefer to keep Vim light, minimal and simple, so, just a splash of useful and brilliant plugins. A plugin can be added in a manual way, but it’s really convenient to use a plugins manager to install and manage them.

To push Vim out of the basic text editor mode, we need to get some plugins. A lot of people (so high skilled people I mean) use too many plugins and transform Vim in a complete IDE or OS. This is the GNU Emacs way, but I don’t want this, I prefer to keep Vim light, minimal and simple, so, just a splash of useful and brilliant plugins. A plugin can be added in a manual way, but it’s really convenient to use a plugins manager to install and manage them.

You have different choices, the most famous are NeoBundle, Pathogen,  vim-plug and Vundle. I like vim-plug, so here I use it. It’s a modern Vim plugin manager, downloads plugins into separate directories for you and makes sure that they are loaded correctly. It allows you to easily update the plugins, review (and optionally revert) the changes, and remove the plugins that are no longer used.

To find your next favorite plugin by yourself, you can use the magic Vim Awesome. It is a comprehensive, accurate, and up-to-date directory of Vim plugins.


vim-plug

To install and use vim-plug, you need to download plug.vim and put it in the ‘autoload’ directory. Let’s do it (curl should be installed) in a terminal:

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

The usage of vim-plug is relatively simple, you must add a vim-plug section to your ~/.vimrc.

" Plugins will be downloaded under the specified directory.
call plug#begin('~/.vim/plugged')

" Declare the list of plugins.
Plug 'tpope/vim-sensible'
Plug 'junegunn/seoul256.vim'

" List ends here. Plugins become visible to Vim after this call.
call plug#end()

After adding the above to the top of your Vim configuration file, reload it (:source ~/.vimrc) or restart Vim. In the end, run :PlugInstall inside Vim to install the plugins.


lightline.vim

A light and configurable statusline/tabline plugin for Vim. I like it because it’s really minimal and simple. From the readme file:

  • Minimalism. The core script is very small to achieve enough functions as a statusline plugin.
  • Configurability. You can create your own component and easily add to the statusline and the tabline.
  • Orthogonality. The plugin does not rely on the implementation of other plugins. Such plugin crossing settings should be configured by users.

To install lightline.vim, just put the following configuration to your .vimrc:

Plug 'itchyny/lightline.vim'

Reload Vim and install it with :PlugInstall.


commentary.vim

Comment stuff out. Use gcc to comment out a line (takes a count), gc to comment out the target of a motion (for example, gcap to comment out a paragraph), and gc in visual mode to comment out the selection. That’s it.

commentary.vim also uncomments, too. The above maps actually toggle, and gcu uncomments a set of adjacent commented lines.

To install commentary.vim, just put the following configuration to your .vimrc:

Plug 'tpope/vim-commentary'

And install it with :PlugInstall. Without exiting Vim, you can also do:

:source %
:PlugInstall


surround.vim

This plugin is all about ‘surroundings’: parentheses, brackets, quotes, XML tags, and more. The plugin provides mappings to easily delete, change and add such surroundings in pairs.

This plugin is very powerful for HTML and XML editing, a niche which currently seems underfilled in Vim land. (As opposed to HTML/XML inserting, for which many plugins are available). Adding, changing, and removing pairs of tags simultaneously is a breeze.

Place this in your .vimrc:

Plug 'tpope/vim-surround'

And then run the following in Vim:

:source %
:PlugInstall


fzf and fzf.vim

fzf is a general-purpose command-line fuzzy finder. It’s an interactive Unix filter for command-line that can be used with any list; files, command history, processes, hostnames, bookmarks, git commits, etc.

fzf in itself is not a Vim plugin, and the official repository only provides the basic wrapper function for Vim and it’s up to the users to write their own Vim commands with it. However, I’ve learned that many users of fzf are not familiar with Vimscript and are looking for the “default” implementation of the features they can find in the alternative Vim plugins.

fzf.vim repository is a bundle of fzf-based commands and mappings. They are not designed to be flexible or configurable, and there’s no guarantee of backward-compatibility.

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }

Plug 'junegunn/fzf.vim'

And again:

:source %
:PlugInstall


Configure Vim from scratch

Vim can also permit a lot of configuration from scratch without the need of plugins. You can learn a lot about it on the official documentation or on the book (PDF here) completely dedicated to Vim written by Steve Oualline. It’s written for Vim 5.7, but it is still a useful introduction to any modern version of Vim.

Anyway, if you want to keep it simple, you can use the Vim Config – Simple and sane Vim configuration website.

"" General config
set number " Show line numbers
set linebreak " Break lines at word (requires Wrap lines)
set showbreak=+++ " Wrap-broken line prefix
set textwidth=100 " Line wrap (number of cols)
set showmatch " Highlight matching brace
set visualbell " Use visual bell (no beeping)

set hlsearch " Highlight all search results
set smartcase " Enable smart-case search
set ignorecase " Always case-insensitive
set incsearch " Searches for strings incrementally

set autoindent " Auto-indent new lines
set shiftwidth=4 " Number of auto-indent spaces
set smartindent " Enable smart-indent
set smarttab " Enable smart-tabs
set softtabstop=4 " Number of spaces per Tab

"" Advanced config
set ruler " Show row and column ruler information

set undolevels=1000 " Number of undo levels
set backspace=indent,eol,start " Backspace behaviour

For now, it’s all about the simple configuration of Vim. If you need the final result, you can get the complete file at GitHub.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *