I’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.
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:
- vim-plug (simple vim plugin manager)
- gnupg-vim (useful for encrypted files and resources)
- vim-airline (adds useful icons, coloring, tab/buffer/split behavior and more)
- tabular (text alignment)
- vim-colors-solarized (more colors and looks)
- vim-fugitive (git branch awareness and more)
- vim-jinja2 (jinja2 template syntax)
- tmux-vim (tmux and vim compatibility and fixes)
- tmux-complete (insert mode completion of words in adjacent tmux panes)
- nerdtree (file manager / tree explorer for vim)
- vim-jedi (Python syntax completion in vim)
- vim-powerline (enhanced status line)
- vim-obsession (continually save vim sessions every 15minutes)
- ctrlp (search/complete files plugin, control + p to activate)
- youcompleteme (entire code completion engine) – full version only see below
- ycmd (code completion backend engine) – full version only, see below
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 ~ wget https://github.com/sadsfae/misc-dotfiles/raw/master/vimfiles.tar tar -xvf vimfiles.tar
When this is complete skip past the sections marked full version only.
or .. Option #2 – Download the Full Version (328MB)
cd ~ wget https://github.com/sadsfae/misc-dotfiles/raw/master/vimfiles-full.tar 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
python3 build.py --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.
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