Time for a new vim setup!
5 Sep 2015
The last time I updated my vim config in any serious way, vim 7.1 was all the rage. As of this writing, we are up to vim 7.4, and I've started loving go, so it's time for a serious update!
Step 1: Blow away .exrc and .gvimrc and consolidate everything in .vimrc.
.exrc is for really old versions of vi that don't need to exist anymore, and vim is smart enough to ignore the gvim stuff inside .vimrc, so there's no need for me to keep a separate .gvimrc anymore.
Also, because of Pathogen, vim now has a standard way of doing plugins! I will actually use vim-plug, but the format carries across other vim plugin managers.
Step 2: Make sure you tell Bash your terminal is capable of 256 colors by putting this somewhere in your .bashrc:
###############################################
# Tell terminal it can support 256 colors
export TERM=xterm-256color
# Tell the world (git in particular) that you want to use vim
# (instead of vi, which seems to pretend it can't understand all of .vimrc)
export VISUAL=vim
export EDITOR=vim
# Make vi a function that calls vim
vi() {
vim "$@"
}
Step 3: Download vim-plug.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Step 4: Put my color scheme in its own file. Gone are the days of putting my color preferences in .vimrc and .gvimrc! Put this in ~/.vim/colors/
highlight clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name = "manni"
highlight Normal guibg=grey91 guifg=Black ctermfg=0
highlight Cursor guibg=Black guifg=White ctermfg=15
highlight NonText guibg=bg guifg=#bcbcbc ctermfg=250
highlight SpecialKey guibg=bg guifg=#bcbcbc ctermfg=250
" programming...
highlight Comment guibg=bg guifg=grey50 ctermfg=244
highlight Constant guibg=bg guifg=Brown ctermfg=124
highlight Label guibg=bg guifg=Brown ctermfg=124
highlight Number guibg=bg guifg=Brown ctermfg=124
highlight Special guibg=bg guifg=DarkRed ctermfg=9
highlight Function guibg=bg guifg=DarkBlue ctermfg=18
" NONE resets Type; in particular, turn off bold from default setting
highlight Type NONE
highlight Type guibg=bg guifg=Purple ctermfg=91
highlight Statement NONE
highlight Statement guibg=bg guifg=DarkGreen ctermfg=22
highlight StorageClass NONE
highlight StorageClass guibg=bg guifg=DarkBlue ctermfg=18
Step 5: Put this in ~/.vimrc
set nocompatible " enable vim features instead of strict vi compatibility
set t_Co=256 " tell vim it's OK to use 256 colors at the terminal
filetype on " try to detect the filetype
filetype plugin on " enable loading the plugin file for specific file types
filetype indent on " enable loading the indent file for specific file types
syntax on " enable syntax highlighting
call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
call plug#end()
set showmatch " show matching brackets and parens
" syntax sync minlines=5000 " sync syntax highlighting in a 5000-line window
syntax sync fromstart " sync syntax highlighting from the start of the file
set nobackup " do not make backup~ files
set nowritebackup " do not make backup~ files
set encoding=utf-8 " set character encoding to UTF-8
set scrolloff=3 " show 3 lines above or below cursor when scrolling
set showmode " show insert, replace, or visual mode in last line
set showcmd " show command in last line
set visualbell " flash screen on bell
set ttyfast " assumes fast connection
set ruler " show line and column number
set laststatus=2 " every window gets a status line
set list " show spaces and tabs
set listchars=tab:→\ ,space:·,trail:·,nbsp:·
set nohlsearch " switch off search pattern highlighting
" WARNING: need a space at the end of this line
set statusline=%<%F%m%r%h%w\ \ \ \ %=%{&ff}/%Y\ \ \ \ %l,%v\ \ \ %o\
colorscheme manni
" for gvim
set guifont=Monospace\ 9
set ch=2 " make command line two lines high
set mousehide " turn off mouse pointer when typing begins
set mouse=c " put mouse in command-line mode, so mouse clicks don't move cursor
set guioptions-=T " turn off toolbar
set guioptions-=m " turn off menus
set guioptions+=b " add horizontal scrollbar
set nowrap " do not wrap long lines; have them scroll off the side
" Make shift-insert work like in Xterm
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
" Set startup window size, which only makes sense for gvim, not vim in
" terminal
if has("gui_running")
set lines=60 columns=120
endif
let mapleader = ","
let maplocalleader = "\\"
" Ruby overrides
augroup filetype_ruby
autocmd!
autocmd FileType ruby setlocal shiftwidth=2
autocmd FileType ruby setlocal softtabstop=2
autocmd FileType ruby setlocal expandtab
augroup END
" golang overrides
augroup filetype_golang
autocmd!
autocmd FileType go setlocal shiftwidth=2
autocmd FileType go setlocal tabstop=2
autocmd FileType go setlocal softtabstop=0
autocmd FileType go setlocal noexpandtab
autocmd FileType go nmap <Leader>d <Plug>(go-def-vertical)
autocmd FileType go nmap <Leader>D <Plug>(go-doc-vertical)
autocmd FileType go nmap <Leader>b <Plug>(go-doc-browser)
autocmd FileType go nmap <Leader>i <Plug>(go-implements)
autocmd FileType go nmap <Leader>n <Plug>(go-info)
autocmd FileType go nmap <Leader>r <Plug>(go-rename)
augroup END
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_fmt_command = "goimports"
Step 6: Install gorename so that you can use it from within vim:
go get golang.org/x/tools/cmd/gorename
Step 7: Install gocode so that you can use it from within vim:
go get github.com/nsf/gocode $GOPATH/bin/gocode set propose-builtins true
Step 8: Install the vim-go plugin. Launch vim, and type :PlugInstall,
and the vim-go plugin will get installe. Restart vim.
Custom compile vim
4 Sep 2015
The instructions at http://vim.wikia.com/wiki/Building_Vim still work fine with the source code downloaded from https://github.com/vim/vim.