aboutsummaryrefslogtreecommitdiff
path: root/.vim/vimrc
blob: abfe0465ff61901d56d25445c196799a1cc94b61 (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
" ===========
" VARIABLES
" ===========

" Needs to be enabled before ALE is loaded
let g:ale_completion_enabled = 1

runtime bundle/vim-pathogen/autoload/pathogen.vim
execute pathogen#infect('bundle-active/{}')

set nocompatible

" Style
highlight Pmenu ctermfg=0 ctermbg=7 guibg=Magenta

" Tabs
set tabstop=8
set softtabstop=8
set shiftwidth=8
set noexpandtab

"Disable bell
set vb
set t_vb=

set ttimeoutlen=10

" Flashy statusline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#branch#enabled = 1
"let g:airline#extensions#whitespace#enabled = 1
let g:airline#extensions#ale#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_highlighting_cache = 1

" Enable colored brackets
let g:rainbow_active = 1

" ALE config
"set omnifunc=ale#completion#OmniFunc
"let g:ale_completion_autoimport = 1
let g:ale_set_highlights = 1 "Highlights are annoying
let g:ale_set_signs = 1
"let g:ale_virtualtext_cursor = 1 " Only use one of the following
let g:ale_cursor_detail = 1
let g:ale_close_preview_on_insert = 1
let g:ale_floating_preview = 1
"let g:ale_hover_to_floating_preview  = 1
let g:ale_floating_window_border = []
let g:ale_linters = {'rust': [ 'analyzer']}

highlight ALEWarning cterm=underline,italic ctermfg=yellow
highlight ALEError cterm=underline,italic ctermfg=red

"All things cursor
set guicursor+=a:blinkon0 "disable blinking
if &term =~ "xterm\\|rxvt"
	" 1 or 0 -> blinking block
	" 2 -> solid block
	" 3 -> blinking underscore
	" 4 -> solid underscore
	" 5 -> blinking vertical bar
	" 6 -> solid vertical bar
	let &t_SI .= "\<Esc>[6 q" " Normal
	let &t_EI .= "\<Esc>[2 q" " Insert
endif

"show line endings and tabs
set listchars=tab:>\ ,trail:~,extends:>,precedes:<
set list

" leader
let mapleader = "-"
let leader = "-"
let maplocalleader = "-"

syntax enable
filetype plugin indent on

"Line number Highlight
set nu rnu
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE

"set foldmethod=syntax

" ==============
" SHORTCUTS
" ==============

"Switch windows with keys
"nmap <silent> <C-w-k> :wincmd k<CR>
"nmap <silent> <C-w-j> :wincmd j<CR>
"nmap <silent> <C-w-h> :wincmd h<CR>
"nmap <silent> <C-w-l> :wincmd l<CR>

" Completion
inoremap <expr> <Tab> Tab_Or_Complete()

nmap <silent> <C-s> :vsplit<CR>:e .<CR>
nmap <silent> <C-e> :e .<CR>

" Fold
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf

nmap <silent> <F4> :Runbuffer<CR>
au filetype c* nmap <silent> <F4> :Make<CR>
au filetype *tex nmap <silent> <F4> :Makelatex<CR>
au filetype *tex nmap <silent> <F2> :Openpdf<CR>

nmap <silent> <F5> :NERDTreeToggle<CR>
nmap <silent> <F6> :TlistToggle<CR>

"Tab mgmt
nmap <silent> gc :tabclose<CR>
nmap <silent> gn :tabnew<CR>:e .<CR>

"tmap <silent> <Esc> <C-\><C-n>

" Smart brackets
inoremap "" ""<left>
inoremap '' ''<left>
inoremap () ()<left>
inoremap [] []<left>
inoremap {} {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O

" vterminal
nmap <silent> <S-F3> :Newterm<CR>
nmap <silent> <F3> :VTermToggle<CR>
tnoremap <silent> <S-Tab> <C-W>:VTermSwitch<CR>
nnoremap <silent> <S-Tab> :VTermSwitch<CR>
"let g:vterminal_coverage = '0.33'

" reload vimrc
nmap <silent> <S-F12> :so $MYVIMRC<CR>

" ===========
" COMMANDS
" ===========

command -bar Suw :w !SUDO_ASKPASS="/usr/lib/ssh/ssh-askpass" sudo -A  tee %

"^] Jump to tag, ^t jump back
command! MakeTags !ctags -R .

command -bar Newterm call Run_in_terminal("")
command -bar Runbuffer call Run_in_terminal(expand("%:p"))
command -bar Make call Run_in_terminal("make run")
command -bar Fileheader call Insert_Header(expand("%"))

command -bar Makelatex silent! execute "!(pdflatex % > /dev/null 2>&1 && killall -s SIGHUP mupdf)&" | redraw!
command Openpdf silent! execute "!mupdf " . (join(split(expand("%"), '\.')[:-2], ".") . ".pdf") . " > /dev/null 2>&1 &" | redraw!

" ===========
" FUNCTIONS
" ===========

function Insert_Header(name)
	let l:name=systemlist("git config --global --get user.name")[0]
	let l:mail=systemlist("git config --global --get user.email")[0]
	call append("0", ["/*", " * ".a:name, " * (c) ".strftime("%Y")." ".l:name." <".l:mail.">", " * License: All rights reserved.", " */"])
	startinsert
endfunction

function Run_in_terminal(prog)
	let l:args = " "

	if !has('nvim')
		if !has('terminal')
			return
		endif

		let l:args='++curwin'
	endif

	tabnew
	execute "terminal " . l:args . " " . a:prog
	startinsert
endfunction

" if we are in the middle of typing, complete,
" otherwise just type TAB
function! Tab_Or_Complete() abort
  if pumvisible()
    return "\<C-N>"
  elseif col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^[[:keyword:][:ident:]]'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
endfunction