Skip to content

Instantly share code, notes, and snippets.

@assaf
Created May 21, 2013 19:50
Show Gist options
  • Save assaf/5622679 to your computer and use it in GitHub Desktop.
Save assaf/5622679 to your computer and use it in GitHub Desktop.
.vimrc
version 7.0
if &cp | set nocp | endif
let s:cpo_save=&cpo
set cpo&vim
let &cpo=s:cpo_save
unlet s:cpo_save
set cscopeprg=/usr/bin/cscope
set cscopetag
set cscopeverbose
set fileencodings=utf-8,latin1
set helplang=en
set showcmd "show incomplete cmds down the bottom
set showmode "show current mode down the bottom
set hlsearch "hilight searches by default
set linebreak "wrap lines at convenient points
set paste
set mouse=a
let MRU_File=$HOME.'/.vimrecent'
let MRU_Max_Entries = 1000
let MRU_Use_Current_Window = 1
"syntax on
" Syntax coloring lines that are too long just slows down the world
set synmaxcol=2048
" Ack so much better than grep.
set grepprg=ack\ -a
" Conversion HTML (:help 2html.vim)
let g:html_use_css = 1
let g:html_use_encoding = "utf8"
let g:use_xhtml = 0
set scrolloff=3
runtime macros/matchit.vim
set wildignore=*.o,*.obj,*.rbc,*~ "stuff to ignore when tab completing
set smartcase
" ---------------------------------------------------------------------------
" General
" ---------------------------------------------------------------------------
set nocompatible " essential
set history=1000 " lots of command line history
set cf " error files / jumping
set ffs=unix,dos,mac " support these files
set isk+=_,$,@,%,#,- " none word dividers
set viminfo='1000,f1,:100,@100,/20
set modeline " make sure modeline support is enabled
"set autoread " reload files (no local changes only)
set tabpagemax=50
set dictionary=/usr/share/dict/words
let g:netrw_http_cmd = "curl"
let g:netrw_http_xcmd = "-o"
" ----------------------------------------------------------------------------
" Backups
" ----------------------------------------------------------------------------
set nobackup " do not keep backups after close
set writebackup " do keep a backup while working
set backupdir=~/.vim/backup
set directory=~/.vim/backup
set backupcopy=yes " keep attributes of original file
set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
" ----------------------------------------------------------------------------
" Text Formatting
" ----------------------------------------------------------------------------
set autoindent " automatic indent new lines
set smartindent " be smart about it
set nowrap " do not wrap lines
set softtabstop=2 " yep, two
set shiftwidth=2 " ..
set tabstop=2
set expandtab " expand tabs to spaces
set nosmarttab " fuck tabs
set formatoptions+=n " support for numbered/bullet lists
set textwidth=80 " wrap at 80 chars by default
set virtualedit=block " allow virtual edit in visual block ..
" ----------------------------------------------------------------------------
" UI
" ----------------------------------------------------------------------------
set ruler " show the cursor position all the time
set noshowcmd " don't display incomplete commands
set nolazyredraw " turn off lazy redraw
set number " line numbers
set wildmenu " turn on wild menu
set wildmode=list:longest,full "make cmdline tab completion similar to bash
set ch=2 " command line height
"set backspace=indent,eol,start
set backspace=2 " allow backspacing over everything in insert mode
set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
set shortmess=filtIoOA " shorten messages
set report=0 " tell us about changes
set nostartofline " don't jump to the start of line when scrolling
set nofoldenable
set foldmethod=manual
" ----------------------------------------------------------------------------
" Visual Cues
" ----------------------------------------------------------------------------
set showmatch " brackets/braces that is
set mat=5 " duration to show matching brace (1/10 sec)
set incsearch " do incremental searching
set laststatus=2 " always show the status line
set ignorecase " ignore case when searching
set nohlsearch " don't highlight searches
set visualbell " shut the fuck up
highlight IncSearch ctermfg=7 ctermbg=3 cterm=underline
highlight Search ctermfg=7 ctermbg=3 cterm=underline
"statusline setup
set statusline=%f "tail of the filename
"display a warning if fileformat isnt unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*
"display a warning if file encoding isnt utf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*
set statusline+=%h "help file flag
set statusline+=%y "filetype
set statusline+=%r "read only flag
set statusline+=%m "modified flag
"display a warning if &et is wrong, or we have mixed-indenting
set statusline+=%#error#
set statusline+=%{StatuslineTabWarning()}
set statusline+=%*
set statusline+=%{StatuslineTrailingSpaceWarning()}
"display a warning if &paste is set
set statusline+=%#error#
set statusline+=%{&paste?'[paste]':''}
set statusline+=%*
set statusline+=%= "left/right separator
set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
set statusline+=%c, "cursor column
set statusline+=%l/%L "cursor line/total lines
set statusline+=\ %P "percent through file
"recalculate the trailing whitespace warning when idle, and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
"return '[\s]' if trailing white space is detected
"return '' otherwise
function! StatuslineTrailingSpaceWarning()
if !exists("b:statusline_trailing_space_warning")
if search('\s\+$', 'nw') != 0
let b:statusline_trailing_space_warning = '[\s]'
else
let b:statusline_trailing_space_warning = ''
endif
endif
return b:statusline_trailing_space_warning
endfunction
"return the syntax highlight group under the cursor ''
function! StatuslineCurrentHighlight()
let name = synIDattr(synID(line('.'),col('.'),1),'name')
if name == ''
return ''
else
return '[' . name . ']'
endif
endfunction
"recalculate the tab warning flag when idle and after writing
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
"return '[&et]' if &et is set wrong
"return '[mixed-indenting]' if spaces and tabs are used to indent
"return an empty string if everything is fine
function! StatuslineTabWarning()
if !exists("b:statusline_tab_warning")
let tabs = search('^\t', 'nw') != 0
let spaces = search('^ ', 'nw') != 0
if tabs && spaces
let b:statusline_tab_warning = '[mixed-indenting]'
elseif (spaces && !&et) || (tabs && &et)
let b:statusline_tab_warning = '[&et]'
else
let b:statusline_tab_warning = ''
endif
endif
return b:statusline_tab_warning
endfunction
" ----------------------------------------------------------------------------
" Mappings
" ----------------------------------------------------------------------------
map! <xHome> <Home>
map! <xEnd> <End>
map! <S-xF4> <S-F4>
map! <S-xF3> <S-F3>
map! <S-xF2> <S-F2>
map! <S-xF1> <S-F1>
map! <xF4> <F4>
map! <xF3> <F3>
map! <xF2> <F2>
map! <xF1> <F1>
map <xHome> <Home>
map <xEnd> <End>
map <S-xF4> <S-F4>
map <S-xF3> <S-F3>
map <S-xF2> <S-F2>
map <S-xF1> <S-F1>
map <xF4> <F4>
map <xF3> <F3>
map <xF2> <F2>
map <xF1> <F1>
" quickfix mappings
map <F7> :cn<CR>
map <S-F7> :cp<CR>
map <A-F7> :copen<CR>
noremap <Space> j
noremap <BS> X
" emacs movement keybindings in insert mode
imap <C-a> <C-o>0
imap <C-e> <C-o>$
map <C-e> $
map <C-a> 0
" reflow paragraph with Q in normal and visual mode
nnoremap Q gqap
vnoremap Q gq
" sane movement with wrap turned on
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" do not menu with left / right in command line
cnoremap <Left> <Space><BS><Left>
cnoremap <Right> <Space><BS><Right>
noremap <D-Right> <Esc>:tabnext<CR>
noremap <D-S-Right> <Esc>:tabnext<CR>
noremap <D-Left> <Esc>:tabprev<CR>
noremap <D-S-Left> <Esc>:tabprev<CR>
"make Y consistent with C and D
nnoremap Y y$
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" reselect visual block after ident/outdent
vnoremap < <gv
vnoremap > >gv
" ---------------------------------------------------------------------------
" Commands
" ---------------------------------------------------------------------------
cmap w!! w !sudo tee % >/dev/null
command! Q quit
command! W write
command! Wq wq
command! -bar -nargs=0 SW :silent exe "write !sudo tee % >/dev/null"|silent edit!
" ---------------------------------------------------------------------------
" Pathogen
" ---------------------------------------------------------------------------
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
filetype plugin indent on " load filetype plugin
" ---------------------------------------------------------------------------
" Colors
" ---------------------------------------------------------------------------
syntax enable
set background=dark
colorscheme solarized
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
" ---------------------------------------------------------------------------
" Powerline
" ---------------------------------------------------------------------------
python from powerline.ext.vim import source_plugin; source_plugin()
set guifont=Menlo\ for\ Powerline:h16
set nocompatible
set laststatus=2
" ---------------------------------------------------------------------------
" Misc
" ---------------------------------------------------------------------------
let g:CommandTAcceptSelectionTabMap=['<Tab>']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment