vimrc 6.75 KB
Newer Older
1 2 3
set nocompatible
set ruler
set number
Murukesh Mohanan's avatar
Murukesh Mohanan committed
4
"set bg=dark
5 6 7 8 9 10 11 12 13 14 15 16

set incsearch
" This shows what you are typing as a command.  I love this!
set showcmd
" Who doesn't like autoindent?
set autoindent

" Needed for Syntax Highlighting and stuff
filetype on
filetype plugin on
filetype plugin indent on
syntax enable
17
set grepprg=grep\ -nH
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

" Spaces are better than a tab character
" set expandtab
set smarttab

" Who wants an 8 character tab?  Not me!
set tabstop=4
set shiftwidth=4
set softtabstop=4

" Cool tab completion stuff
set wildmenu
set wildmode=list:longest,full

set ignorecase
set smartcase
set incsearch
set hlsearch
set showmatch

set tags=tags;/
set wrap
set formatoptions=tcrql
set scrolloff=5               " keep at least 5 lines above/below
set sidescrolloff=5           " keep at least 5 lines left/right
set history=200
set backspace=indent,eol,start
set undolevels=1000           " 1000 undos
set updatecount=100           " switch every 100 chars
set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
set ttyfast                   " we have a fast terminal
49
set pastetoggle=<F10>
50
set title
51
set titlelen=20
52
set laststatus=2
53
set wildignore+=*.aux,*.toc,*.pdf
54
set isfname-==
Murukesh Mohanan's avatar
Murukesh Mohanan committed
55
set display+=lastline
56 57
set undofile
set undodir=$HOME/.vim/undo
Murukesh Mohanan's avatar
Murukesh Mohanan committed
58 59
set sessionoptions-=options
set sessionoptions+=winpos,winsize
Murukesh Mohanan's avatar
Murukesh Mohanan committed
60 61

let g:tex_flavor = "latex"
62

Murukesh Mohanan's avatar
Murukesh Mohanan committed
63 64 65 66 67 68
function! s:Help2Url (...)
	if winheight('%') < winwidth('%')
		exec 'silent! vert bo help ' . ( a:0 ? a:1 : '' )
	else
		exec 'silent! help ' . ( a:0 ? a:1 : '' )
	endif
Murukesh Mohanan's avatar
Murukesh Mohanan committed
69 70 71 72
	if ! a:0
		exec "normal \<c-T>"
	endif
	let l:tagfile = expand ('%:t')
73
	let @+ = expand ('<cword>')
Murukesh Mohanan's avatar
Murukesh Mohanan committed
74 75 76 77 78 79 80 81 82 83 84 85 86
	try
		python import urllib
		let @+ = pyeval ('urllib.quote_plus ("' . @+ . '")')
		let @+ = printf ('http://vimhelp.appspot.com/%s.html#%s', l:tagfile, @+)
	catch /^Vim\%((\a\+)\)\=:E887/
		try
			if has('python3')
				python3 import urllib.parse
				let @+ = py3eval ('urllib.parse.quote ("' . @+ . '")')
				let @+ = printf ('http://vimhelp.appspot.com/%s.html#%s', l:tagfile, @+)
			endif
		endtry
	endtry
Murukesh Mohanan's avatar
Murukesh Mohanan committed
87 88
endfunction

Murukesh Mohanan's avatar
Murukesh Mohanan committed
89
command! -nargs=? -complete=help H call s:Help2Url (<f-args>)
Murukesh Mohanan's avatar
Murukesh Mohanan committed
90

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
noremap    ;           :
noremap    ,           ;
nnoremap   <           :tabp<CR>
nnoremap   >           :tabn<CR>
noremap    <leader>,   :bp<CR>
noremap    <leader>.   :bn<CR>
command!   C           let @/=""
cnoremap   w!!         w !sudo tee >/dev/null %
noremap    <leader>P   "*p
noremap    <leader>p   "+p
noremap    <leader>Y   "*y
noremap    <leader>y   "+y
inoremap   <Down>      <C-o>gj
inoremap   <Up>        <C-o>gk
nnoremap   <Down>      gj
nnoremap   <Up>        gk
107

108 109 110 111 112
function! YCMInstallCmd()
	let l:ycm_cmd = 'python2 ./install.py'
	if executable('c++')
		let l:ycm_cmd .= ' --clang-completer'
	endif
Murukesh Mohanan's avatar
Murukesh Mohanan committed
113 114 115
	"if executable('go')
	"	let l:ycm_cmd .= ' --gocode-completer'
	"endif
116 117 118 119 120 121
	if executable('npm')
		let l:ycm_cmd .= ' --tern-completer'
	endif
	return l:ycm_cmd
endfunction

Murukesh Mohanan's avatar
Murukesh Mohanan committed
122
"execute pathogen#infect()
Murukesh Mohanan's avatar
Murukesh Mohanan committed
123
call plug#begin()
Murukesh Mohanan's avatar
Murukesh Mohanan committed
124
" Common plugins
Murukesh Mohanan's avatar
Murukesh Mohanan committed
125 126 127 128 129 130 131 132 133
Plug 'vim-scripts/diffchar.vim'
Plug 'scrooloose/nerdtree'
Plug 'ervandew/supertab'
Plug 'scrooloose/syntastic'
Plug 'tpope/vim-surround'
Plug 'bling/vim-airline'
Plug 'tpope/vim-fugitive'
Plug 'tomasr/molokai'
Plug 'ctrlpvim/ctrlp.vim'
Murukesh Mohanan's avatar
Murukesh Mohanan committed
134
Plug 'gabrielelana/vim-markdown', {'for': 'markdown'}
Murukesh Mohanan's avatar
Murukesh Mohanan committed
135
Plug 'majutsushi/tagbar', {'for': ['cpp', 'c', 'go', 'sh', 'javascript']}
Murukesh Mohanan's avatar
Murukesh Mohanan committed
136
Plug 'godlygeek/tabular'
Murukesh Mohanan's avatar
Murukesh Mohanan committed
137

138 139
if executable('cmake')
	" YCM command lifted from vim-plug readme
Murukesh Mohanan's avatar
Murukesh Mohanan committed
140
	Plug 'Valloric/YouCompleteMe', { 'do': YCMInstallCmd(), 'for': ['cpp', 'c', 'sh', 'javascript', 'vim', 'tex'] }
141 142
	autocmd! User YouCompleteMe if !has('vim_starting') | call youcompleteme#Enable() | endif
endif
Murukesh Mohanan's avatar
Murukesh Mohanan committed
143 144
if executable('go')
	Plug 'fatih/vim-go', {'for': 'go'}
Murukesh Mohanan's avatar
Murukesh Mohanan committed
145 146 147
	Plug 'Shougo/neocomplete.vim', {'for': 'go'}
	Plug 'Shougo/vimproc.vim', {'do': 'make'}
	Plug 'Shougo/echodoc.vim'
Murukesh Mohanan's avatar
Murukesh Mohanan committed
148 149 150 151 152 153 154 155 156 157 158
endif
if executable('latex')
	Plug 'lervag/vimtex', {'for': 'tex'}
endif
if executable('ghc')
	Plug 'dag/vim2hs', {'for': 'hs'}
endif
if executable('man')
	Plug 'murukeshm/vim-manpager'
endif
if executable('dpkg')
Murukesh Mohanan's avatar
Murukesh Mohanan committed
159
	Plug 'vim-scripts/deb.vim'
Murukesh Mohanan's avatar
Murukesh Mohanan committed
160 161
endif
if executable('logrotate')
Murukesh Mohanan's avatar
Murukesh Mohanan committed
162 163
	Plug 'moon-musick/vim-logrotate'
endif
Murukesh Mohanan's avatar
Murukesh Mohanan committed
164
call plug#end()
165

166 167 168 169 170 171 172
function! EnableYCM()
	call plug#load('YouCompleteMe')
	call youcompleteme#Enable()
endfunction

nnoremap <leader>ycm :call EnableYCM()<cr>

Murukesh Mohanan's avatar
Murukesh Mohanan committed
173
colorscheme molokai
174
highlight Normal  ctermbg=none
175
highlight NonText ctermbg=none
176
highlight Visual  ctermbg=DarkGrey
Murukesh Mohanan's avatar
Murukesh Mohanan committed
177
set cursorline
Murukesh Mohanan's avatar
Murukesh Mohanan committed
178

179
" From http://vi.stackexchange.com/questions/258/
180 181
autocmd BufWritePre  *.sh,*.py if !filereadable(expand('%')) | let b:is_new = 1 | endif
autocmd BufWritePost *.sh,*.py if get(b:, 'is_new', 0) | silent execute '!chmod +x %' | endif
182

Murukesh Mohanan's avatar
Murukesh Mohanan committed
183
let g:SuperTabDefaultCompletionType = "context"
184
let g:SuperTabClosePreviewOnPopupClose = 1
Murukesh Mohanan's avatar
Murukesh Mohanan committed
185
set omnifunc=syntaxcomplete#Complete
Murukesh Mohanan's avatar
Murukesh Mohanan committed
186
set foldmethod=syntax
Murukesh Mohanan's avatar
Murukesh Mohanan committed
187
let g:syntastic_cpp_compiler_options = ' -std=c++11'
188
let g:syntastic_python_python_exec = '/usr/bin/python3'
189
let g:airline#extensions#tabline#enabled = 0
190
let g:ctrlp_prompt_mappings = {
Murukesh Mohanan's avatar
Murukesh Mohanan committed
191 192 193
			\ 'AcceptSelection("e")': ['<c-t>'],
			\ 'AcceptSelection("t")': ['<cr>', '<2-LeftMouse>'],
			\ }
194 195
let g:ctrlp_max_depth = 40
let g:ctrlp_max_files = 10000
Murukesh Mohanan's avatar
Murukesh Mohanan committed
196
let g:ctrlp_custom_ignore = {
Murukesh Mohanan's avatar
sync  
Murukesh Mohanan committed
197
			\ 'dir': '\v[\/](plugged|undo|view|\.git|_site)$'
Murukesh Mohanan's avatar
Murukesh Mohanan committed
198
			\ }
Murukesh Mohanan's avatar
Murukesh Mohanan committed
199
let g:DiffColors = 100
200 201 202 203
let g:DiffUnit = "Word3"
let g:DiffUpdate = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_collect_identifiers_from_tags_files = 1
Murukesh Mohanan's avatar
Murukesh Mohanan committed
204
let g:ycm_seed_identifiers_with_syntax = 1
205
let g:ycm_python_binary_path = '/usr/bin/python3'
Murukesh Mohanan's avatar
Murukesh Mohanan committed
206 207 208 209 210
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
Murukesh Mohanan's avatar
Murukesh Mohanan committed
211

212
if empty($MAN_PN) && @% == "" && getcwd() == "/tmp"
Murukesh Mohanan's avatar
Murukesh Mohanan committed
213 214 215
	" From http://vi.stackexchange.com/questions/239/
	" with exception for reading manpages
	try
216 217 218 219
		silent find test.*
	catch /^Vim\%((\a\+)\)\=:E345/
		silent edit test.sh
	endtry
220 221
endif

222 223
" From http://vi.stackexchange.com/questions/2009/
function! FindInPath(name)
Murukesh Mohanan's avatar
Murukesh Mohanan committed
224
	" Force creation of new file for paths beginning with ./
225
	if expand('%') !~ '^[.~]\?/'
Murukesh Mohanan's avatar
Murukesh Mohanan committed
226
		try
Murukesh Mohanan's avatar
Murukesh Mohanan committed
227 228 229 230 231 232 233 234 235 236 237 238
			let path=&path
			" Add any extra directories to the normal search path
			set path+=~,~/.vim,/etc
			" If :find finds a file, then wipeout the buffer that was created for the "new" file
			setlocal bufhidden=wipe
			exe 'silent keepalt find! '. fnameescape(expand('<afile>'))
			" Restore 'path' and 'bufhidden' to their normal values
			let &path=path
			set bufhidden<
		catch /^Vim\%((\a\+)\)\=:E345/
			return 0
		endtry
Murukesh Mohanan's avatar
Murukesh Mohanan committed
239
	endif
240 241 242 243 244 245 246
endfunction
autocmd BufNewFile * nested call FindInPath(expand('<afile>'))

"au VimEnter * tab all | tabfirst

" From http://vi.stackexchange.com/questions/2358/
autocmd FileType * exec("setlocal dictionary+=".$HOME."/.vim/dictionary/".expand('<amatch>'))
247 248 249 250
set completeopt+=menuone
if has('patch-7.4-775')
	set completeopt+=noinsert
endif
251
set complete+=k
Murukesh Mohanan's avatar
Murukesh Mohanan committed
252

Murukesh Mohanan's avatar
Murukesh Mohanan committed
253
runtime local/$CONFLOCAL.vim