-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
384 lines (346 loc) · 12 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
"-----Newly Learned Vim Features-----"
" <C-f> inside command mode opens the command line window
" q: does the same thing but from normal mode
"
"-----Test the speed of vim on startup on unix and windows, respectively-----"
" rm -f vim.log && vim --startuptime vim.log +q && tail -n 1 vim.log | cut -f1 -d' '
" rm -force -ErrorAction Ignore vim.log; vim --startuptime vim.log +q; tail -n 1 vim.log | cut -f1 -d' '
set nocompatible " be iMproved, required
if has('nvim')
let s:editor_root=expand("~/.config/nvim")
elseif has('unix')
let s:editor_root=expand("~/.vim")
endif
" Setting up plugins
if empty(glob(s:editor_root . '/plugged'))
autocmd VimEnter * PlugInstall
endif
call plug#begin(s:editor_root . '/plugged')
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-repeat'
Plug 'mhinz/vim-startify'
Plug 'tpope/vim-unimpaired'
Plug 'honza/vim-snippets'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'w0rp/ale'
Plug 'rakr/vim-one'
Plug 'tpope/vim-fugitive'
Plug 'RRethy/vim-illuminate'
Plug 'mfussenegger/nvim-jdtls'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'cormacrelf/vim-colors-github'
Plug 'itchyny/lightline.vim'
Plug 'airblade/vim-gitgutter'
Plug 'mg979/vim-visual-multi'
Plug 'svermeulen/vim-yoink'
Plug 'yazgoo/yank-history'
if version < 800 && has('unix')
Plug 'vim-syntastic/syntastic'
endif
call plug#end()
syntax enable
set hlsearch
set shiftwidth=4
set ignorecase
set smartcase
set completeopt=menu,menuone,noselect
set incsearch
if !has('mac')
let g:auto_color_switcher#desable = v:true
endif
let mapleader = " "
if (has("termguicolors"))
set termguicolors
set t_Co=256
endif
if has('nvim')
let g:one_allow_italics = 1
colorscheme one
set bg=light
endif
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab
set number relativenumber
set infercase
set splitbelow
set splitright
set noerrorbells
" let g:startify_change_to_vcs_root=1
let g:ale_fixers = {
\ 'javascript': ['eslint'],
\ 'typescript': ['tslint'],
\}
let g:ale_linters = {
\ 'cs':['syntax', 'semantic', 'issues'],
\ 'python': ['pylint'],
\ 'java': []
\ }
"-----mappings-----"
nnoremap <silent> + :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> \- :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <leader>ev :silent e ~/.vim/vimrc<CR>
nnoremap <leader>pi :PlugInstall<CR>
nnoremap <leader>pc :PlugClean<CR>
nnoremap <leader>rp :w<CR>:!python3 %<CR>
nnoremap <leader>tp :!python3 test_%<CR>
nnoremap <leader>rj :w<CR>:!node %<CR>
nnoremap <leader>bn :bn<CR> " Move to the next buffer
nnoremap <leader>bp :bp<CR> " Move to the previous buffer
nnoremap <silent> <esc><esc> :nohlsearch<CR><esc>
nnoremap gt :!ctags -R --exclude=.git --exclude=node_modules --exclude=out --exclude=build .<CR>
nnoremap gb :ls<CR>:b<Space>
nnoremap <leader>af :ALEFix<CR>
nnoremap Y y$
nnoremap gs :mksession! ./.session.vim<CR>
nnoremap gl :source ./.session.vim<CR>
nnoremap <leader>w :w<CR>
nnoremap [l :set norelativenumber nonumber<CR>:GitGutterDisable<CR>
nnoremap ]l :set relativenumber number<CR>:GitGutterEnable<CR>
nnoremap yob :call ToggleBackground()<CR>
nnoremap <leader>d :Gdiff<CR>
nnoremap <leader>o :FZF<CR>
nnoremap <leader>g :Rg<CR>
" Opens list of registers to paste from
nnoremap gp :reg <bar> exec 'normal! "'.input('>').'p'<CR>
nmap <leader>h :YankHistoryRgPaste<CR>
nmap <c-n> <plug>(YoinkPostPasteSwapBack)
nmap <c-p> <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
" pulls vim changes from git
if has('unix')
nnoremap <leader>pv :!(cd ~/.vim && git reset HEAD --hard && git pull)<CR>
elseif has ('win32')
nnoremap <leader>pv :!cd ~/vimfiles; git reset HEAD --hard; git pull<CR>
endif
" Renames selected word accross the file
" nnoremap <leader>rn :%s/\<<c-r><c-w>\>/
" more natural windows mappings
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-=> <C-W><C-=>
" buffer mappings
set hidden " This allows buffers to be hidden if you've modified a buffer
"-----Macros-----"
" Takes clipboard link of github to plugin and turns it into vim-plug syntax
let @p = "oPlug '*'T/;dT'"
" Add diagnostic info for https://github.com/itchyny/lightline.vim
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'filename', 'readonly', 'modified' ],
\ ],
\ 'right':[
\ [ 'filetype', 'fileencoding', 'lineinfo', 'percent' ],
\ ],
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead',
\ },
\ }
function UpdateBackground()
if system("defaults read -g AppleInterfaceStyle") == "Dark\n"
if &bg == "light" | set bg=dark | endif
else
if &bg == "dark" | set bg=light | endif
endif
runtime autoload/lightline/colorscheme/one.vim
call lightline#init()
call lightline#colorscheme()
call lightline#update()
endfunction
function ToggleBackground()
if &bg == "light"
set bg=dark
else
set bg=light
endif
runtime autoload/lightline/colorscheme/one.vim
call lightline#init()
call lightline#colorscheme()
call lightline#update()
endfunction
"-----auto-commands-----"
if has('nvim') && has('mac')
augroup nightfall
autocmd!
autocmd FocusGained,BufEnter * call UpdateBackground()
augroup END
endif
augroup autosourcing
autocmd!
if has('nvim')
autocmd BufWritePost vimrc execute "source " . s:editor_root . "/init.vim"
else
autocmd BufWritePost vimrc execute "source " . s:editor_root . "/vimrc"
endif
autocmd BufWritePost vimrc execute UpdateBackground()
augroup END
augroup TrimTrailingWhitespace
autocmd!
autocmd BufWritePre * %s/\s\+$//e
augroup END
" Ignore these directories
set wildignore+=*/build/**
set wildignore+=*/bin/**
set wildignore+=*/node_modules/**
set wildignore=*.swp,*.bak
set wildignore+=*.pyc,*.class,*.sln,*.Master,*.csproj,*.csproj.user,*.cache,*.dll,*.pdb,*.min.*
set wildignore+=*/.git/**/*,*/.hg/**/*,*/.svn/**/*
set wildignore+=tags
set wildignore+=*.tar.*
" Better display for messages
set cmdheight=2
lua << EOF
-- 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)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', 'gh', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Setup lspconfig.
local nvim_lsp = require('lspconfig')
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'tsserver' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
}
}
end
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
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-Space>'] = 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 }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
jdtls_setup = function()
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
local eclipse_dir = os.getenv('HOME') .. '/.config/eclipse-jdt/'
local root_dir = require('jdtls.setup').find_root({'packageInfo'}, 'Config')
local home = os.getenv('HOME')
local eclipse_workspace = home .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ':p:h:t')
local ws_folders_lsp = {}
local ws_folders_jdtls = {}
if root_dir then
local file = io.open(root_dir .. "/.bemol/ws_root_folders", "r");
if file then
for line in file:lines() do
table.insert(ws_folders_lsp, line);
table.insert(ws_folders_jdtls, string.format("file://%s", line))
end
file:close()
end
end
local config = {
on_attach = on_attach,
cmd = {
'java',
'-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4',
'-Declipse.product=org.eclipse.jdt.ls.core.product',
'-Dlog.protocol=true',
'-Dlog.level=ALL',
'-Xms1g',
'--add-modules=ALL-SYSTEM',
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
'-javaagent:' .. eclipse_dir .. '/lombok.jar',
'-jar', eclipse_dir .. '/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',
'-configuration', eclipse_dir .. '/config_linux',
'-data', eclipse_dir .. project_name,
eclipse_workspace
},
root_dir = root_dir,
init_options = {
workspaceFolders = ws_folders_jdtls,
},
}
require('jdtls').start_or_attach(config)
for _,line in ipairs(ws_folders_lsp) do
vim.lsp.buf.add_workspace_folder(line)
end
end
EOF
augroup lsp
autocmd!
autocmd FileType java luado jdtls_setup()
augroup end