Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Created June 11, 2014 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeinthehole/dd1f6528470d45628d1d to your computer and use it in GitHub Desktop.
Save codeinthehole/dd1f6528470d45628d1d to your computer and use it in GitHub Desktop.
" ==================================================
" VIMRC file for David Winterbottom (@codeinthehole)
" ==================================================
" Inspiration {{{
" -----------
" See http://www.youtube.com/watch?v=aHm36-na4-4
"
" Good articles:
" - http://alexpounds.com/blog/2014/06/06/the-vimrc-antiques-roadshow
" }}}
" Core {{{
" ----
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" Switch syntax highlighting on when the terminal has colors
if &t_Co > 2 || has("syntax")
syntax on
endif
filetype indent plugin on " Turn on filetype detection
" }}}
" Leader keys {{{
" -----------
" Comma is easy to type
let mapleader = ","
let g:mapleader = ","
" }}}
" Editing behaviour {{{
set backspace=indent,eol,start " Allow backspacing over everything in insert mode
set scrolloff=3 " Controls when to scroll winow
set showmatch " Show matching delimiters
set noshowmode " Don't show mode changes
set matchtime=1 " Jump to matching bracket for 2/10ths of a second
set autoindent " Always set autoindenting on
set si " Smart indenting
set nowrap " Don't word wrap
set tabstop=4 " Length of tab
set expandtab " Expand tabs into space
set shiftwidth=4
set softtabstop=4
set shiftround " Round indent to multiple of 'shiftwidth'
set smarttab " Allow backspacing of a shiftwidth of spaces
set noeol " Prevent a carriage return at end of last line
set lazyredraw " Don't redraw while executing macros (for performance)
" Treat hyphens as part of a word
set iskeyword+=-
" }}}
" Command line behaviour {{{
set completeopt=menu,longest,preview " Insert mode completion options
set complete-=i
set history=1000 " Number of lines in command line history
set showcmd " Display incomplete commands
set wildmenu " Use menu to show command line completions
set wildmode=list:longest,full " Command-line completion
set wildignore+=*.pyc,*egg-info*
set shellslash " A forward slash is used when expanding filenames
set cmdheight=2 " Try and avoid the dreaded "press <Enter> to continue" by setting the
" the height of the command bar
" }}}
" Appearance {{{
set ruler " Show the cursor position all the time in the status bar
set pastetoggle=<F11> " Toggle paste mode using F11
set number " Line numbers on by default
set confirm " Prompt for unsaved files
set title " Set window title to filename
let &titleold=""
set winminheight=0 " Allows windows to be fully squashed
" }}}
" Folding {{{
set foldenable
set foldmethod=marker
set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo
" }}}
" Misc {{{
set enc=utf-8 " Use UTF-8 as the default buffer encoding
set t_RV= " Don't request terminal version string
set mouse=a " Enables use of mouse in all modes
set mousehide " Hide mouse when typing
set ttyfast " Faster output (vim updates screen in bigger batches)
" }}}
" Display {{{
set shortmess=atI " Prevent file messages appearing
set visualbell " Rather than beeps
set virtualedit=block
" }}}
" Files/buffers {{{
set hidden " Don't abandon unloaded buffers
set fileformats=unix " File format
set autowrite " Auto-write file if modified on exit
set autoread " Auto-load file if it changes elsewhere
set nobackup " Don't keep a back-up file, they're annoying
set noswapfile
" }}}
" Searching {{{
set wrapscan " Wrap searching
set incsearch " Do incremental searching
set hlsearch " Highlight all search results (sometimes annoying)
set gdefault " Global setting on by default in subsituting
set ignorecase smartcase " Smart search behaviour
set magic
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor\ --column
set grepformat=%f:%l:%c%m
" Use ag for CtrlP plugin (it doesn't need to cache as it's so fast)
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
let g:ctrlp_use_caching = 0
endif
" }}}
" History - keep undo history between sessions {{{
if has('persistent_undo')
set undofile
set undodir=~/.vim_undo
set undolevels=2000
endif
" }}}
" GUI options {{{
if has("gui_running")
" Set GUI options
set guioptions-=m " Lose toolbar, menu and scrollbar
set guioptions-=T
set guioptions-=r
set guioptions-=L
" Dimensions
if &diff
set columns=240
else
set columns=120
endif
set lines=62
" Colors/font
set background=light
set guifont=Monaco:h14
set selectmode=mouse,key,cmd
endif
" }}}
" Operator-pending mappings {{{
" Text object for string wrapped in spaces
" eg {{ asdf|asdf }}
" maybe use ciW
vnoremap i<space> :<c-u>silent! normal! T<space>vt<space><cr>
vnoremap a<space> :<c-u>silent! normal! F<space>ft<space><cr>
omap i<space> :normal vi<space><cr>
omap a<space> :normal va<space><cr>
" Text object for word within a method name
" eg here_is_my_method_name
" More people don't have _ in their word chars
vnoremap i_ :<c-u>silent! normal! T_vt_<cr>
vnoremap a_ :<c-u>silent! normal! F_vf_<cr>
omap i_ :normal vi_<cr>
omap a_ :normal va_<cr>
" Text object for next set of parentheses
onoremap in( :<c-u>normal! f(vi(<cr>
onoremap i/ :<c-u>normal! T/vt/<cr>
" URL path segment
" eg /asdf/asdf/asdf
vnoremap i/ :<c-u>silent! normal! T/vt/<cr>
vnoremap a/ :<c-u>silent! normal! F/vf/<cr>
omap i/ :normal vi/<cr>
omap a/ :normal va/<cr>
" }}}
" Abbreviations {{{
" Auto-correct common typos
iabbrev si is
iabbrev tehn then
" }}}
" Mappings {{{
" ===========
" GLOBAL
" ------
" Make useless key useful again (UK Mac keyboard issue...)
set pastetoggle=§
" INSERT MODE
" -----------
" Alias for escape - see http://cloudhead.io/2010/04/24/staying-the-hell-out-of-insert-mode/
inoremap kj <ESC>
inoremap <ESC> <NOP>
" No more cursor keys!
inoremap <Left> <NOP>
inoremap <Right> <NOP>
inoremap <Up> <NOP>
inoremap <Down> <NOP>
" Mimic some emacs shortcuts that work in bash
inoremap <C-d> <ESC>ddi
inoremap <C-e> <ESC>A
inoremap <C-a> <ESC>I
" Save and quit from insert mode
inoremap <leader><leader> <ESC>:wq<CR>
" NORMAL MODE
" -----------
" Shortcut for :
nnoremap ; :
" Jump to alternate file
nnoremap <leader><leader> <c-^>
" Make yank consistent with other commands
nnoremap Y y$
" Disable unwanted keys
nnoremap K <NOP>
" Cursor moves up/down on the screen, not lines in the file
nmap j gj
nmap k gk
" Format paragraph
nnoremap Q gqap
" Stop cursor jumping when joining lines
nnoremap J mzJ`z
" Put result in centre of window when jumping between search results
nnoremap n nzz
nnoremap N Nzz
" Space is pager
nnoremap <Space> <PageDown>
" Jump between search matches when using :grep
nmap <silent> <RIGHT> :cnext<CR>
nmap <silent> <RIGHT><RIGHT> :cnfile<CR><C-G>
nmap <silent> <LEFT> :cprev<CR>
nmap <silent> <LEFT><LEFT> :cpfile<CR><C-G>
" Typos
nmap :W :w
nmap :E :e
nmap :Q :q
" Use backspace to turn off highlighted search terms
nnoremap <BS> :nohlsearch<CR>
" Select the last thing pasted
nnoremap gV `[v`]
" Leading mappings
" ----------------
" Faster saving and quiting
nnoremap <leader>w :w!<CR>
nnoremap <leader>q :q<CR>
nnoremap <leader>x :xa<CR>
" Change to current directory
nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
" Toggle paste mode
nnoremap <leader>pp :setlocal paste!<CR>
" Sort paragraph under cursor (useful for python imports)
nnoremap <leader>s vip : !sort<CR>
" Change to current directory
nnoremap <leader>f :CtrlP<CR>
" Diff behaviour
nnoremap <leader>u :diffupdate<cr>
nnoremap <leader>g :diffget<cr>
nnoremap <leader>p :diffput<cr>
set diffopt+=iwhite
" Quick file access
nnoremap <leader>b :e ~/.bashrc<CR>
nnoremap <leader>a :e ~/.bash_aliases<CR>
nnoremap <leader>i :e ~/.inputrc<CR>
nnoremap <leader>g :e ~/.gitconfig<CR>
nnoremap <leader>v :e $VIRTUAL_ENV/lib/python2.7/site-packages/
nnoremap <leader>o :e ~/Workspace/django-oscar/oscar/
nnoremap <leader>h :help<SPACE>
" Always use verymagic search mode
" nnoremap / /\v
" VISUAL MODE
" -----------
" Remap escape (annoying?)
vnoremap kj <ESC>
" When in visual mode, retain visual selection after action
vmap <expr> > ShiftAndKeepVisualSelection(">")
vmap <expr> < ShiftAndKeepVisualSelection("<")
function! ShiftAndKeepVisualSelection(cmd)
set nosmartindent
if mode() =~ '[Vv]'
return a:cmd . ":set smartindent\<CR>gv"
else
return a:cmd . ":set smartindent\<CR>"
endif
endfunction
" }}}
" Plugins {{{
" -------
" Pathogen (loaded this way so it works on remote servers where
" autoload/pathogen.vim might not exist). See
" https://github.com/tpope/vim-pathogen/issues/134
runtime! autoload/pathogen.vim
if exists("*pathogen#infect")
call pathogen#infect()
call pathogen#helptags()
endif
" Mini buffer explorer
let g:miniBufExplSplitBelow = 0 " Put new window above
let g:miniBufExplMapWindowNavVim = 1 " Allow CTRL+hj,k,l to jump between windows
let g:miniBufExplMapWindowNavArrows = 1 " Allow CTRL+arrows to jump between windows
let g:miniBufExplMapCTabSwitchBufs = 1 " CTRL+tab to jump between buffers
let g:miniBufExplModSelTarget = 1
let g:miniBufExplUseSingleClick = 1 " Single click to load buffer
map <Leader>b :MiniBufExplorer<CR>
map <Leader>bu :UMiniBufExplorer<CR>
" NERD_tree config
let NERDTreeIgnore = ['.pyc$', '\~$']
nnoremap <leader>n :NERDTreeToggle<CR>
" riv (RST editing)
let g:riv_fold_auto_update = 0 " Don't update folds on write
" }}}
" Status bar {{{
set showmode " Display which mode we're in
set laststatus=2 " Always show status bar
if has('statusline')
" Notes:
" %n = buffer number
" %f = path to file
" %y = filetype
" %l = line number
" %L = total lines in file
"
set statusline=%n\:\ %f\ %y\
set statusline+=%=
set statusline+=col\ %c\ line\ %l/%L
endif
" }}}
" Tags {{{
" ----
set tags=$VIRTUAL_ENV/tags,~/tags;/
" }}}
" Autocommands {{{
" ------------
" Save view on exit
autocmd BufWinLeave ?* silent mkview
autocmd BufWinEnter ?* silent loadview
" Better settings for Git commit messages
autocmd Filetype gitcommit setlocal spell textwidth=72
" Delete trailing whitespace when saving python files
autocmd BufWrite *.py :call DeleteTrailingWS()
function! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunction
" Set multiple filetypes for some types so that multiple snippet files
" are loaded.
autocmd FileType python set ft=python.django
autocmd FileType html set ft=htmldjango.html
" Some other filetypes
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd BufRead,BufNewFile *.scala set filetype=scala
autocmd BufRead,BufNewFile *.pp set filetype puppet
autocmd BufRead,BufNewFile *.sls set filetype=yaml
" Auto-source vimrc after save
augroup VimReload
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END
" }}}
" Colorscheme (put them in ~/.vim/colors) {{{
" These needs to be near the end of ~/.vimrc for some reason
if &t_Co >= 256 || has("gui_running")
" Don't complain if colorscheme doesn't exist
silent! colorscheme peaksea
set background=light
endif
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment