Post

VIM

How to turn Vim into a powerful and customizable IDE

What is Vim? - Vim is a text editor that is commonly used by programmers for writing and editing code. It is known for its powerful features and efficient navigation, which make it a popular choice among many developers.

Benefits or advantages of using Vim as an IDE

  • Efficient navigation: Vim uses a set of keyboard shortcuts for moving around and editing text, which can be more efficient than using a mouse. This allows users to work quickly and efficiently without having to take their hands off the keyboard.
  • Powerful features: Vim has a large number of built-in features and plugins that allow users to customize their editor and add additional functionality. This includes syntax highlighting, code completion, and support for many different programming languages.
  • Customizability: Vim is highly customizable, allowing users to configure their editor to suit their personal preferences and workflow. This includes setting keybindings, changing the color scheme, and adding plugins.
  • Community support: Vim has a large and active community of users who share tips, tutorials, and plugins online. This makes it easy for users to learn how to use Vim and get help when they need it.

Basics of setting up Vim as an IDE

Installing Vim

There are several ways of how you can install Vim.

a) Using package manager

  • On Debian and LinuxMint
    1
    
    └─$ sudo apt install vim
    
  • On Arch Linux
    1
    
    └─$ sudo pacman -S vim
    
  • On Fedora
    1
    
    └─$ sudo dnf install vim
    

b) Installing from source

  1. Make sure you have this packages installed
    1
    
    └─$ sudo apt-get install libncurses5-dev libperl-dev python-dev ruby-dev mercurial checkinstall lua5.2 liblua5.2-dev
    
  2. clone the vim source from github
    1
    
    └─$ git clone https://github.com/vim/vim.git
    
  3. Then move to the vim directory
    1
    
    └─$ cd vim
    
  4. Run this configure
    1
    2
    3
    4
    5
    6
    7
    8
    
    └─$ ./configure --prefix=/opt/vim \
             --enable-gui=no \
             --with-features=huge \
             --enable-perlinterp \
             --enable-pythoninterp \
             --enable-rubyinterp \
             --enable-luainterp \
             --enable-cscope
    
  5. compile and install
    1
    
    └─$ make && sudo make install
    

Customizing Vim for your specific needs

On your home directory, create a file called .vimrc and this is the file which you will place your vim configuration.

  • Setting to show line numbers
    1
    2
    
    set number
    set relative number
    
  • Setting backspace to behave normal. “Sometimes backspace doesn’t behave normal.”
    1
    
    set bs=2
    
  • Make search to be case insesitive
    1
    2
    3
    4
    5
    
    set hlsearch
    set incsearch
    set ignorecase
    set smartcase
    set nohlsearch "This is to remove the highlighting after searching
    
  • Setting compactibility mode to vim only
    1
    
    set nocompatible
    
  • Automatically wrap text that extends beyond the screen length
    1
    
    set wrap
    
  • set Encoding type to utf-8
    1
    
    set encoding=utf-8
    
  • To show status bar
    1
    
    set laststatus=2
    
  • Automatic deletes trailing white spaces on save. (I don’t always use this because I use a plugin that shows me the whitespaces on runtime)
    1
    
    autocmd BufWritepre * %s/\s\
    
  • set to change buffer without saving
    1
    
    set hidden
    
  • removing swapfiles
    1
    
    set noswapfile
    
  • view file folder stucture
    1
    2
    
    inoremap <c-n> <Esc>:Lex<cr>:vertical resize 30<cr>
    nnoremap <c-n> <Esc>:Lex<cr>:vertical resize 30<cr>
    
  • Automatically closing braces
    1
    2
    3
    4
    5
    6
    
    inoremap { {}<Esc>ha
    inoremap ( ()<Esc>ha
    inoremap [ []<Esc>ha
    inoremap " ""<Esc>ha
    inoremap ' ''<Esc>ha
    inoremap ` ``<Esc>ha
    
  • To disable the arrow keys My favorite
    1
    2
    3
    4
    
     noremap <Up> <Nop>
     noremap <Down> <Nop>
     noremap <Left> <Nop>
     noremap <Right> <Nop>
    
  • remapping jj to be escape key
    1
    
     imap jj <Esc>
    

    Customizing Vim for development

    Before starting we must set up a file we shall be using to install our plugins. For that case add this to your .vimrc file.

Make sure you have created a file called .vimrc.plugfile

  • On the .vimrc file call the .vimrc.plugfile
    1
    2
    3
    
     if filereadable(expand("~/.vimrc.plug"))
           source ~/.vimrc.plug
     endif
    
  • On .vimrc.plugfile add:
1
2
3
4
call plug#begin('~/.vim/plugged')
" All the plugins will be in between here

call plug#end()

There are alot of plugins but here are some of the essential ones for developers.

  1. Ale - (Asynchronous Lint Engine) is a plugin providing linting (syntax checking and semantic errors)
  2. COC - Coc is an intellisense engine for VIM.
  3. Markdown-preview - Markdown Preview for (Neo)vim

    Setting up vim for python development

    …coming soon

This post is licensed under CC BY 4.0 by the author.