Vim is a versatile and powerful text editor for command-line environments in Linux/UNIX systems. Vim is free, open source, and is available on many different platforms, but it does have some quirks out of the box. If you’re comfortable working in a regular text editor you might find yourself lost, but in this guide I’ll show you how to supercharge Vim with a simple configuration file.
Besides the idiosyncrasies of being a non-GUI’d text editor, there were a couple things I wasn’t wild about when using a fresh, unmodified version of Vim:
- On some computers, the arrow keys don’t always navigate. They might instead insert random characters into your file (like the up and down arrows insert the letters A and B instead of navigating).
- Syntax highlighting is not on by default.
- Smart indenting is not enabled by default.
- Line numbers are not enabled by default.
- The Delete key does not function normally.
- No mouse functionality.
Vim’s settings are stored in a configuration file called .vimrc which is located in your profile’s home directory. You can add dozens of excellent features to Vim by making some very simple changes in this file – only one problem, you have to do a lot of reading to figure out which settings to enable.
A co-worker of mine recently gave me bartered with me for an excellent .vimrc file, and I enjoyed it so much that I decided to post it here. He notes that he originally found it on the internet and made changes to it, so if you want to take any credit for this wonderful configuration just let me know in the comments.
Modifying Vim’s Settings
To edit (or create) a .vimrc file, just go to your command-line environment and use a text editor to open ~/.vimrc (the ~/ syntax denotes your home directory). If you already have Vim installed, you can use the following command:
[code lang=”bash”]
vim ~/.vimrc
[/code]
After that, copy and paste the following code into the file (you might need to press Shift + Insert to paste), then write the changes to file with the command :wq). These changes will immediately take effect after you’ve re-opened Vim.
If you’re wondering what any of these settings do, check out the comments after each single quotation mark (“). Single quotation marks in the .vimrc file are viewed as comment syntax, meaning they will be ignored by Vim.
[code lang=”bash”]
set nocompatible "This fixes the problem where arrow keys do not function properly on some systems.
syntax on "Enables syntax highlighting for programming languages
set mouse=a "Allows you to click around the text editor with your mouse to move the cursor
set showmatch "Highlights matching brackets in programming languages
set autoindent "If you’re indented, new lines will also be indented
set smartindent "Automatically indents lines after opening a bracket in programming languages
set backspace=2 "This makes the backspace key function like it does in other programs.
set tabstop=4 "How much space Vim gives to a tab
set number "Enables line numbering
set smarttab "Improves tabbing
set shiftwidth=4 "Assists code formatting
colorscheme darkblue "Changes the color scheme. Change this to your liking. Lookin /usr/share/vim/vim61/colors/ for options.
"setlocal spell "Enables spell checking (CURRENTLY DISABLED because it’s kinda annoying). Make sure to uncomment the next line if you use this.
"set spellfile=~/.vimwords.add "The location of the spellcheck dictionary. Uncomment this line if you uncomment the previous line.
set foldmethod=manual "Lets you hide sections of code
"— The following commands make the navigation keys work like standard editors
imap <silent> <Down> <C-o>gj
imap <silent> <Up> <C-o>gk
nmap <silent> <Down> gj
nmap <silent> <Up> gk
"— Ends navigation commands
"— The following adds a sweet menu, press F4 to use it.
source $VIMRUNTIME/menu.vim
set wildmenu
set cpo-=<
set wcm=<C-Z>
map <F4> :emenu <C-Z>
"— End sweet menu
[/code]
With these changes, you should be dominating source code with Vim in no time. And I have no doubt that it will impress the ladies, too.
Image courtesy: Jason Ryan
Leave a Reply
You must be logged in to post a comment.