What a simple editor like vim can do hmmmmm??🤔
Published on March 27, 2021 by Suraj Kumar
vim vimrc editor_in_unix secforge
6 min READ
Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient.
Vim is highly configurable and an editor that is really built for developers and operations.
We want an editor which is quick. Modern IDE takes 1 or 2 minutes based on system configuration to load on machine. usally we have to download additional packages to make the IDE work more efficently.
We will cover some topics to make our vim more interactive and cool.
Let’s begin our journey with the more improvised vim editor so let’s Roll.
vim ~/.vimrc
# Inside the vimrc files updated these lines
syntax on
set noerrorbells
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab
set smartindent
set nu
set nowrap
set smartcase
set noswapfile
set nobackup
set undodir=~/.vim/undodir
set undofile
set incsearch
set colorcolumn=80
highlight ColorColumn ctermbg=0 guibg=lightgrey
:source %
:wq!
Syntax on just gives you some basic high-lighting this works with a lot of language. But you may have to add some extension to work with every language
No beep occurs when an error message is displayed.
tabstop meaning that it’s only four characters long.
softtabstop meaning that it’s only four spaces long.
This will set tabstops every 4 spaces and set the shiftwidth (that amount we indent) as 4 spaces.
Expand tab simply means converted from a tab character to spaces.
Vim do its best to indent.
We get nice line numbers
It simply means if the lines go off the screen it appears on the next line so instead of that i want to just go off with no wrapping.
The ‘smartcase’ option only applies to search patterns that you type.
To disable swap files from within vim.
To prevent new swap files from being created.
Vim to keep its undo history . Happens with me a lot like once I saved the files I need to undo it but vim don’t let me do this after this setup we have to create this directory
mkdir ~/.vim/undodir -p
ls ~/.vim
Save undos after file closes.
Incremental searches will be done. The Vim editor will start searching when you type the first character of the search string. As you type in more characters, the search is refined. :/search
VIM will highlight anything that exceeds column 80.
Its simply sources the files you have.Sourcing a file is ‘executing’ it
Now we are done with the sets. Its improved the vim editor But we have to uncover more treasures in Vim
Well well we need some installer and plugin manager to do some cool stuff for us.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# Open the ~/.vimrc Add the following lines.
# I have listed all the plugins I tried.
call plug#begin('~/.vim/plugged')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/nerdcommenter'
Plug 'altercation/vim-colors-solarized'
Plug 'itchyny/lightline.vim'
" call PlugInstall to install new plugins
call plug#end()
" basics
filetype plugin indent on
syntax on
"set nu
"set relativenumber
set incsearch
set ignorecase
set smartcase
set nohlsearch
set tabstop=2
set softtabstop=0
set shiftwidth=4
set expandtab
set nobackup
set noswapfile
set nowrap
set cursorcolumn
set cursorline
let mapleader = "\<Space>"
" navigate split screens easily
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
nmap <C-_> <Plug>NERDCommenterToggle
nmap <C-_> <Plug>NERDCommenterToggle<CR>gv
" solarized
syntax enable
set background=dark
" deoplete
let g:deoplete#enable_at_startup = 1
" use tab to forward cycle
inoremap <silent><expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
" use tab to backward cycle
inoremap <silent><expr><s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
" Close the documentation window when completion is done
autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif
"NERDTree
" How can I close vim if the only window left open is a NERDTree?
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" toggle NERDTree
map <C-n> :NERDTreeToggle<CR>
let g:NERDTreeChDirMode=2
let g:NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__', 'node_modules']
let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
let g:NERDTreeShowBookmarks=1
let g:nerdtree_tabs_focus_on_files=1
let g:NERDTreeMapOpenInTabSilent = '<RightMouse>'
if has('persistent_undo') "check if your vim version supports it
set undofile "turn on the feature
set undodir=$HOME/.vim/undo "directory where the undo files will be stored
endif
:source %
:PlugInstall
vim -c 'PlugInstall'
# In case if source gives some error
I know we can do a lot with vim . There’s still a lot to learn but as far I have learned I have shared my vimrc files and some Intresting tips that you can also apply for vim configurations.
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/nerdcommenter'
Plug 'altercation/vim-colors-solarized'
Plug 'itchyny/lightline.vim'