Customizing Vim Editor to Use as an Alternative to IDE
Vim is a lightweight integrated editor that comes most of the unix machines by default. However, we can customize it to make it more like an IDE and it is useful when you are remotely working on a machine and you don’t have a nice editor to work on your project. For that, you need to customize a file called .vimrc. So, create the file if it is not already there in your ~/ directory.
touch .vimrc
Now paste the following lines on your .vimrc file. You can open it with either nano editor or vim editor.
syntax on
set noerrorbells "no sound effects
set tabstop=4 softtabstop=4 "how many spaces a tab should use
set shiftwidth=4
set expandtab
set wildmenu
set smartindent
set rnu relativenumber " relative line number
set nowrap
set smartcase
set noswapfile "no swap file (vim creates them by default)
set nobackup "no backup file
set undodir=~/.nvim/undodir
set undofile
set cursorline
set incsearch
set formatoptions-=cro
set background=dark
These are some sane basic settings you can add and anything else you want. Now we need to add plugins to make vim better. In order to do that, we need to add a plugin manager. Download the plugin manager from here.
Add the following at the end of your .vimrc file:
call plug#begin("~/.vim/plugged")
" add plugins here
call plug#end()
After setting up vim plug you can do pretty much anything. First, we can set the color scheme. You can find the vim color schemes here but you don’t need to download anything from there. You can paste the following lines below " add plugins here to get 4 different color schemes:
Plug 'ps173/dadara'
Plug 'gruvbox-community/gruvbox'
Plug 'liuchengxu/space-vim-dark'
Plug 'dracula/vim', { 'as': 'dracula' }
Now add the following line after the line call plug#end() line to set up space-vim-dark color scheme:
colorscheme space-vim-dark
Install the plugins by opening vim and running :PlugInstall command.
Now, if you open vim, you should notice a nice theme. However, we’re going to add some more plugins such as - Nerd Tree (file viewer / manager), COC (for code completion), vim-devicons (for icons), polygot (better syntax highlighting), VColor and Colorizer (css colors), NerdCommenter (for commenting) etc. In order to install these, paset the following lines of code and your .vimrc file should look like this:
syntax on
set noerrorbells "no sound effects
set tabstop=4 softtabstop=4 "how many spaces a tab should use
set shiftwidth=4
set expandtab
set wildmenu
set smartindent
set rnu relativenumber " relative line number
set nowrap
set smartcase
set noswapfile "no swap file (vim creates them by default)
set nobackup "no backup file
set undodir=~/.nvim/undodir
set undofile
set cursorline
set mouse=a
set incsearch
set formatoptions-=cro
set background=dark
call plug#begin("~/.vim-back/plugged")
" add plugins here
Plug 'ps173/dadara'
Plug 'gruvbox-community/gruvbox'
Plug 'liuchengxu/space-vim-dark'
Plug 'dracula/vim', { 'as': 'dracula' }
"CSS properties and color selector
Plug 'KabbAmine/vCoolor.vim'
Plug 'lilydjwg/colorizer'
" File explorer
Plug 'scrooloose/nerdtree'
Plug 'ryanoasis/vim-devicons'
" Intellisense and code completion with syntax highlighting
Plug 'neoclide/coc.nvim', {'branch': 'release'}
let g:coc_global_extensions = ['coc-css', 'coc-html', 'coc-json', 'coc-tsserver']
Plug 'sheerun/vim-polyglot'
Plug 'preservim/nerdcommenter'
" Airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
colorscheme space-vim-dark
" NERD TREE AND ICONS
let g:NERDTreeShowHidden = 1
let g:NERDTreeMinimalUI = 0
let g:NERDTreeIgnore = ['node_modules']
let NERDTreeStatusline='NERDTree'
" Automaticaly close nvim if NERDTree is only thing left open
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" File explorer plugin
map <C-b> :NERDTreeToggle<CR>
" nerd commenter
noremap <leader>c :NERDCommenterComment<CR>
Remember to run :PlugInstall command to see the reflection. To know more about specific plugins, visit the respective github repo. Happy coding!
Enjoy Reading This Article?
Here are some more articles you might like to read next: