Some Tips for VIM Users

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  :set invnumber

"toggle wrapping mode with Ctrl+w
map  :set invwrap

"Reload Current File, ask for confirmation if changed
map  :confirm :edit

"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
  • 94 Users Found This Useful
Was this answer helpful?

Related Articles

Setting time with NTP in LINUX

NTP (Network Time Protocol) could be used to set time synced with ntp clocks, to do this use the...

Linux version & Operating System info

LINUX Version Info To learn the architecture and kernel version info use the shell command...

Compile and build Apache + MySQL + PHP from the source [cite]

This is a complete working solution to build Apache (httpd-2.2.25), MySQL (MySQL-5.6.14) and PHP...

Using vi Editor

Vi is the one of the mostly used editor in Linux via terminal. In most cases where Linux is used...

Build PHP5.5 on CentOS 6.4 with MSSQL Support [cite]

Most of the yum repos doesn’t include PHP5.5.X on current releases for the time being. So...