A couple of days ago I finally got fed up with Sublime Text asking me if I wanted to buy a registered version and switched to Vim. I am thoroughly enjoying the switch, and thought I would share some tips that helped me in this post.

Vim?

Yes, Vim. For those who are unfamiliar, Vim is a text editor as old as dirt. Okay, maybe it’s not that old, but still. It’s also one of the most powerful editors out there, and like good wine it has improved greatly with age.

Janus

If you are new to Vim, I would recommend using Janus. This will set you up with tons of color schemes as well as a few useful plugins to get you started. To install Janus, first install the prerequisites.

On Linux and Mac OSX, this means installing ack, ctags, git, and rake. I recommend installing gvim (on OSX, use MacVim) as well, as some color schemes are finicky in the terminal version (even with 256 color mode enabled). I have not tried installing on Windows so I can’t help with that. However, on Mac and Linux, the next step is executing the following command in terminal:

$ curl -Lo- https://bit.ly/janus-bootstrap | bash

An important thing to keep in mind if you decide to use Janus is that when you install new plugins, unlike with vanilla Vim, you will need to git clone new plugins into the ~/.janus directory, not the ~/.vim/bundle directory. In practice this would mean that where the plugin readme may tell you to install the plugin by running this

$ git clone https://github.com/username/project ~/.vim/bundle/project

you should instead run this:

$ git clone https://github.com/username/project ~/.janus/project

Another thing you have to keep in mind is that instead of editing your .vimrc file you should edit the .vimrc.after file. This ensures that your settings will not be overwritten when Janus is updated.

Copy and Pasting From Other Programs

At first I tried adding key commands for Ctrl-V and Ctrl-C to my .vimrc file, but they didn’t work very well. I then found that you can use Ctrl-Insert to copy and Shift-Insert to paste, and it works system-wide, so now I just do that instead of trying to map it to Ctrl-V.

Some Helpful Plugins

Besides the ones that come with Janus, I found these plugins helpful:

  • Vim-session: Adds session-save options. I have it set to autosave my session on close.
  • Vim-airline: A very pretty status line for Vim. Add this to your .vimrc.after if you are having trouble getting your patched font to work.
set encoding=utf-8
let g:airline_powerline_fonts=1
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
let g:airline_detect_modified=1
  • Vimshell: Gives you a somewhat mature shell in gVim.
  • Auto-Pairs: Automatically adds closing brackets and parentheses.

My Current .vimrc.after

In case it helps anyone:

" Change working directory
cd ~

" be iMproved
set nocompatible

" disable the welcome screen
set shortmess+=I

" ctrl-v and ctrl-c copy/paste
"map <C-c> "+y
"map <C-x> "+x
"map <C-v> <ESC>"+gP

" vimshell shortcut
map <leader>s <ESC>:VimShellPop<return>

" my font
set guifont=Source\ Code\ Pro\ for\ Powerline\ Medium\ 13

" color scheme
set t_Co=256
color jellybeans

" airline stuff
let g:airline_powerline_fonts=1
"let g:airline_right_sep='<'
set encoding=utf-8
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
let g:airline_detect_modified=1

" Vimshell stuff
let g:vimshell_enable_smart_case = 1
let g:vimshell_prompt = '>'
let g:vimshell_right_prompt = 'system("date")'
let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")'
let g:vimshell_temporary_directory = "~/tmp/vimshell"

" fix tab size
set tabstop=4
set shiftwidth=4
set noexpandtab

" more stuffs
set ttimeoutlen=50

" Laravel stuff
autocmd FileType *.php set ft=php.laravel
autocmd BufEnter *.blade.php set ft=php.laravel.blade

" Auto-source .vimrc and .gvimrc on change
augroup myvimrc
	au!
	autocmd bufwritepost .vimrc.after source ~/.vimrc.after
	autocmd bufwritepost .vimrc.before source ~/.vimrc.before
	autocmd bufwritepost .vimrc source ~/.vimrc
augroup END

" super retab (http://vim.wikia.com/wiki/VimTip1592)
command! -nargs=1 -range SuperRetab <line1>,<line2>s/\v%(^ *)@<= {<args>}/\t/g
command! -range=% -nargs=0 Tab2Space execute '<line1>,<line2>s#^\t\+#\=repeat(" ", len(submatch(0))*' . &ts . ')'
command! -range=% -nargs=0 Space2Tab execute '<line1>,<line2>s#^\( \{'.&ts.'\}\)\+#\=repeat("\t", len(submatch(0))/' . &ts . ')'

" custom autocmds
map <leader>w :set wrap linebreak nolist<CR>
map <leader>W :set nowrap nolinebreak list<CR>

" session save variables
let g:session_autosave = 'yes'
let g:session_persist_colors = 0
let g:session_autoload = 'yes'

About Mark Fischer, Jr.

Mark is a web developer and programmer. He likes reading classic novels, listening to classical music, skiing, and eating donuts.

Filed under vim