aboutsummaryrefslogtreecommitdiff
path: root/config/vim/vimrc
blob: 6822f788374fca6cba97bbc644f23678edd516af (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
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
" xdg {{{
set runtimepath^=$XDG_CONFIG_HOME/vim
set runtimepath+=$XDG_DATA_HOME/vim
set runtimepath+=$XDG_CONFIG_HOME/vim/after

set packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim
set packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after

let g:netrw_home = $XDG_DATA_HOME . '/vim'
call mkdir($XDG_DATA_HOME . '/vim/spell', 'p')
set viewdir=$XDG_DATA_HOME/vim/view | call mkdir(&viewdir, 'p')

set backupdir=$XDG_CACHE_HOME/vim/backup | call mkdir(&backupdir, 'p')
set directory=$XDG_CACHE_HOME/vim/swap   | call mkdir(&directory, 'p')
set undodir=$XDG_CACHE_HOME/vim/undo     | call mkdir(&undodir,   'p')
" }}}

source $XDG_CONFIG_HOME/vim/pluggins.vim  " load pluggins

" common {{{
let mapleader = ' '         " set leader key to space
let maplocalleader = '-'    " set file local leader key to backslash
" vint: -ProhibitSetNoCompatible
set nocompatible            " not compatible with vi
set number                  " line number
" set relativenumber          " line number relative to cursor
set numberwidth=1           " line numbers gutter autowidth
set cursorline              " highlight current line
set noshowmatch             " dont jump to pair bracket
set autoread                " reload files when changes happen outside vim
set autowrite               " auto write buf on certain events
set hidden                  " keep change in buffer when quitting window
set noswapfile              " disable swap files
set scrolloff=2             " line padding when scrolling
set textwidth=0             " when line wrap occurs
set wrapmargin=0            " disable auto line wrapping
set encoding=utf-8          " utf-8 encoding
scriptencoding utf-8
set formatoptions-=t        " do not auto break line > 89 character
filetype plugin indent on   " allow to add specific rules for certain type of file
" set mouse=a                 " mouse scrolling (heretic)
set shellredir=>            " don't inclue stderr when reading a command
" }}}

" browse list with tab {{{
set wildmode=longest,list,full
set wildmenu                " tab to cycle through completion options
set path+=**                " recursive :find
" }}}

" intuitif split opening {{{
set splitbelow
set splitright
set fillchars+=vert:│       " split separator
" }}}

" tab {{{
set expandtab               " tab to space
set tabstop=4               " tab size
set shiftwidth=4
set smarttab
set autoindent
set smartindent
" }}}

" file search {{{
set ignorecase              " case insensitive
set smartcase
set hlsearch                " match highlight
set incsearch
" }}}

" status {{{
set laststatus=2            " always a statusline (all window)
set showcmd                 " show current partial command in the bottom right
set noshowmode              " dont show current mode (i.e --INSERT--)
" }}}

" fold {{{
set foldmethod=indent       " create fold based on the text indent
set nofoldenable            " not folded by default
" }}}

"""""""""""""""
" colorscheme "
"""""""""""""""

set background=dark
" one {{{
" let g:onedark_terminal_italics=1
" colorscheme onedark
" }}}
" dracula {{{
" let g:dracula_bold = 1
" let g:dracula_italic = 1
" let g:dracula_colorterm = 0
" silent! colorscheme dracula
" }}}
" solarized {{{
" set t_Co=16
" let g:solarized_termcolors=16
" let g:solarized_visibility='low'  " visibility of invisible chars with set list
" silent! colorscheme solarized
" }}}

let g:gruvbox_italic=1
let g:gruvbox_bold=1
let g:gruvbox_termcolors=256
let g:gruvbox_contrast_dark='medium'
let g:gruvbox_contrast_light='hard'
let g:gruvbox_invert_selection=0
colorscheme gruvbox

" lightline {{{
let g:lightline = {}
" let g:lightline.colorscheme = 'solarized'  " lightline theme to solarized
" let g:lightline.colorscheme = 'jellybeans'  " lightline theme to onedark
let g:lightline = {
      \ 'colorscheme': 'gruvbox',
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
      \ },
      \ 'component_function': {
      \   'gitbranch': 'FugitiveHead'
      \ },
      \ }
" }}}

""""""""""""
" mappings "
""""""""""""

" split navigation {{{
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" nnoremap <C-S-J> <C-W><S-J>
" nnoremap <C-S-K> <C-W><S-K>
" nnoremap <C-S-L> <C-W><S-L>
" nnoremap <C-S-H> <C-W><S-H>
nnoremap <leader>s= <C-W>=
" }}}

" common {{{
" 'Y' yank to the end of the line
noremap Y y$
" solves annoying delay went exiting insert mode
inoremap <ESC> <C-C>
" kj to exit insert mode
inoremap kj <ESC>
" remove visual mode keybinding
noremap Q <nop>
" search with very magic
nnoremap / /\v
nnoremap ? ?\v
" move line up and down
nnoremap _ ddkP
nnoremap + ddp
" long move up/down
nnoremap ( 10k
nnoremap ) 10j
" tag nagigation
nnoremap <leader>] <C-]>
nnoremap <leader>t <C-t>
" common change until
nnoremap cu ct_
nnoremap cp ct)
nnoremap c, ct,
" }}}

" buffer navigation {{{
nnoremap <leader>bn :bn<CR>
nnoremap <leader>bp :bp<CR>
nnoremap <leader><TAB> :b#<CR>
nnoremap <leader>bl :ls<CR>
" }}}

nnoremap <leader>sc :source $MYVIMRC<cr>  " source vimrc

" c {{{
" create c function body from prototype
nnoremap gcf A<BS><CR>{<CR><CR>}<ESC>j

" initialise a school header file
function PutHeaderBoilerPlate()
    let l:filename = join(split(toupper(expand('%:t')), '\.'), '_')
    " echom l:filename
    call append(12, '#ifndef ' . l:filename)
    call append(13, '# define ' . l:filename)
    call append(15, '#endif')
endfunction
nnoremap gch :Stdheader<CR>:call PutHeaderBoilerPlate()<CR>

" put semicolon at the end of line
nnoremap <leader>; mqA;<ESC>`q
" }}}

" cpp {{{
" Put Coplien Form boilerplate class
function PutCoplienFormFunc(name)
    let l:default_constructor = a:name . '();\n'
    let l:copy_constructor    = a:name . '(const ' . a:name . '& other);\n'
    let l:copy_operator       = a:name . '& operator=(const ' . a:name . '& other);\n'
    let l:destructor          = '~' . a:name . '();\n'

    execute 'normal iclass ' . a:name . '\n{\npublic:\n' . l:default_constructor . l:copy_constructor . l:copy_operator . l:destructor . '\nprivate:\n};\n'
    execute 'normal <2{'
endfunction
" Put Coplien Form boilerplate according to filename
command! PutCoplienFormFile call PutCoplienFormFunc(split(expand('%:t'), '\.')[0])
command! -nargs=1 PutCoplienForm call PutCoplienFormFunc("<args>")
" }}}

" quickfix window toggle {{{
nnoremap <leader>q :call QuickfixToggle()<CR>
nnoremap <leader>n :cnext <CR>
nnoremap <leader>p :cprevious <CR>
let g:quickfix_is_open = 0
function! QuickfixToggle()
    if g:quickfix_is_open
        cclose
        let g:quickfix_is_open = 0
    else
        copen
        let g:quickfix_is_open = 1
    endif
endfunction
" }}}

function! CountScopeLines()
    normal! mq
    execute '/^}'
    let l:end_brace = line('.')
    execute '?^{'
    let l:start_brace = line('.')
    normal! k
    let l:scope_len = l:end_brace - l:start_brace - 1
    let l:scope_name = substitute(getline('.'), '\t', ' ', 'g')
    echom l:scope_len . ' lines in |' . l:scope_name . '|'
    normal! `q
endfunction
command! CountScopeLines call CountScopeLines()

" make {{{
nnoremap <leader>m :make all <CR>
" }}}

augroup vimrc
    autocmd!
augroup END

" hook {{{
" remove trailing white space on save
autocmd vimrc BufWritePre * %s/\s\+$//e
" dirty hack to disable this feature on markdown (autocmd! wouldn't work)
autocmd vimrc BufReadPre *.md autocmd! BufWritePre
" }}}

" filetype {{{
" real tab in c file for school projects
let g:c_syntax_for_h = 1   " filetype=c in header files instead of filetype=cpp

augroup vimrc_files
    autocmd!
    " school c
    autocmd Filetype c setlocal noexpandtab
    autocmd Filetype c setlocal comments=s:/**,m:**,e:*/,s:/*,m:**,e:*/
    autocmd Filetype c setlocal equalprg=clang-format
    " std::cout << ... << std::endl; shortcut
    autocmd Filetype cpp nnoremap <leader>cout istd::cout <<  << std::endl;<ESC>2F<hi
    autocmd Filetype vim setlocal foldmethod=marker " vim fold method to marker
    autocmd FileType haskell setlocal formatprg=stylish-haskell
    autocmd FileType lisp,html,css,htmldjango setlocal shiftwidth=2
    autocmd Filetype markdown nnoremap <leader>r :execute 'silent !pandoc % -o %:r.pdf &' \| redraw! \| echom 'Converting to pdf: ' . expand('%:r') . '.pdf'<CR>
    autocmd Filetype markdown setlocal textwidth=80
augroup END
" }}}

""""""""""""
" pluggins "
""""""""""""

" directory to ignore when searching in file tree
set wildignore=*/doc/*,*/tmp/*,*.o,*.so,*.a,*.swp,*.zip,*/node_modules/*,*/vendor/*,.bundle/*,bin/*,.git/*,*.pyc

" ctrlp {{{
" ctrlp ignore all stuff in the .gitignore
" let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
" let g:ctrlp_working_path_mode = 'rw'
" let g:ctrlp_mruf_case_sensitive = 0
"
" nnoremap <leader>p :CtrlPTag<CR>
" }}}

" fzf.vim {{{
nnoremap <C-p> :GFiles --exclude-standard --others --cached<CR>
nnoremap <leader>p :Tags<CR>
" }}}

" quick-scope {{{
" let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" }}}

" man-plugin {{{
" runtime! ftplugin/man.vim
" let g:ft_man_open_mode = 'vert'    " open in a vertical split
" let g:ft_man_no_sect_fallback = 2  " if page specified fallback to page 2 (syscall pages)
" autocmd Filetype man unmap <buffer> q:  hmmmm??
" }}}

" eazy-align {{{
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
" }}}

vnoremap <leader>c y:call system("xclip -selection clipboard", getreg("\""))<CR>
nnoremap <leader>v :call setreg("\"", system("xclip -selection clipboard -o"))<CR>p

let g:c_formatter_42_format_on_save = 0

let g:gutentags_ctags_exclude = ['doc/*', 'docs/*', 'Makefile', '.mypy_cache', '.pytest_cache', '.tox', 'build/*', 'dist/*']
" let g:gutentags_ctags_exclude_wildignore = 1

let g:goyo_height = 90
let g:goyo_width = 100

set viminfo+=n$XDG_CACHE_HOME/vim/viminfo

let g:python_highlight_all = 1

nnoremap <leader>l :SidewaysRight<CR>
nnoremap <leader>h :SidewaysLeft<CR>
nnoremap <leader>w :ArgWrap<CR>
nnoremap <leader>ss :setlocal spell!<CR>

hi link juliaFunctionCall Identifier
hi link juliaParDelim Delimiter

nnoremap gf :vsp <cfile><CR>

" from: https://vim.fandom.com/wiki/Autocomplete_with_TAB_when_typing_words

" function! TabOrComplete(direction)
"     if col('.') > 1 && strpart(getline('.'), col('.') - 2, 3) =~# '^\w'
"         return a:direction ==# 'next' ? "\<C-n>" : "\<C-p>"
"     else
"         return "\<TAB>"
"     endif
" endfunction

" inoremap <TAB> <C-r>=TabOrComplete('next')<CR>
" st maps Shift-Tab to <ESC>[Z (and it's discouraged to change it)
" inoremap <ESC>[Z <C-r>=TabOrComplete('prev')<CR>

command! LaTeXtoUnicodeToggle call LaTeXtoUnicode#Toggle()

command! YankFilePath  let @" = expand('%')