-
Notifications
You must be signed in to change notification settings - Fork 4
/
.vimrc
executable file
·406 lines (340 loc) · 16 KB
/
.vimrc
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
" ------------------------------------------------------------------------------------
" Vim configuration file
" Author : Ronan Guilloux
" Copyright : 2011, Ronan GUILLOUX
" Licence : GNU Affero GPL v3 - http://www.gnu.org/licenses/agpl-3.0.txt
" Provided as is, without warranty of any kind
" Available on https://github.com/ronanguilloux/dotfiles
" ------------------------------------------------------------------------------------
" ------------------------------------------------------------------------------------
" Source local settings
" ------------------------------------------------------------------------------------
if filereadable("~/.vimlocalrc")
source ~/.vimlocalrc
endif
" Use pathogen to easily modify the runtime path to include all
" " plugins under the ~/.vim/bundle directory
call pathogen#helptags()
"call pathogen#runtime_append_all_bundles()
call pathogen#incubate()
" All PHP, Js, md, HTML, CSS, Symfony, Golang vim config & enhancements
" are in .vim/after/ftplugin/*.vim files
" ------------------------------------------------------------------------------------
" Basics
" ------------------------------------------------------------------------------------
if has("syntax")
syntax on
endif
let mapleader="," " the leader character
set shortmess=atI " no more “Press ENTER or type command to continue”
set nocompatible " explicitly get out of vi-compatible mode
set noerrorbells " do not make any noise!
set visualbell " use the visual bell
set number " precede each line with its line number
set mouse=a " normal+visual+insert+command-line modes for mouse
set showcmd " show the command being typed
set showmode " show the mode we are in
set omnifunc=syntaxcomplete#Complete
set ruler " display current mouse position
set ttyfast " we use a rapid terminal
set history=1000 " increase history
set nobackup " do not backup files on overwrite
set undolevels=1000 " use many levels of undo
set noundofile " don't keep a persistent undofile
"set title " display the default title at the top of the window
set completeopt=longest,menu
set wildmenu " long autocompletion shrowing various solutions
set wildmode=list:longest " make it longest
set wildignore=*.o,*.fasl,*.obj,*.bak,*.exe,*.pyc,*.jpg,*.gif,*.png " ignoring this
set clipboard+=unnamed " share windows clipboard
set fileformats=unix,dos,mac " support all three, in this order
set shell=/bin/bash
set scrolloff=3 " cursor start the scrolling three lines before the bottom border
set lazyredraw " redraw only when we need to.
" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vimrc
" Run NERDTree on load
autocmd vimenter * NERDTree
" How can I close vim if the only window left open is a NERDTree?
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
let NERDTreeShowHidden=1
" ------------------------------------------------------------------------------------
" Gvim conf
" ------------------------------------------------------------------------------------
if has('gui_running')
set guifont=Monaco\ Bold\ 10
endif
" ------------------------------------------------------------------------------------
" Colorscheme solarized - https://github.com/altercation/vim-colors-solarized
" ------------------------------------------------------------------------------------
"let g:solarized_termcolors = 256
let g:solarized_termtrans = 0
let g:solarized_degrade = 0
let g:solarized_bold = 0
let g:solarized_underline = 1
let g:solarized_italic = 1
let g:solarized_contrast = "normal"
let g:solarized_visibility = "normal"
syntax enable
set background=dark
"colorscheme solarized
colorscheme slate
" option name default optional
" ------------------------------------------------
" ------------------------------------------------------------------------------------
" Status line
" ------------------------------------------------------------------------------------
set laststatus=2 " status bar : only if there are at least two windows
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ %r%{CurDir()}%h\ \ \ Line:\ %l/%L\ \ Col:%c%V\ \ Doc:%P\ (%{&encoding})
"set statusline=%<%F%h%m%r%h%w%y[%{CurDir()}%h]\ %{strftime(\"%c\",getftime(expand(\"%:p\")))}%=\ line:%l\/%L\ col:%c%V\ pos:%o\ %P
" ------------------------------------------------------------------------------------
" Folding
" ------------------------------------------------------------------------------------
" set foldmarker={,} " Fold C style code (only use this as default if you use a high foldlevel)
set nofoldenable " Turn off folding
"set foldmethod=marker " Fold on the marker
set foldlevel=100 " Don't autofold anything (but I can still fold manually)
"set foldopen=block,hor,mark,percent,quickfix,tag " what movements open folds
"function SimpleFoldText()
" return getline(v:foldstart).' '
"endfunction
"set foldtext=SimpleFoldText() " Custom fold text function (cleaner than default)
let g:vim_markdown_folding_disabled=1
" ------------------------------------------------------------------------------------
" Filetype : enable loading the plugins + indent file for specific file types
" ------------------------------------------------------------------------------------
if has("autocmd")
filetype plugin indent on
endif
" ------------------------------------------------------------------------------------
" Invisible character
" ------------------------------------------------------------------------------------
nmap <leader>l :set list!<CR>
set listchars=nbsp:¤,tab:>-,trail:¤,extends:>,precedes:<,eol:¬,trail:·
" ------------------------------------------------------------------------------------
" Highlight current line
" ------------------------------------------------------------------------------------
set cursorline
hi CursorLine term=underline cterm=underline
" ------------------------------------------------------------------------------------
" Highlight & remove trailing whitespaces
" ------------------------------------------------------------------------------------
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" ------------------------------------------------------------------------------------
" Automatically remove trailing whitespace before write
" ------------------------------------------------------------------------------------
function! StripTrailingWhitespace()
normal mZ
%s/\s\+$//e
if line("'Z") != line(".")
echo "Stripped whitespace\n"
endif
normal `Z
endfunction
" don't include .md below, empty spaces are parsed by markdown
autocmd BufWritePre *.txt,*.twig,*.php,*.yml,*.xml,*.js,*.html,*.css,*.java,*.c,*.cpp,*.vim :call StripTrailingWhitespace()
" ------------------------------------------------------------------------------------
" Swapping
" ------------------------------------------------------------------------------------
set backupdir=~/.vim/tmp/,~/.tmp,~/tmp,/var/tmp,/tmp " Keep swap files in one location
set directory=~/.vim/tmp/,~/.tmp,~/tmp,/var/tmp,/tmp " Keep swap files in one location
" ------------------------------------------------------------------------------------
" Editing
" ------------------------------------------------------------------------------------
set ff=unix " unix EOL
set fileencoding=UTF-8 " speak UTF-8
set encoding=UTF-8 " display UTF-8
set autowrite " write the contents of the file, if it has been modified (:next, :make),
set showmatch " show matching (){}[]
set mat=2 " how many tenths of a second to blink
set autoread " if current file is modified by another IDE, vim will refresh it
set listchars=tab:>-,trail:- " show tabs and trailing
set report=0 " tell us when anything is changed via :...
set gfn=Monospace\ 10
set wrap " wrap lines
" C-c and C-v - Copy/Paste :
vmap <C-C> "+yi
imap <C-V> <esc>"+gPi
map <S-Insert> <MiddleMouse>
" ------------------------------------------------------------------------------------
" Indentation
" ------------------------------------------------------------------------------------
"set smartindent
set autoindent
set copyindent " copy the previous indentation on autoindenting
set shiftround "round to a multiple of our tab setting
"set cindent " C-like indentation
" ------------------------------------------------------------------------------------
" Tabs Versus Spaces : any tab char become 4 space chars
" ------------------------------------------------------------------------------------
set tabstop=4 " number of spaces that a <Tab> in the file counts for.
set shiftwidth=4 " number of spaces to use for each step of (auto)indent.
set expandtab " in Insert mode: Use the appropriate number of spaces to insert a <Tab>
set smarttab
set softtabstop=4 "softtab value, 4 spaces
set backspace=indent,eol,start
" ------------------------------------------------------------------------------------
" Search options
" ------------------------------------------------------------------------------------
" Enable folding by indentation
" Use: zc, zo, zC, zO, zR, zM
" Ctrl-K .3 for ⋯
" set foldmethod=indent
highlight Folded ctermfg=red
highlight FoldColumn ctermfg=white
set fillchars=fold:⋯
" ------------------------------------------------------------------------------------
" Search options
" ------------------------------------------------------------------------------------
set wrapscan " make search wrap around
set hlsearch " when there is a previous search pattern, highlight all its matches
set incsearch " enable incremental search
set ignorecase " search is case insensitive
set smartcase " search becomes case sensitive if expression contains uppercase character
" Clear search highlight :
nmap <silent> <leader>/ :let @/=""<cr>
" ------------------------------------------------------------------------------------
" SnipMate
" ------------------------------------------------------------------------------------
ino <c-j> <c-r>=TriggerSnippet()<cr>
snor <c-j> <esc>i<right><c-r>=TriggerSnippet()<cr>
" ------------------------------------------------------------------------------------
" TEMPLATES
" ------------------------------------------------------------------------------------
"autocmd bufNewFile *.html 0r ~/.vim/templates/html
" See vim-templates bundle
" ------------------------------------------------------------------------------------
" Zencoding
" ------------------------------------------------------------------------------------
"autocmd bufNewFile *.html 0r ~/.vim/templates/html
" See vim-templates bundle
"let g:user_zen_mode='n' "only enable normal mode functions.
"let g:user_zen_mode='inv' "enable all functions, which is equal to
"let g:user_zen_mode='a' "enable all function in all mode.
"let g:user_zen_expandabbr_key = '<C-e>'
let g:use_zen_complete_tag = 1
" ------------------------------------------------------------------------------------
" CTAGS
" ------------------------------------------------------------------------------------
" Cf. http://goo.gl/P6AAT
" MAC OS X: http://goo.gl/U9AnWq
set tags=tags;/ " Look in the current directory for "tags", towards $HOME, until one is found
let Tlist_Use_Right_Window=1
"let Tlist_Auto_Open=1
let Tlist_Show_One_File=0 " 1 = Only show tags for current buffer
let Tlist_Enable_Fold_Column=0 " no fold column (only showing one file)
let Tlist_Compact_Format=0
let Tlist_WinWidth=28
let Tlist_Exit_OnlyWindow=1
let Tlist_File_Fold_Auto_Close = 1
"let Tlist_Process_File_Always = 1
"let Tlist_GainFocus_On_ToggleOpen = 1 " set focus on Tlist at start
let Tlist_Ctags_Cmd = "ctags"
map <F4> :TlistToggle<cr>
map <F8> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
" Alt-right/left to navigate forward/backward in the tags stack
map <M-Left> <C-T>
map <M-Right> <C-]>
" Explore tags for the word under the cursor
map <C-l> <C-]>
" Back to previous location after browsing tags
map <C-h> <C-T>
" Jump to next tag match
map ]t :tnext<CR>
" Jump to previous tag match
map [t :tprevious<CR>
" GUARD file
set tags+=vendor.tags
" ------------------------------------------------------------------------------------
" TABS (buffer tabs)
" ------------------------------------------------------------------------------------
" Always display tab label
" Tip : using visual mode, this allows double click to add a new tab in the tab line
set showtabline=2
" Tabs key bindings: movements commands
" [Ctrl]+T plus a directional arrow
"map ,t :tabnew<cr>
map ,w :tabclose<cr>
" Tab mappings.
map <leader>tt :tabnew<cr>
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>to :tabonly<cr>
map <leader>tn :tabnext<cr>
map <leader>tp :tabprevious<cr>
map <leader>tf :tabfirst<cr>
map <leader>tl :tablast<cr>
map <leader>tm :tabmove
" Improving tab name readability
highlight TabLine term=none cterm=none
highlight TabLineSel ctermbg=darkblue
"set rtp+=/home/ronan/dotfiles/.vim/bundle/powerline/powerline/bindings/vim
" ------------------------------------------------------------------------------------
" Keybord shortcuts
" ------------------------------------------------------------------------------------
" Selct all
map <C-a> ggVG
" Copy (le gv c'est pour remettre la sélection)
map <C-c> "+ygv
" Cut
map <C-x> "+x
" Past
map <C-p> "+gP
" ------------------------------------------------------------------------------------
" Vim 7 spell checker
" ------------------------------------------------------------------------------------
if has("spell")
" Language : FR
map ,lf :setlocal spell spelllang=fr<cr>
" Language : EN
map ,le :setlocal spell spelllang=en<cr>
" Language : Aucun
map ,ln :setlocal spell spelllang=<cr>
endif
set spellsuggest=5
autocmd BufEnter *.txt set spell
" autocmd BufEnter *.txt set spelllang=fr
autocmd BufEnter *.txt set spelllang= " no default lang
set nospell
" ------------------------------------------------------------------------------------
" Vim Templates
" ------------------------------------------------------------------------------------
augroup templates
au!
" read in template files
autocmd BufNewFile *.* silent! execute '0r $HOME/vimfiles/templates/skeleton.'.expand("<afile>:e")
" parse special text in the templates after the read
autocmd BufNewFile * %substitute#\[:VIM_EVAL:\]\(.\{-\}\)\[:END_EVAL:\]#\=eval(submatch(1))#ge
augroup END
" ------------------------------------------------------------------------------------
" Vim Functions
" ------------------------------------------------------------------------------------
" CleanCode function,
" thanks to @ornicar
function! CleanCode()
%retab " Replace tabs with spaces
%s/\r/\r/eg " Turn DOS returns ^M into real returns
%s= *$==e " Delete end of line blanks
echo "Cleaned up this mess."
endfunction
nmap <leader>cc :call CleanCode()<cr>
function! CurDir()
let curdir = substitute(getcwd(), '/home/ronan/', "~/", "g")
return curdir
endfunction
function! HasPaste()
if &paste
return 'PASTE MODE '
else
return ''
endif
endfunction
" ------------------------------------------------------------------------------------
" GIT Messages
" ------------------------------------------------------------------------------------
autocmd Filetype gitcommit spell textwidth=72