Trick out your Vim Editor

vim-iconI’ve been a long-time vim user, dating back to when I figured out how to exit the damn thing.  Over the years I’ve tried various vimrc configurations, plugins and looks and even other editors but I’ve always come back to it for a few reasons: the main one being that you’re guaranteed it will be installed on any server you touch.  I’m sharing my vim setup here and how to use the same one if you like it.


Why Customize?
If you dabble in any development or write ops tools you’ll most likely want language-specific syntax highlighting, buffers, git support and some extended functionality.  The plugin architecture and availability of plugins are very plentiful if not downright overwhelming.  Here are the plugins I use currently:

How to Try this Setup
To quickly get the same setup as me you’ll need to run the following commands.  I have provided a tarball of my ~/.vim and ~/.vimrc that already have the above plugins setup and configured.

Note: there are two versions available, it’s recommended to go with the light version but I have a more complete, skynet-like version that provides a full syntax and text string completion engine but it’s a tad buggy and gigantic.

Install any necessary packages first.  I use Fedora, so substitute yum for CentOS/RHEL or your appropriate package manager.  If these aren’t packaged in RPM you can manually add them via the Plug Vim plugin manager.

dnf install git vim-enhanced

Backup your Current VIM Files
(as normal user)

Backup your current ~/.vim and ~/.vimrc just in case you hate it, then you can revert everything and complain about it in the comments.

mv ~/.vim ~/.vim-bak ; mv ~/.vimrc ~/.vimrc-bak

Download And Setup Options
Pick only one of these options below, most people just want the regular version but the full version can be useful also.

Option #1 – Download the Regular Version (4MB)
The regular version comes without the full code completion engine for most languages, quality-of-life highlighting, git awareness and Python syntax via docstring lookups is included via jedi.

Download vim files and extract them.

cd ~
tar -xvf vimfiles.tar

When this is complete skip past the sections marked full version only.

or .. Option #2 – Download the Full Version (328MB)
This includes a slew of third-party plugin dependencies for youcompleteme which provides library, docstring and code completion for C, C++, Go, Javascript and Python as well as completion of any common strings, variables or text that’s ever been visible in any of your tmux sessions or panes or vim buffers.  Of course some people might say why don’t you just run emacs at this point.  It’s quite large, but hey kitchen sinks aren’t light.

cd ~
tar -xvf vimfiles-full.tar

Install Development Dependencies (full version only)
For the full version only, you’ll need cmake and other dependencies to build the ycmd backend server components.

dnf install cmake gcc gcc-c++ python-devel python3-devel golang-src -y

Now update the ycm submodule parts (full version only)

cd ~/.vim/plugged/ycmd
git submodule update --init --recursive

Lastly, build the autocomplete engine components.  Here I am enabling the following syntax engine completion: C, C++, Javascript, and Go (Python is already included).

python3 --clang-completer --gocode-completer --tern-completer --system-libclang

Setup Vim Plugin Manager (regular and full versions)
Open Vim and use the Plug package manager to install and update all the plugins.  You can just use things right away but it’s better to clone and install the latest versions.


This above clean the current git repos, which are currently set to my file hierarchy.


The above will install the latest version of the plugins.


Use :PlugUpdate to update all the plugin git repos going forward when you like.


Set System Variables (regular and full versions)
Set some variables to not anger your system (like crontab or git).

git config --global core.editor /usr/bin/vim
echo "export EDITOR=vim" >> ~/.bashrc

That’s it, you should be ready to go.

What it Looks Like
Utilizing nerdtree (control + n to open/close) which is useful when editing many files.
Use T to open files as new vim tabs in the background, see tips below for more commands.


Working with SCM
Fugitive plugin adds useful git branch information and functionality.


Code View with Python
Using vim-jedi (control + space auto-completes possible library syntax and shows docstring info).
Yes, I think you can change the background color.


Things work in tmux as well.


Control P – Search
The cntrlp plugin provides full search/autocomplete of files inside current git repository or directory hierarchy.


Tmux Everything Completion (Full Version)
The youcompleteme + tmux-complete plugins let you autocomplete any variable, string, word or phrase used across any tmux sessions or panes.  This makes re-using variables and common strings a lot easier.  Like omni-completion for code syntax just type control + space when in insert mode.


In the above example I’m typing the letter “a” and control + space, it shows anything I’ve typed or seen in any of my existing tmux sessions or panes.

Javascript Completion (full version)
The gigantic MS word-sized full version does common Javascript syntax completion.


Email with Mutt
mutt compose is freshened up a bit with vim.


Updating Plugins with Plug
You can run :PlugUpdate to update your current plugins, or add new ones in your ~/.vimrc to install new ones:


Known Issues (full version only)
If you have problems with the vimfiles-full.tar version and powerline check that the $PYTHONPATH= is correct in ~/.vimrc as a workaround for powerline.

I’ve also seen occasional crashes of the ycm server for C syntax, but it restarts itself and you can hit enter to keep going.

Useful Vim Commands
This is a very small list, check other resources if you want to do something specific but here are some of the options I use frequently.

  • :tabe <path/to/file> – opens a new or existing file in a new tab
  • :tabnew – opens a new tab
  • gt – switches to the next tab
  • gT – switches to the previous tab
  • :set paste – enables paste mode, I turn this off by default for wordwrap in mutt
  • :set nopaste – turns off paste mode.
  • :set list – turns on whitespace indicators
  • :set nolist – turns off whitespace indicators
  • :set number – turns on line numbers
  • :set nonumber – turns off line numbers
  • ctrl + space – toggles code completion for Python or string completion of used strings elsewhere.
  • ctrl + n – toggles nerdtree file browser on/off
    • T  – opens files in new vim tab
    • ctrl + w + w – toggles nerdtree focus
    • r – refreshes current directory listings
    • R – refreshes root directory listings
    • m – filesytem actions: create, move
      • a – create a file or directory
      • m – move file or directory
      • d – delete file or directory
      • c – copy file or directory
  • :sp – creats a horizontal split pane
  • :vsp – creates a vertical split pane
  • :sp <path/to/file> – opens an existing or new file in a horizontal pane
  • :vsp <path/to/file> – opens an existing or new file in a vertical pane
  • ctrl + ww – jumps between split panes
  • ctrl + p – powerful file search/completion
  • :%s/dog/cat – searches for dog and replaces it with cat
  • v + direction arrows (or pgdn/pgup) – visual mode and text selection
    • y – yanks (copies) selection to a buffer
    • P – pastes the selection where your cursor is located
    • :s/dog/cat – you can also search/replace within highlighted text

About Will Foster

hobo devop/sysadmin, all-around nice guy.
This entry was posted in open source, sysadmin and tagged , , , , , . Bookmark the permalink.

Have a Squat, Leave a Reply ..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s