How to Turn Vim Into a Lightweight IDE

Build your own editor to facilitate programming with Vim

Image for post
Image for post

Introduction

Task Overview

Getting the Final Configuration File

$ curl -L https://raw.githubusercontent.com/danebulat/vim-config/master/light-ide/vimrc > vimrc

Installing a Vim Plug-in Manager

$ mkdir -p ~/.vim/bundle
$ cd ~/.vim/bundle
$ git clone https://github.com/VundleVim/Vundle.vim.git Vundle.vim
set nocompatible
filetype off
" Set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
" Download plug-ins to the ~/.vim/plugged/ directory
call vundle#begin('~/.vim/plugged')
" Let Vundle manage Vundle
Plugin 'VundleVim/Vundle.vim'
call vundle#end()
filetype plugin indent on
$ vim ~/.vimrc
# In Vim
:PluginInstall

Modifying Some Vim Settings

set nu     " Enable line numbers
syntax on " Enable syntax highlighting
" How many columns of whitespace a \t is worth
set tabstop=4
" How many columns of whitespace a "level of indentation" is worth
set shiftwidth=4
" Use spaces when tabbing
set expandtab
set incsearch  " Enable incremental search
set hlsearch " Enable highlight search
set termwinsize=12x0   " Set terminal size
set splitbelow " Always split below
set mouse=a " Enable mouse drag on window splits
Image for post
Image for post
The configured terminal and window splitting.

Plug-in Installations

Language Packs for Syntax Highlighting

Plugin 'sheerun/vim-polyglot'
# Install on command line
$ vim +PluginInstall +qall
$ du -hcs ~/.vim/plugged/vim-polyglot

# Output
23M .vim/plugged/vim-polyglot/
23M total

Color Schemes

Plugin 'cocopon/iceberg.vim'
Plugin 'arcticicestudio/nord-vim'
Plugin 'Badacadabra/vim-archery'
Plugin 'kristijanhusak/vim-hybrid-material'
Plugin 'scheakur/vim-scheakur'
Plugin 'lifepillar/vim-solarized'
# Install on command line
$ vim +PluginInstall +qall
$ vim test.cpp
: color <TAB>
set background=dark   " dark or light
colorscheme scheakur " Your favorite color scheme's name
Image for post
Image for post
Previewing color schemes.

Pair Completion

Plugin 'jiangmiao/auto-pairs'
# Install on command line
$ vim +PluginInstall +qall
let g:AutoPairsShortcutToggle = '<C-P>'

File System Explorer

Plugin 'preservim/nerdtree'
# Install on command line
$ vim +PluginInstall +qall
NERDTree mappings for interacting with the file system.
Essential NERDTree commands.
NERDTree commands for working with bookmarks.
let NERDTreeShowBookmarks = 1   " Show the bookmarks table
let NERDTreeShowHidden = 1 " Show hidden files
let NERDTreeShowLineNumbers = 0 " Hide line numbers
let NERDTreeMinimalMenu = 1 " Use the minimal menu (m)
let NERDTreeWinPos = “left” " Panel opens on the left side
let NERDTreeWinSize = 31 " Set panel width to 31 columns
nmap <F2> :NERDTreeToggle<CR>
Image for post
Image for post
Using the NERDTree file explorer to open and edit files.

Source File Outliner

$ sudo pacman -S ctags
# Check Exuberant Ctags or Universal Ctags is installed
$ ctags --version
Plugin 'preservim/tagbar'
# Install on command line
$ vim +PluginInstall +qall
" Focus the panel when opening it
let g:tagbar_autofocus = 1
" Highlight the active tag
let g:tagbar_autoshowtag = 1
" Make panel vertical and place on the right
let g:tagbar_position = 'botright vertical'
" Mapping to open and close the panel
nmap <F8> :TagbarToggle<CR>
Essential tagbar mappings.
Image for post
Image for post
Using the tagbar panel to jump to source code.

Searching Files

sudo pacman -S ack
Plugin 'dyng/ctrlsf.vim'
# Install on command line
$ vim +PluginInstall +qall
" Use the ack tool as the backend
let g:ctrlsf_backend = 'ack'
" Auto close the results panel when opening a file
let g:ctrlsf_auto_close = { "normal":0, "compact":0 }
" Immediately switch focus to the search window
let g:ctrlsf_auto_focus = { "at":"start" }
" Don't open the preview window automatically
let g:ctrlsf_auto_preview = 0
" Use the smart case sensitivity search scheme
let g:ctrlsf_case_sensitive = 'smart'
" Normal mode, not compact mode
let g:ctrlsf_default_view = 'normal'
" Use absoulte search by default
let g:ctrlsf_regex_pattern = 0;
" Position of the search window
let g:ctrlsf_position = 'right'
" Width or height of search window
let g:ctrlsf_winsize = '46'
" Search from the current working directory
let g:ctrlsf_default_root = 'cwd'
" (Ctrl+F) Open search prompt (Normal Mode)
nmap <C-F>f <Plug>CtrlSFPrompt
" (Ctrl-F + f) Open search prompt with selection (Visual Mode)
xmap <C-F>f <Plug>CtrlSFVwordPath
" (Ctrl-F + F) Perform search with selection (Visual Mode)
xmap <C-F>F <Plug>CtrlSFVwordExec
" (Ctrl-F + n) Open search prompt with current word (Normal Mode)
nmap <C-F>n <Plug>CtrlSFCwordPath
" (Ctrl-F + o )Open CtrlSF window (Normal Mode)
nnoremap <C-F>o :CtrlSFOpen<CR>
" (Ctrl-F + t) Toggle CtrlSF window (Normal Mode)
nnoremap <C-F>t :CtrlSFToggle<CR>
" (Ctrl-F + t) Toggle CtrlSF window (Insert Mode)
inoremap <C-F>t <Esc>:CtrlSFToggle<CR>
Essential mappings for navigating the CtrlSF results panel.
Image for post
Image for post
Previewing CtrlSF search results.

Switching Between .h and .cpp Files

Plugin 'derekwyatt/vim-fswitch'
# Install on command line
$ vim +PluginInstall +qall
au! BufEnter *.cpp let b:fswitchdst = 'hpp,h'
au! BufEnter *.h let b:fswitchdst = 'cpp,c'These lines specify that:
nmap <C-Z> :vsplit <bar> :wincmd l <bar> :FSRight<CR>

Pulling Prototypes Into Implementation Files

Plugin 'derekwyatt/vim-protodef'
# Install on command line
$ vim +PluginInstall +qall
" Pull in prototypes
nmap <buffer> <silent> <leader> ,PP
" Pull in prototypes without namespace definition"
nmap <buffer> <silent> <leader> ,PN
Image for post
Image for post
Using the FSwitch and Protodef plug-ins.

In Conclusion

Related Articles

MSc. Programmer and fan of open source software.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store