VIM, one of the best text editors of all time, has a lot of useful options which are usually hidden. To get the best out of this text editor, I’d recommend checking some of these features out.

To get these settings enabled by default, add the lines to your vimrc file, it is usually located at ~/.vimrc if not, just create it. Below is a part of the .vimrc file I like using.

"set tabwidth to 4 characters, automatic indentation and stuff
set tabstop=4 shiftwidth=4
set expandtab
set smarttab
set autoindent
set smartindent

"set searching case insensitive, but if you type uppercase, it will go case sensitive
set ignorecase
set smartcase

"2 lines above/below cursor when scrolling
set scrolloff=2

"show filename in title bar
set title

"show line numbers, and toggle it on/off with F2
set number
map <F2> :set invnumber<CR>

"toggle wrapping mode with Ctrl+w
map <C-w> :set invwrap<CR>

"Reload Current File, ask for confirmation if changed
map <F5> :confirm :edit<CR>

"automatically cd into the directory that the file is in, very useful when running commands within vi
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

"highlight the current line, when you split screen, it will only highlight the line that has focus on
hi CursorLine cterm=NONE ctermbg=blue ctermfg=NONE
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
set cursorline

"set encoding to utf-8
set encoding=utf-8

"highlight search results
set hlsearch
"search while typing
set incsearch

Leave a Reply

Your email address will not be published. Required fields are marked *