-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
257 lines (202 loc) · 7.34 KB
/
init.vim
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
" vim: foldmethod=marker
" speed up loading of lua modules
lua vim.loader.enable()
" Options {{{1
" Indentation
set expandtab
set shiftwidth=2
set softtabstop=-1 " set to same as 'shiftwidth'
set shiftround " indent to a multiple of 'shiftwidth'
" Line Wrapping
set linebreak
set breakindent " keep indentation when wrapping lines
set cpoptions+=n breakindentopt=sbr " display 'showbreak' symbol within the line number column
let &cedit="\<c-o>" " ...since <c-f> is shadowed by vim-rsi
set commentstring=#\ %s
set completeopt-=preview
set cursorline cursorlineopt=number " highlight current line number
set foldlevel=99 " start unfolded by default
set foldmethod=indent
set grepprg=rg\ --vimgrep grepformat^=%f:%l:%c:%m
set helpheight=1000 " maximize help window
set ignorecase smartcase " case-insensitive search, unless query has capital letter
set lazyredraw " only redraw screen when necessary
set list listchars=tab:▸·,extends:❯,precedes:❮,nbsp:⁓
set matchpairs+=«:»
set mouse=
set noswapfile directory='' " disable swapfile
set notimeout
set path-=/usr/include
set relativenumber number numberwidth=1 " use relative line number, but display absolute number on current line
set scrolloff=3
set signcolumn=yes
set splitbelow splitright
set tagcase=smart
set termguicolors
set title
set updatetime=1000
set wildcharm=<c-z>
set wildmode=longest:full,full
" Use dedicated directory for spelling word list files. It needs to be the
" "first directory in 'runtimepath' that is writable", according to the
" documentation of 'spellfile'.
let spellfiles_rtp = stdpath('data') .. '/spellfiles'
let &runtimepath=printf('%s,%s', spellfiles_rtp , &runtimepath)
" Allow syntax highlighting of embedded lua in vimscript files
" c.f. $VIMRUNTIME/syntax/vim.vim
let g:vimsyn_embed = 'l'
" Prevent loading of netrw plugin
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
colorscheme couleurs
" Mappings {{{1
let g:mapleader = ','
" Buffers
nnoremap <leader><leader> <c-^>
nnoremap <leader>b :ls<cr>:b<space>
nnoremap <leader>B :ls<cr>:sb<space>
" close quickfix window before `bdelete`, to avoid prematurely quitting vim
" (cf. g:qf_auto_quit)
nnoremap <silent> <leader><bs> :cclose <bar> :lclose <bar> :bdelete<cr>
" Navigate between windows
nnoremap <a-h> <c-w>h
nnoremap <a-j> <c-w>j
nnoremap <a-k> <c-w>k
nnoremap <a-l> <c-w>l
nnoremap <a-p> <c-w>p
tnoremap <a-h> <c-\><c-n><c-w>h
tnoremap <a-j> <c-\><c-n><c-w>j
tnoremap <a-k> <c-\><c-n><c-w>k
tnoremap <a-l> <c-\><c-n><c-w>l
tnoremap <a-p> <c-\><c-n><c-w>p
xnoremap <a-h> <esc><c-w>h
xnoremap <a-j> <esc><c-w>j
xnoremap <a-k> <esc><c-w>k
xnoremap <a-l> <esc><c-w>l
xnoremap <a-p> <esc><c-w>p
" Resize windows
nnoremap <a-up> 3<c-w>+
nnoremap <a-down> 3<c-w>-
nnoremap <a-right> 3<c-w>>
nnoremap <a-left> 3<c-w><
nnoremap <a-=> <c-w>=
nnoremap <a--> <c-w>_<c-w><bar>
" 'Detach' window to new tab
nnoremap <c-w><c-d> <c-w>T
" Navigate between files in argument list
nnoremap <silent> [a :previous <cr>
nnoremap <silent> ]a :next <cr>
nnoremap <silent> [A :first <cr>
nnoremap <silent> ]A :last <cr>
" Navigate between files in quickfix list
nnoremap <silent> [z :cpfile <cr>
nnoremap <silent> ]z :cnfile <cr>
" Navigate between entries in tag matchlist
nnoremap <silent> [t :tprevious <cr>
nnoremap <silent> ]t :tnext <cr>
nnoremap <silent> [T :tfirst <cr>
nnoremap <silent> ]T :tlast <cr>
" Use ctrl-s to save file
nnoremap <silent> <c-s> :update<cr>
inoremap <silent> <c-s> <esc>:update<cr>
" Move through wrapped lines (unless prefixed with a count)
nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
" Do not increase/decrease numbers with ctrl-a/ctrl-x
nnoremap <c-a> <nop>
nnoremap <c-x> <nop>
" Make ctrl-g print the full path and buffer number by default
nnoremap <c-g> 2<c-g>
" Yank and put from system clipboard
" Recursive maps so that miniyank plugin mappings are preserved
nmap gy "+y
xmap gy "+y
nmap gY "+Y
nmap gp "+p
xmap gp "+p
nmap gP "+P
" Copy last yank to system clipboard
nnoremap <silent> cp :ToSystemClipboard<cr>
" Toggle fold
nnoremap <space> za
" Easier substitute
nnoremap <leader>/ :%s/
xnoremap <leader>/ :s/
" Visually select last changed or yanked text
nnoremap gV `[v`]
" Consider already entered text as prefix when navigating command-line history
" The `wildmenumode()` guard is needed to preserve ctrl-n/ctrl-p behaviour
" when using completion menu.
cnoremap <expr> <c-n> wildmenumode() ? "<c-n>" : "<down>"
cnoremap <expr> <c-p> wildmenumode() ? "<c-p>" : "<up>"
" Navigate between search matches while searching
cnoremap <expr> <tab> getcmdtype() =~ '[?/]' ? "<c-g>" : "<c-z>"
cnoremap <expr> <s-tab> getcmdtype() =~ '[?/]' ? "<c-t>" : "<s-tab>"
" Insert the path of the directory of the current buffer
cnoremap <expr> <c-r>< expand('%:h').'/'
" Join all lines in a paragraph (and make it repeatable through vim-repeat)
nnoremap <silent> gJ vipJ :call repeat#set('gJ')<cr>
" Make `*` and `#` respect `smartcase`
nnoremap * /\<<c-r>=expand('<cword>')<cr>\><cr>
nnoremap # ?\<<c-r>=expand('<cword>')<cr>\><cr>
" Run recorded macro on visual selection
function! ExecuteMacroOnSelection()
execute ":'<,'>normal @" . nr2char(getchar())
endfunction
xnoremap @ :<c-u>call ExecuteMacroOnSelection()<cr>
nnoremap <leader>s :Grep<space>
nnoremap <leader>S :Grep!<space>
" Search operator
nnoremap <silent> gs :set opfunc=v:lua.require'lib.opfunc'.search<cr>g@
xnoremap <silent> gs :<c-u>lua require("lib/opfunc").search(vim.fn.visualmode())<cr>
nmap gss gsiw
" Sort operator
nnoremap zs :echo "sort" <bar> set opfunc=v:lua.require'lib.opfunc'.sort<cr>g@
xnoremap <silent> zs :<c-u>lua require("lib/opfunc").sort(vim.fn.visualmode())<cr>
" Open browser at url under cursor
nnoremap <silent> gx <cmd>Browse<cr>
" Toggle spellcheck and spelllang
nnoremap <silent> cos :set spell! <cr>
nnoremap <silent> col :execute 'setlocal spelllang=' . (&spelllang ==# 'en' ? 'fr' : 'en') <cr>
" Toggle cursorline highlighting
nnoremap <silent> coc <cmd>execute 'set cursorlineopt=' . (&culopt ==# 'number' ? 'both' : 'number')<cr>
" Toggle wrap
nnoremap <silent> cow :set wrap! <bar> set wrap? <cr>
" Toggle relativenumber
nnoremap <silent> con :set relativenumber!<cr>
" Toggle dark/light background
nnoremap <silent> cob :execute 'set bg=' . (&bg ==# 'dark' ? 'light' : 'dark') <cr>
" Toggle colorscheme
nnoremap <silent> cog :execute 'colo ' . (g:colors_name ==# 'couleurs' ? 'gris' : 'couleurs') <cr>
" Use <esc> to exit terminal mode (and alt-[ to send escape to terminal)
tnoremap <expr> <esc> "<c-\><c-n>"
tnoremap <a-[> <esc>
" Emulate i_CTRL-R
tnoremap <expr> <a-r> '<c-\><c-n>"'.nr2char(getchar()).'pi'
" Apply first spelling suggestion to current or next misspelled word
nnoremap Z ge]s1z=
" Use git-jump from within vim. Can pass a count of 1, 2, or 3 for `diff`,
" `staged`, and `merge` variants.
nnoremap <silent> <leader>j :Jump<cr>
" Trigger insert mode completions
inoremap ,f <c-x><c-f>
inoremap ,l <c-x><c-l>
inoremap ,t <c-x><c-]>
inoremap ,<tab> <c-x><c-o>
" Display syntax highlight group of term under cursor
nnoremap <leader>H <cmd>Inspect<cr>
" Map some keys on the French-Canadian keyboard to their English (quasi)
" equivalents in normal mode
nnoremap Ç }
nnoremap ¨ {
nnoremap é /
nnoremap É ?
nnoremap è '
nnoremap È "
" Define `P()` as a global Lua function to pretty-print values
lua _G.P = vim.print
" Abbreviations {{{1
iabbrev Quebec Québec
iabbrev Montreal Montréal
cabbrev Q! q!
cabbrev CF Cfilter