Skip to content

Instantly share code, notes, and snippets.

@areinull
Last active October 2, 2015 08:58
Show Gist options
  • Save areinull/98c62eecffa4e21006c6 to your computer and use it in GitHub Desktop.
Save areinull/98c62eecffa4e21006c6 to your computer and use it in GitHub Desktop.
My vimrc
"Use Vim settings, rather then Vi settings (much better!).
"This must be first, because it changes other options as a side effect.
set nocompatible
"colors zenburn
set background=dark
set exrc
set secure
"set encoding to utf-8
if has("multi_byte")
if &termencoding == ""
let &termencoding = &encoding
endif
set encoding=utf-8
setglobal fileencoding=utf-8
"setglobal bomb
set fileencodings=ucs-bom,utf-8,latin1
endif
"activate vundle
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
"Plugin 'scrooloose/syntastic' "see bellow for status line message
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree'
Plugin 'rdnetto/YCM-Generator'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'majutsushi/tagbar'
Plugin 'sjl/gundo.vim'
" All of your Plugins must be added before the following line
call vundle#end()
filetype plugin indent on
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
"store lots of :cmdline history
"set history=1000
set showcmd "show incomplete cmds down the bottom
set showmode "show current mode down the bottom
set number "show line numbers
highlight LineNr ctermfg=darkgrey guibg=darkgrey
"display tabs and trailing spaces
set list
set listchars=tab:··,trail:·,nbsp:·
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
set incsearch "find the next match as we type the search
set hlsearch "hilight searches by default
set wrap "dont wrap lines
set linebreak "wrap lines at convenient points
if v:version >= 703
"undo settings
set undodir=~/.vim/undofiles
set undofile
set textwidth=110
set colorcolumn=+1 "mark the ideal max text width
highlight ColorColumn ctermbg=darkgrey guibg=darkgrey
endif
"default indent settings
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set autoindent
set smarttab
"folding settings
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
set wildmode=list:longest "make cmdline tab completion similar to bash
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set formatoptions-=o "dont continue comments when pushing o/O
"vertical/horizontal scroll off settings
set scrolloff=3
set sidescrolloff=7
set sidescroll=1
"turn on syntax highlighting
syntax on
"some stuff to get the mouse going in term
"set mouse=a
"set ttymouse=xterm2
"tell the term has 256 colors
set t_Co=256
"hide buffers when not displayed
set hidden
"statusline setup
set statusline =%#identifier#
set statusline+=[%t] "tail of the filename
set statusline+=%*
"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
"read only flag
set statusline+=%#identifier#
set statusline+=%r
set statusline+=%*
"modified flag
set statusline+=%#identifier#
set statusline+=%m
set statusline+=%*
"set statusline+=%{fugitive#statusline()}
"display a warning if &et is wrong, or we have mixed-indenting
set statusline+=%#error#
set statusline+=%{StatuslineTabWarning()}
set statusline+=%*
set statusline+=%{StatuslineTrailingSpaceWarning()}
set statusline+=%{StatuslineLongLineWarning()}
"Syntastic related
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
"let g:syntastic_check_on_open = 1
"let g:syntastic_check_on_wq = 0
"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
set laststatus=2
"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 !&modifiable
let b:statusline_trailing_space_warning = ''
return b:statusline_trailing_space_warning
endif
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 b:statusline_tab_warning = ''
if !&modifiable
return b:statusline_tab_warning
endif
let tabs = search('^\t', 'nw') != 0
"find spaces that arent used as alignment in the first indent column
let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0
if tabs && spaces
let b:statusline_tab_warning = '[mixed-indenting]'
elseif (spaces && !&et) || (tabs && &et)
let b:statusline_tab_warning = '[&et]'
endif
endif
return b:statusline_tab_warning
endfunction
"recalculate the long line warning when idle and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
"return a warning for "long lines" where "long" is either &textwidth or 80 (if
"no &textwidth is set)
"
"return '' if no long lines
"return '[#x,my,$z] if long lines are found, were x is the number of long
"lines, y is the median length of the long lines and z is the length of the
"longest line
function! StatuslineLongLineWarning()
if !exists("b:statusline_long_line_warning")
if !&modifiable
let b:statusline_long_line_warning = ''
return b:statusline_long_line_warning
endif
let long_line_lens = s:LongLines()
if len(long_line_lens) > 0
let b:statusline_long_line_warning = "[" .
\ '#' . len(long_line_lens) . "," .
\ 'm' . s:Median(long_line_lens) . "," .
\ '$' . max(long_line_lens) . "]"
else
let b:statusline_long_line_warning = ""
endif
endif
return b:statusline_long_line_warning
endfunction
"return a list containing the lengths of the long lines in this buffer
function! s:LongLines()
let threshold = (&tw ? &tw : 80)
let spaces = repeat(" ", &ts)
let line_lens = map(getline(1,'$'), 'len(substitute(v:val, "\\t", spaces, "g"))')
return filter(line_lens, 'v:val > threshold')
endfunction
"find the median of the given array of numbers
function! s:Median(nums)
let nums = sort(a:nums)
let l = len(nums)
if l % 2 == 1
let i = (l-1) / 2
return nums[i]
else
return (nums[l/2] + nums[(l/2)-1]) / 2
endif
endfunction
"nerdtree settings
let g:NERDTreeMouseMode = 2
let g:NERDTreeWinSize = 40
"explorer mappings
set <F1>=[[A
nnoremap <F1> :BufExplorer<CR>
set <F2>=[[B
nnoremap <F2> :NERDTreeToggle<CR>
set <F3>=[[C
nnoremap <F3> :TagbarToggle<CR>
"source project specific config files
"runtime! projects/**/*.vim
"dont load csapprox if we no gui support - silences an annoying warning
if !has("gui")
let g:CSApprox_loaded = 1
endif
"make <c-l> clear the highlight as well as redraw
nnoremap <C-L> :nohls<CR><C-L>
inoremap <C-L> <C-O>:nohls<CR>
"map Q to something useful
noremap Q gq
"make Y consistent with C and D
nnoremap Y y$
"visual search mappings
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
"jump to last cursor position when opening a file
"dont do it when writing a commit log entry
autocmd BufReadPost * call SetCursorPosition()
function! SetCursorPosition()
if &filetype !~ 'svn\|commit\c'
if line("'\"") > 0 && line("'\"") <= line("$")
exe "normal! g`\""
normal! zz
endif
end
endfunction
"spell check when writing commit logs
"autocmd filetype svn,*commit* setlocal spell
"http://vimcasts.org/episodes/fugitive-vim-browsing-the-git-object-database/
"hacks from above (the url, not jesus) to delete fugitive buffers when we
"leave them - otherwise the buffer list gets poluted
"
"add a mapping on .. to view parent tree
"autocmd BufReadPost fugitive://* set bufhidden=delete
"autocmd BufReadPost fugitive://*
" \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' |
" \ nnoremap <buffer> .. :edit %:h<CR> |
" \ endif
"
" YouCompleteMe options
"
let g:ycm_register_as_syntastic_checker = 1 "default 1
let g:Show_diagnostics_ui = 1 "default 1
"will put icons in Vim's gutter on lines that have a diagnostic set.
"Turning this off will also turn off the YcmErrorLine and YcmWarningLine
"highlighting
let g:ycm_enable_diagnostic_signs = 1
let g:ycm_enable_diagnostic_highlighting = 1
let g:ycm_always_populate_location_list = 1 "default 0
let g:ycm_open_loclist_on_ycm_diags = 1 "default 1
let g:ycm_complete_in_strings = 1 "default 1
let g:ycm_collect_identifiers_from_tags_files = 1 "default 0
let g:ycm_path_to_python_interpreter = '' "default ''
let g:ycm_server_use_vim_stdout = 0 "default 0 (logging to console)
let g:ycm_server_log_level = 'info' "default info
"let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' "where to search for .ycm_extra_conf.py if not found
"let g:ycm_confirm_extra_conf = 1
let g:ycm_goto_buffer_command = 'same-buffer' "[ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab' ]
let g:ycm_filetype_whitelist = { '*': 1 }
let g:ycm_key_invoke_completion = '<C-Space>'
let g:ycm_autoclose_preview_window_after_completion = 0
let g:ycm_autoclose_preview_window_after_insertion = 1
set <F11>=[23~
nnoremap <F11> :YcmForceCompileAndDiagnostics <CR>
nnoremap <leader>jd :YcmCompleter GoTo<CR>
nnoremap <leader>gt :YcmCompleter GetType<CR>
"YCM generator binding
set <F10>=[21~
nnoremap <F10> :YcmGenerateConfig<CR>
"Gundo mapping
set <F5>=[[E
nnoremap <F5> :GundoToggle<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment