rc

.vimrc

1
" Vngngdn's personal .vimrc.
2
" Some details on the contents:
3
" This file is my personal Vim configuration file. It contains my plugins, is
4
" divided to subject, and fattened with lovely comments.
5
" Please be advised that some (obvious) settings are left out, because I
6
" actually only use NeoVim. Again, this is my PERSONAL file, not a 'general
7
" public Vi(m) compatible' file.
8
9
" VUNDLE {{{
10
" Vundle is used to manage plugins for Vim. It needs additional setup, so it
11
" gets priority in my .vimrc.
12
13
filetype off                  " required
14
15
" set the runtime path to include Vundle and initialize
16
set rtp+=~/.config/nvim/bundle/Vundle.vim
17
call vundle#begin()
18
19
" let Vundle manage Vundle, required
20
Plugin 'VundleVim/Vundle.vim'
21
22
" YCM is a plugin that allows Vim semantic type checking and more programming mumbo jumbo. It is godlike and it must always be there for me.
23
Plugin 'Valloric/YouCompleteMe'
24
25
" Neomake replaces Syntastic from now on. It's an asynchronous linter, so yeah,
26
" pretty cool and must-have.
27
Plugin 'neomake/neomake'
28
29
" Airline provides a neat and feature rich status bar. Really nice to have.
30
Plugin 'bling/vim-airline'
31
32
" Bufferline will show buffers in the status bar. There's enough room anyway, so I fancied having it.
33
Plugin 'bling/vim-bufferline'
34
35
" A fuzzy searcher. Just CTRL+P and BAM all your files are visible.
36
Plugin 'kien/ctrlp.vim'
37
38
" This is a plugin for Git interaction. It places added and removed line icons
39
" in the 'gutter' (the bar next to the line numbering). It's better than
40
" Fugitive, because not only does it provide something you don't have with it
41
" (visible change lines), Fugitive offers functionality I rarely use (Git
42
" commands from Vim, which I ALWAYS do in the standard TUI), and it has
43
" provisions for NeoVim's asynchronous abilities.
44
Plugin 'airblade/vim-gitgutter'
45
46
" This provides snippets for redundant code. Praise the hackers man.
47
Plugin 'SirVer/ultisnips'
48
49
" In addition to UltiSnips, this plugin contains a prefetched repository of snippets. Must have, because I'm not planning on writing all of those by myself.
50
Plugin 'honza/vim-snippets'
51
52
" Rust syntax files, including Syntastic integration:
53
" To be removed when these are added to (Neo)Vim 'upstream'.
54
Plugin 'rust-lang/rust.vim'
55
56
" Kotlin syntax files
57
Plugin 'udalov/kotlin-vim'
58
59
" All of your Plugins must be added before the following line
60
call vundle#end()            " required
61
filetype plugin indent on    " required
62
" }}}
63
64
" YOUCOMPLETEME {{{
65
" YouCompleteMe is a godlike completer for Vim. As such, it is worthy of its own section.
66
" However, I'll be trying out Deoplete in the future, which might render it
67
" obsolete. Until further notice, I'm keeping this beauty.
68
"
69
" This setting will force YCM to close the preview buffer after selecting the completion.
70
let g:ycm_autoclose_preview_window_after_completion=1
71
72
" Sets the symbol used to indicate a syntax error:
73
let g:ycm_error_symbol = '>>'
74
75
" Sets the symbol used to indicate a warning:
76
let g:ycm_warning_symbol = 'i'
77
78
" Fills the identifier completion database with the language's keywords (e.g., when starting a new Java file, "class" will already be in the completion engine.
79
let g:ycm_seed_identifiers_with_syntax = 1
80
81
" This setting tells YCM what keys to use to accept completion. I removed <Down> as default, because I'm a silly coder and still use my arrow keys to navigate my source files. Hey, years of negligence for Vim leaves its marks. To think I ever thought Notepad++ was the best editor ever, the fuck...
82
let g:ycm_key_list_select_completion=['<TAB>']
83
84
" Same reason; I'm a dumb fuck and arrows are still hardwired in my brain.
85
let g:ycm_key_list_previous_completion=['<S-TAB>']
86
87
" Configures the pointer to the ycm_extra_conf.py file.
88
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
89
let g:ycm_confirm_extra_conf = 0 " Disables security confirmation before loading the conf.py file.
90
91
" Configuration necessary for sematic Rust completion
92
let g:ycm_rust_src_path = '/usr/src/rust/src'
93
" }}}
94
"
95
" NEOMAKE {{{
96
" This setting lets Neomake run on every file write:
97
autocmd! BufWritePost * Neomake
98
" }}}
99
"
100
" GITGUTTER {{{
101
" Disables all keymappings of GitGutter. I don't use them anyway.
102
let g:gitgutter_map_keys = 0
103
" Sets the 'refresh time' of when to update. Standard is 4 seconds.
104
set updatetime=250
105
" Asynchronous updating is default, so no setting is needed. Check the FAQ if
106
" necessary for more information.
107
" }}}
108
"
109
" AIRLINE {{{
110
" Airline is a great status bar plugin. Although it can behave quirky if Powerline is not on the scene. These scripts are dedicated to handle that behavior.
111
112
" These lines will load the powerline font for use in Airline.
113
if !exists('g:airline_symbols')
114
		let g:airline_symbols={}
115
	endif
116
let g:airline_symbols.space="\ua0"
117
let g:airline_powerline_fonts=1
118
119
" If there is only one tab opened, the tab bar will display the different buffers.
120
let g:airline#extensions#tabline#enabled=1
121
let g:bufferline_echo = 0 " Disables automatic echoing to the bufferline.
122
123
" }}}
124
125
" ULTISNIPS {{{
126
" As mentioned earlier, this provides snippets to stop redundant code.
127
128
" To begin, changing default TAB, because YCM already uses TAB.
129
	let g:UltiSnipsExpandTrigger="<c-l>"
130
	let g:UltiSnipsJumpForwardTrigger="<c-j>"
131
	let g:UltiSnipsJumpBackwardTrigger="<c-k>"
132
133
" }}} 
134
"
135
" COLOURS & COLORS {{{
136
137
colorscheme molokai " I like molokai. I've used badwolf, but I like popping colors.
138
139
" }}}
140
141
" SPACES & TABS {{{
142
143
" To everyone: STOP USING TABS. USE SPACES. Really. The amount of
144
" inconsistencies in source code can be reduced by a landslide if everyone uses
145
" spaces. Spaces look the same on EVERY editor, IDE, printed sheet, ... Spaces
146
" enjoy *universal consistency across every computer*. TABs are objectively less
147
" useful than spaces.
148
149
" The number of visual spaces per TAB hit.
150
set tabstop=4
151
152
" Amount of spaces inserted when TAB is hit during editing.
153
set softtabstop=4
154
155
" Makes TABs spaces when TAB is hit.
156
set expandtab
157
158
" Setting the amount of tabs to 4. The default is 8.
159
set shiftwidth=4
160
161
" This breaks lines after column 80.
162
set textwidth=80
163
" }}}
164
165
" UI CONFIGURATION {{{
166
167
" The next 2 settings enable relative line numbering, but retain the absolute
168
" line numbering for the line currently selected by the cursor.
169
set number
170
set relativenumber
171
set cursorline " Highlights the line currently selected by the cursor.
172
filetype indent on " Detects filetype on load, and loads the appropriate syntax file.
173
set showmatch " Highlights matching parenthesis on hover ("[, {, ...").
174
" scrolloff tells Vim how much lines above/below the cursor should always be
175
" visible. For example, if set to 5, there will always be 5 lines below and
176
" above the cursor, except when reaching the EOF.
177
set scrolloff=5
178
" Next setting disables outputting the current mode to the last line. I did so,
179
" because I use Airline, which already prints the current mode.
180
set noshowmode
181
182
" Shows a graphical menu when Vim suggests autocompletions in Ex mode
183
set wildmenu
184
185
" }}}
186
187
" SEARCHING {{{
188
189
" Problem with hlsearch is that it does not turn off the highlighting. So searching for vowels may quickly result in everything being highlighted. This is a mapping. It will remove highlighting when entering \<SPACE>
190
nnoremap <leader><space> :nohlsearch<CR>
191
" }}}
192
193
" FOLDING {{{
194
" In case I forget (I'm Belgian), folding is hiding code parts that belong together, like functions. Très important. Fuck azerty.
195
196
" This enables folding as is.
197
set foldenable
198
199
" This setting determines how many folds have to be opened. The number indicates the folding level. So 0 = every possible folding is folded. 99 = practically everything is open. I'm using 10, since I already have a problem with more than 3 nested loops.
200
set foldlevelstart=10
201
202
" This setting blocks overuse of nested foldings. I don't know how this will turn out in LISP/Scheme, but I'll be damned if this setting does more harm than good.
203
set foldnestmax=10
204
205
" This setting is commented by default, but included in case I start to grow hate for the current way Vim handles folding (za). It basically maps that command to spacebar. I may map it to z because then I only have to type one letter and RETURN, that's 33% of my time saved! =3
206
"nnoremap <space> za
207
208
" }}}
209
210
" MOVEMENT {{{
211
212
" Up and down moving in Vim using j/k defaults to "physical line movement", i.e.
213
" if a line is too long, it's wrapped to the next line ("virtual lines"), but
214
" the line counter still regards it as 1 line.
215
" The next setting makes it so that, if j/k is pressed once, it moves over
216
" virtual lines, but when repeated (say "5dd"), it moves over physical lines.
217
" Basically, the perfect tradeoff solution when using relative line numbering.
218
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
219
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
220
" Next 4 lines disable arrow keys.
221
noremap <Up> <nop>
222
noremap <Down> <nop>
223
noremap <Left> <nop>
224
noremap <Right> <nop>
225
" }}}
226
227
" BACKING UP {{{
228
229
" What these lines do, is move the backup files to the /tmp folder. This will keep my directories clean and neat.
230
set backup
231
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
232
set backupskip=/tmp/*,/private/tmp/*
233
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
234
set writebackup
235
" }}}
236
"
237
" NEOVIM {{{
238
" While it certainly is an improvement over 'vanilla' Vim, it does some things
239
" that keep me from using Vim as it's supposed to be; limited to no mouse usage.
240
" So I disable it. I'll enable it again when I've twisted my mind far enough to
241
" not touch my mouse again. (Not to mention some terminals don't support mouse
242
" control, so it's a bad habit nonetheless if you spend all your time on
243
" GNU/Linux distros)
244
set mouse=""
245
" }}}
246
"
247
" MACROS {{{
248
" Function that allows to quickly switch between relative and absolute numbering using
249
" CTRL+N(umber).
250
function! NumberToggle()
251
	if(&relativenumber == 1)
252
		set norelativenumber  " Necessary to disable the previous behavior.
253
		set number
254
	else
255
		set number " Retains absolute number on the current line.
256
		set relativenumber
257
	endif
258
endfunc
259
nnoremap <C-n> :call NumberToggle()<cr>
260
" }}}
261
262
" ENVIRONMENT INTEGRATION {{{
263
264
" Tmux is an awesome terminal multiplexer. However, with Vim, it may act tricky
265
" with cursor look. Next setting changes the block cursor to a vertical bar
266
" cursor, which I prefer.
267
if exists('$TMUX')
268
    let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
269
    let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
270
else
271
    let &t_SI = "\<Esc>]50;CursorShape=1\x7"
272
    let &t_EI = "\<Esc>]50;CursorShape=0\x7"
273
endif
274
275
" Makes Vim use the system's clipboard.
276
"set clipboard^=unnamedplus,unnamed
277
278
" }}}
279
" OTHER IMPORTANT STUFF {{{
280
281
" Makes 'Y' act like 'D' and 'C'. Normally, Y yanks the entire line, but D and C
282
" do their action until the end of the line. so Y is technically yy.
283
noremap Y y$
284
285
" I found this gem on Reddit. If I'm editing a file that's read only, and I started Vim without sudo, then this little line will do just that for me. All I have to do is use "w!!" when saving.
286
" Extensive explanation can also be found at https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work#7078429
287
cmap w!! w !sudo tee > /dev/null %
288
289
290
" This setting will allow me to switch to another buffer without need to save the current buffer.
291
set hidden
292
293
" I use NeoVim, but I may encounter a vanilla Vim user once in a while. Next
294
" setting disables Vi compatibility (which NeoVim does by default).
295
set nocompatible  
296
297
" Same reasoning. Enables syntax processing in Vim.
298
syntax enable
299
" }}}
300
301
" Because Vim can fold vimrc files with the right syntax, These lines will tell Vim how to handle that.
302
set modelines=2 "This tells Vim that the last 2 lines of this file should only apply to this file.
303
" So as you can see, the last 2 lines get a special vim:-prefix, so Vim knows for sure this is what's important.
304
" To wrap a new section, look at the other sections, and copy that syntax.
305
" vim:foldmethod=marker
306
" vim:foldlevel=0
307