-
Notifications
You must be signed in to change notification settings - Fork 5
/
.vimrc
421 lines (349 loc) · 13.7 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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
" Theme
Plug 'chriskempson/base16-vim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'ryanoasis/vim-devicons'
Plug 'dracula/vim', { 'as': 'dracula' }
" Testing
Plug 'janko-m/vim-test'
" Git(Hub)
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
" LSP
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/nvim-lsp-installer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'folke/trouble.nvim'
" Autocomplete
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" Fuzzy search
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
Plug 'nvim-telescope/telescope-file-browser.nvim'
" Languages
Plug 'vim-ruby/vim-ruby'
Plug 'fatih/vim-go'
" Misc
Plug 'kyazdani42/nvim-web-devicons'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'christoomey/vim-tmux-navigator'
call plug#end()
set nocompatible " Vim behavior, not Vi.
set encoding=utf-8 " Use UTF-8 encoding
set nobackup " Don't backup
set nowritebackup " Write file in place
set noswapfile " Don't use swap files (.swp)
set autoread " Autoreload buffers
set autowrite " Automatically save changes before switching buffers
syntax enable " Enable syntax highlight
syntax on " Syntax on for wimwiki
" History, Cursor, Rulers
set history=50 " Just remember last 50 commands
set laststatus=2 " Always display the status line
set ruler " Show the cursor position all the time
set number " Show line numbers
set showcmd " Display incomplete commands
set cursorline " Highlight current cursor line
set shell=$SHELL " Default shell is ZSH
" Tabs and white spaces
set nowrap " Don't wrap lines
set tabstop=2 " Tabs are always 2 spaces
set expandtab " Expand tabs into spaces
set shiftwidth=2 " Reindent with 2 spaces (using <<)
set list " Show invisible chars
set listchars="" " Reset listchars
set list listchars=tab:»·,trail:· " Set listchars for tabs and trailing spaces
" Search
set hlsearch " Highlight matches
set incsearch " Incremental searching
set ignorecase " Searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
" Apparence
let base16colorspace=256
set background=dark
set guifont=InconsolataForPowerline\ Nerd\ Font\ Medium:h18
set linespace=2
set visualbell
set termguicolors
colorscheme base16-dracula
let g:airline_theme='dracula'
let g:airline_powerline_fonts = 1
let g:airline#extensions#nvimlsp#enabled = 1
let g:airline#extensions#nvimlsp#error_symbol = 'E'
let g:airline#extensions#nvimlsp#warning_symbol = 'W'
let g:tmuxline_theme='base16_dracula'
if filereadable(expand("~/.vimrc_background"))
let base16colorspace=256
source ~/.vimrc_background
endif
if !has('nvim')
set antialias
endif
set guioptions-=T " Hide the Vim toolbar
set guioptions-=r " Hide the Vim scrollbars
if has('gui_running')
set transparency=5 " A bit of transparency
endif
" highlight the 80th column
"
" In Vim >= 7.3, also highlight columns 120+
if exists('+colorcolumn')
let &colorcolumn="80,".join(range(120,999),",")
endif
" Splits
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>
" Buffers
map <leader>bd :bufdo bdelete<cr>
" ctags
map <silent> <Leader>rt :!retag<cr>
nmap <F8> :TagbarToggle<CR>
" Remove highlight after search
nmap <silent> <C-N> :silent noh<CR>
" Quick switch between numbers ruler
noremap <silent> <F12> :set number!<CR>
" Open my sharpening tools list (Thanks to Ben Orenstein)
map <Leader>sha :sp ~/Documents/Work/sharp.txt<CR>
" Force using hjkl, not arrows
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>
" Demo
function! ReadDemoingSlideInformations()
let g:demoing_file_name = str2nr(expand("%:r"))
let g:demoing_file_type = "." . expand("%:e")
endfunction
function! LoadDemoingSlide()
execute "edit " . g:demoing_file_name . g:demoing_file_type
endfunction
function! NextDemoingSlide()
call ReadDemoingSlideInformations()
let g:demoing_file_name += 1
call LoadDemoingSlide()
endfunction
function! PreviousDemoingSlide()
call ReadDemoingSlideInformations()
let g:demoing_file_name -= 1
call LoadDemoingSlide()
endfunction
map <F4> :call NextDemoingSlide()<CR>
map <F3> :call PreviousDemoingSlide()<CR>
function! Carousel()
for theme in split(globpath(&runtimepath, 'colors/*.vim'), '\n')
let t = fnamemodify(theme, ':t:r')
try
execute 'colorscheme '.t
echo t
catch
finally
endtry
sleep 4
redraw
endfor
endfunction
map <silent> <Leader>tc :call Carousel()<cr>
" The Silver Searcher
" Inspired by http://robots.thoughtbot.com/faster-grepping-in-vim/
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor\ --path-to-ignore\ $HOME/.agignore
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
" bind K to grep word under cursor
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" bind , (backward slash) to grep shortcut
command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
nnoremap , :Ag<SPACE>
endif
nmap <silent> <leader>re :TestNearest<CR>
nmap <silent> <leader>r :TestFile<CR>
nmap <silent> <leader>rs :TestSuite<CR>
nnoremap <leader>tr <cmd>TroubleToggle<cr>
" Ruby
if has('nvim')
" Run Ruby script in NeoVim terminal emulator
map <Leader>rr :w<CR>:split \| terminal ruby %<CR>:startinsert<CR>
endif
" Automatically fold comments in Ruby files
autocmd FileType ruby,eruby
\ set foldmethod=expr |
\ set foldexpr=getline(v:lnum)=~'^\\s*#'
function! RubocopAutocorrect()
execute "!rubocop -a " . bufname("%")
endfunction
map <silent> <Leader>cop :call RubocopAutocorrect()<cr>
" From: https://shime.sh/til/writing-custom-vim-template
" Automatically add frozen string literal to the header of Ruby files.
function! RubyTemplate()
" Add pragma comment
call setline(1, '# frozen_string_literal: true')
" Add two empty lines
call append(1, repeat([''], 2))
" Place cursor on line number 3
call cursor(3, 0)
" Write file to refresh the buffer
execute "w"
endfunction
autocmd BufNewFile *.rb :call RubyTemplate()
function! FormatJSON()
execute "%!python -m json.tool"
endfunction
map <silent> <Leader>json :call FormatJSON()<cr>
" Coc
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
" Go
let g:python3_host_prog = '/usr/local/bin/python3'
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
"" Run Go
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
au FileType go nmap <leader>rt <Plug>(go-run-tab)
au FileType go nmap <Leader>rs <Plug>(go-run-split)
au FileType go nmap <Leader>rv <Plug>(go-run-vertical)
"" Go docs
au FileType go nmap <leader>ds <Plug>(go-def-split)
au FileType go nmap <leader>dv <Plug>(go-def-vertical)
au FileType go nmap <leader>dt <Plug>(go-def-tab)
au FileType go nmap <leader>gd <Plug>(go-doc)
au FileType go nmap <leader>gv <Plug>(go-doc-vertical)
au FileType go nmap <leader>gb <Plug>(go-doc-browser)
"" Go types
au FileType go nmap <leader>s <Plug>(go-implements)
au FileType go nmap <leader>i <Plug>(go-info)
let g:go_term_mode = "split"
let g:go_term_enabled = 1
let g:go_fmt_command = "goimports"
lua << EOF
require'lspconfig'.solargraph.setup{}
require'lspconfig'.gopls.setup{}
require'lspconfig'.eslint.setup{}
require'lspconfig'.tsserver.setup{}
local opts = { noremap=true, silent=true }
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'solargraph', 'gopls', 'eslint', 'tsserver' }
for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup {
on_attach = on_attach,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
}
end
-- Setup nvim-lsp-installer
local lsp_installer = require("nvim-lsp-installer")
-- Setup nvim-treesitter
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
ident = {
enable = true, disable = { "yaml" }
}
}
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-n>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{ name = 'buffer' },
})
})
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- The following example advertise capabilities to `clangd`.
require'lspconfig'.clangd.setup {
capabilities = capabilities,
}
require('telescope').setup({
pickers = {
find_files = {
theme = "dropdown",
}
},
})
require('telescope').load_extension('fzf')
require("telescope").load_extension "file_browser"
EOF
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>