summaryrefslogtreecommitdiffstats
path: root/dotvimrc
blob: e77a53b09d0de0e78bdd723cb5561503a3875c58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
set nocompatible
syn on
set ignorecase
set smartcase
set modeline
set modelines=5
set wildmode=longest:full
set wildmenu
set hlsearch
set pastetoggle=<F10>
set tw=0
set backspace=eol,indent,start
set number
"set mouse=a "Disabled
"set grepprg=grep\ -nH\ $*
set grepprg=rg\ --vimgrep\ $*
let g:tex_flavor = "latex"

setglobal formatoptions+=j

" so that :find and :tabfind work
set path=$PWD/**

" in visual mode, show count
set showcmd
set scrolloff=3

" persistent-undo
set undodir=~/.vim/undodir
set undofile

set runtimepath+=~/.vim/bundle/neobundle.vim/

" remove toolbar
set guioptions-=T
" remove menu
set guioptions-=m

set formatoptions+=j " Delete comment character when joining commented lines

set history=1000

set tabpagemax=50

let mapleader="\<Space>"

"if has("autocmd") && exists("+omnifunc")
	"autocmd Filetype *
	"\   if &omnifunc == "" |
	"\     setlocal omnifunc=syntaxcomplete#Complete |
	"\   endif
"endif

call neobundle#begin(expand('~/.vim/bundle/'))

" Let NeoBundle manage NeoBundle
NeoBundleFetch 'Shougo/neobundle.vim'

" Recommended to install
" After install, turn shell ~/.vim/bundle/vimproc, (n,g)make -f your_machines_makefile
"NeoBundle 'Shougo/vimproc'

"NeoBundle 'https://github.com/CoatiSoftware/vim-coati'
"nnoremap <leader>as :CoatiRefresh<CR>
"nnoremap <leader>aa :CoatiActivateToken<CR>

"NeoBundle 'elixir-lang/vim-elixir'

NeoBundle 'mileszs/ack.vim.git'
let g:ackprg = "rg"
let g:ack_default_options = " --vimgrep"
noremap <Leader>a :Ack! --vimgrep -t cpp -t c -t py <cword><CR>
noremap <Leader>A :Ack! --vimgrep <cword><CR>

NeoBundle 'tpope/vim-fugitive'

"Show + - ~ in the margin for vim modification
NeoBundle "airblade/vim-gitgutter"
let g:gitgutter_eager = 0 " only update on read/write


NeoBundle 'kien/ctrlp.vim' "amazing search with ctrl p

NeoBundle 'JazzCore/ctrlp-cmatcher'
let g:ctrlp_match_func = {'match' : 'matcher#cmatch' }

" Also search tags
let g:ctrlp_extensions = ['tag']
noremap <Leader>p :CtrlP<CR>
noremap <Leader>b :CtrlPBuffer<CR>

"let g:ctrlp_working_path_mode = 'a'

" Ignore some folders and files for CtrlP indexing
let g:ctrlp_custom_ignore = { 'dir':  '\.git$\|\CODENAME_Data' }

NeoBundle 'git-time-lapse'

NeoBundle 'Valloric/YouCompleteMe.git'
let g:ycm_extra_conf_globlist = ['~/dab/*', '~/*']
let g:ycm_always_populate_location_list = 1
noremap <Leader>y :YcmDiags<CR>
noremap <Leader>Y :YcmRestartServer<CR>
noremap <Leader>F :YcmCompleter FixIt<CR>:ccl<CR>

NeoBundle 'tpope/vim-surround.git'
NeoBundle 'taglist.vim'
NeoBundle 'majutsushi/tagbar'
noremap <Leader>t :TagbarToggle<CR>
NeoBundle 'ifdef-highlighting'
NeoBundle 'ciaranm/detectindent' "adapts tabstop and this shit automagically

NeoBundle "scrooloose/nerdtree"

" Nice tabulation
NeoBundle 'godlygeek/tabular'
"http://vimcasts.org/episodes/aligning-text-with-tabular-vim/

let g:Powerline_symbols = 'unicode'

NeoBundle 'Tag-Signature-Balloons'

function! ToggleFullScreen()
    call system("wmctrl -i -r ".v:windowid." -b toggle,fullscreen")
    redraw
endfunction

colorscheme bramwombat

if has("nvim")
    set termguicolors
    set cursorline
    set noincsearch
elseif has("gui_running")

    if has("gui_gtk2")
        set guifont="Source Code Pro Medium 12"
    elseif has("gui_win32")
        set guifont=Lucida_Console:h10:cANSI
    endif

    nnoremap <Leader><F11> :call ToggleFullScreen()<CR>

    set cursorline
else
    set t_Co=256
endif

"set a sudo vim
cmap w!! w !sudo tee % > /dev/null

hi scalaNew gui=underline
hi scalaMethodCall gui=italic
hi scalaValName gui=underline
hi scalaVarName gui=underline
"folding
set foldcolumn=2
set foldmethod=marker

" tabs are 4 space by default
set shiftwidth=4
set tabstop=4
set expandtab

"What highlighting group is the current cursor on ?
function! SyntaxItem()
  return synIDattr(synID(line("."),col("."),1),"name")
endfunction

"Nice statusbar
set laststatus=2
set statusline=
set statusline+=%-3.3n\                             " buffer number
set statusline+=%f\                                 " file name
set statusline+=%h%m%r%w                            " flags
set statusline+=\[%{strlen(&ft)?&ft:'none'},        " filetype
set statusline+=%{&fileencoding},                   " encoding
set statusline+=%{&fileformat},                     " file format
set statusline+=%{((exists(\"+bomb\")\ &&\ &bomb)?\"B,\":\"\")}]\  " BOM
set statusline+=%{strftime('%a\ %b\ %e\ %H:%M')}\   " hour
"set statusline+=%{SyntaxItem()}                     " syntax highlight group under cursor
set statusline+=%=                                  " right align
if !empty(glob("bundle/vim-fugitive/plugin/fugitive.vim"))
  set statusline+=%{fugitive#statusline()}\           " git branch
endif
set statusline+=0x%-8B\                             " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P               " offset

"tags
set tags=tags,./tags,../tags,../../tags

"C syntax for ellisys files
autocmd BufNewFile,BufRead *.usbs set filetype=c

"C syntax for ARM Scatterfiles
autocmd BufNewFile,BufRead *.scat set filetype=c

"ARM Assembler for .s files
autocmd BufNewFile,BufRead *.s set filetype=armasm

"Markdown, not modula2
autocmd BufNewFile,BufRead *.md set filetype=markdown

set nostartofline

"Leader-f switches from C source .c to header .h file
"It automatically detects .cpp <-> .h
"                         .c   <-> .h
"                         .cpp <-> .hpp
function! MPB_Flip_Ext()
python << endpython
import vim
import os.path

def loadfile(filename):
    vim.command("e {}".format(filename))

currentfile = vim.eval('expand("%")')

c_exts = ["c", "cpp", "cc"]
h_exts = ["h", "hpp"]

currentfile_split = currentfile.split(".")
if len(currentfile_split) > 0:
    ext = currentfile_split[-1]
    basename = currentfile[:-(1+len(ext))]

    if ext in c_exts:
        for h_ext in h_exts:
            h_filename = basename + "." + h_ext
            if os.path.exists(h_filename):
                loadfile(h_filename)
    elif ext in h_exts:
        for c_ext in c_exts:
            c_filename = basename + "." + c_ext
            if os.path.exists(c_filename):
                loadfile(c_filename)
endpython
endfun

noremap <F4> :call MPB_Flip_Ext()<CR>
noremap <Leader>f :call MPB_Flip_Ext()<CR>

noremap <Leader>m :make -j4<CR>

"Show trailing whitespace
highlight ExtraWhitespace ctermbg=darkgreen guibg=#344011
autocmd BufEnter * exe ':2match ExtraWhitespace /\s\+$\| \+\ze\t\|\t\+\ze /'

" F5 sets the search register to the word under cursor, without moving
" the cursor
noremap <F5> :let @/ = expand('<cword>')<CR>:3match none<CR>

" F6: Highlight the word under cursor in darkcyan
highlight ManualHighlight ctermbg=darkcyan guibg=darkcyan
noremap <F6> :exe printf('match ManualHighlight /%s/', escape(expand('<cword>'), '/\'))<CR>

"if has("gui_running")
"    " auto highlight word under cursor
"    highlight WordUnderCursor ctermbg=darkred guibg=#552211
"    autocmd CursorMoved * exe printf('3match WordUnderCursor /\V\<%s\>/', escape(expand('<cword>'), '/\'))
"endif

"Show tabs
set listchars=tab:›\ ,trail:␣
set list

"clang_complete options
set completeopt=menu,menuone,longest
"let g:clang_complete_copen=1

"some CScope maps
noremap <Leader>fs :cscope f s <cword><Enter>

if has("cscope")
    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
        " else add database pointed to by environment
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
endif

"short tag and tselect
noremap <Leader>[ :tselect <C-r><C-w><CR>
noremap <Leader>] :tag <C-r><C-w><CR>

"I use bnext and bprev a lot
noremap [b :bprev<CR>
noremap ]b :bnext<CR>

"Same for location list
noremap [l :lprev<CR>
noremap ]l :lnext<CR>

"Error list
noremap [e :cNext<CR>
noremap ]e :cnext<CR>

noremap [h :GitGutterPrevHunk<CR>
noremap ]h :GitGutterNextHunk<CR>

"GIT stuff
noremap <Leader>gt :call TimeLapse()<cr>
noremap <Leader>gb :Gblame<cr>

noremap <Leader>e :NERDTreeToggle<CR>

noremap <Leader>T :set expandtab!<CR>

" Vim. Live it.
noremap <up> <nop>
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
inoremap <up> <nop>

"very magic search
noremap <Leader>/ /\v

call neobundle#end()

filetype plugin indent on

NeoBundleCheck