-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.vim
executable file
·343 lines (299 loc) · 10.2 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
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
" How do I reload my config without closing vim??
" :so %
" :PlugInstall
" :PlugUpdate
"
" If you want to uninstall something, remove the line, run ":so %", then run
" ":PlugClean"
set number
set ignorecase
set smartcase
set smartindent
set scrolloff=12 " space between cursor and bottom of screen before scroll
let mapleader = ","
" Preserve undo/redo history
set undofile
" 2 space indentation
set tabstop=4
set softtabstop=0
set expandtab
set shiftwidth=2
set smarttab
" character limit column
highlight ColorColumn ctermbg=0
set colorcolumn=80
" Easy split switching
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
" Copy to system clipboard by hitting leader first
vnoremap <leader>y "+y
nnoremap <leader>Y "+yg_
nnoremap <leader>y "+y
nnoremap <leader>yy "+yy
" Paste from system clipboard by hitting leader first
nnoremap <leader>p "+p
nnoremap <leader>P "+P
vnoremap <leader>p "+p
vnoremap <leader>P "+P
" Format comments to match line length with gw in visual mode.
set textwidth=80
set formatoptions=q
" Remap escape
imap jk <Esc>
" react to the mouse as well
set mouse=a
" eslint. Justin disabled because slowing down saving non-JS files.
" let g:neomake_javascript_enabled_makers = ['eslint']
" autocmd! BufWritePost,BufEnter * Neomake
nmap <Leader>n :lnext<CR> " next error/warning
nmap <Leader>N :lprev<CR> " previous error/warning
" vim-javascript
let g:javascript_plugin_jsdoc = 1 " jsdoc syntax highlighting
" disable folding
set nofoldenable
" [buffer number] followed by filename:
set statusline=[%n]\ %t
" show line#:column# on the right hand side
set statusline+=%=%l:%c
nnoremap <C-p> <cmd>Telescope find_files<cr>
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>
" vim-plug
call plug#begin('~/.vim/plugged')
" use vim-jsx on .js files too
let g:jsx_ext_required = 0
" elm syntax highlighting
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:elm_syntastic_show_warnings = 1
" flow syntax highlighting
let g:javascript_plugin_flow = 1
" deoplete code completion
" let g:deoplete#enable_at_startup = 1
"
" <TAB>: completion.
" inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" Set paths to homebrew pythons
" let g:python_host_prog = '/usr/local/bin/python'
" let g:python3_host_prog = '/usr/local/bin/python3'
" Dart
let dart_style_guide = 2
" autocmd FileType dart call deoplete#custom#buffer_option('auto_complete', v:false)
" lsc
" set shortmess-=F
" let g:lsc_server_commands = {'dart': 'dart_language_server'}
" vim-plug
call plug#begin('~/.vim/plugged')
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.8' }
" Justin disabled neomake because it's slowing down saving non-JS files.
" Plug 'https://github.com/neomake/neomake.git'
Plug 'https://github.com/leafgarland/typescript-vim.git'
Plug 'pangloss/vim-javascript'
Plug 'https://github.com/hail2u/vim-css3-syntax.git'
Plug 'mxw/vim-jsx'
Plug 'tpope/vim-fugitive'
Plug 'lewis6991/gitsigns.nvim'
Plug 'elmcast/elm-vim'
Plug 'tikhomirov/vim-glsl'
Plug 'flowtype/vim-flow'
Plug 'vim-scripts/loremipsum'
Plug 'maxmx03/solarized.nvim'
Plug 'google/vim-searchindex'
Plug 'lukas-reineke/indent-blankline.nvim'
" Removed dart-vim-plugin because syntax highlighting is now done with tree-sitter.
" Plug 'dart-lang/dart-vim-plugin'
if has('nvim')
" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
" Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
" Plug 'carlitux/deoplete-ternjs', { 'do': 'npm install -g tern' }
" I previously tried using lsc, but it makes nvim slow in big files.
" Plug 'neoclide/coc.nvim', {'branch': 'release'} " Also do: :CocInstall coc-flutter and coc-snippets
" Then coc I couldn't get fully working, like autocompletion of fn params.
" So here I'm trying lsp:
" Plug 'natebosch/vim-lsc'
" Plug 'natebosch/vim-lsc-dart'
" Plug 'honza/vim-snippets'
Plug 'neovim/nvim-lspconfig'
" Plug 'mfussenegger/nvim-jdtls'
Plug 'stevearc/dressing.nvim' " optional for vim.ui.select for flutter-tools.
" TODO(justinmc): Completion is often very slow in practice. This seems to be
" the completion plugin of choice, so it's probably my config's fault.
Plug 'hrsh7th/nvim-cmp' " Autocompletion plugin
" Justin - This is suspcious for performance problems, so I'm disabling it for
" now. However, I'm totally not convinced that it is the problem.
" Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-nvim-lua'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'saadparwaiz1/cmp_luasnip' " Snippets source for nvim-cmp
Plug 'L3MON4D3/LuaSnip', {'tag': 'v2.*', 'do': 'make install_jsregexp'}
Plug 'akinsho/flutter-tools.nvim'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'folke/trouble.nvim'
Plug 'folke/which-key.nvim'
Plug 'windwp/nvim-autopairs'
Plug 'AndrewRadev/splitjoin.vim'
call plug#end()
" Colors!
" Note to self: Seems like on GLinux this has to match the terminal theme...
syntax enable
set background=dark
colorscheme solarized
lua <<EOF
-- local config = {
-- cmd = {'/usr/local/google/home/jmccandless/bin/jdt-language-server-1.9.0-202203031534/bin/jdtls'},
-- root_dir = vim.fs.dirname(vim.fs.find({'gradlew', '.git', 'mvnw'}, { upward = true })[1]),
-- }
-- Justin: This was starting even when opening dart files, so I disabled for now.
-- require('jdtls').start_or_attach(config)
require('gitsigns').setup()
require("trouble").setup {
}
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<leader>N', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', '<leader>n', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, 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
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, bufopts)
-- nnoremap("<C-o>", jdtls.organize_imports, bufopts, "Organize imports")
end
-- Add additional capabilities supported by nvim-cmp
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require('lspconfig')
local lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}
lspconfig['pyright'].setup{
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
lspconfig['ts_ls'].setup{
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
lspconfig['rust_analyzer'].setup{
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
-- Server-specific settings...
settings = {
["rust-analyzer"] = {}
}
}
--[[
lspconfig['dartls'].setup{
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
]]--
require("flutter-tools").setup{
-- TODO(justinmc): Is there anything you can do to improve performance here?
lsp = {
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
settings = {
analysisExcludedFolders = {},
},
},
}
-- luasnip setup
local luasnip = require 'luasnip'
require("luasnip.loaders.from_snipmate").lazy_load({ paths = {"./snips"} })
-- nvim-cmp setup
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require 'cmp'
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
-- Justin - I'm not clear if or how much this stuff helps performance.
-- I think that completion can't happen if the flutter linter thing hasn't
-- finished running. Maybe that's more to do with my problems?
performance = {
async_budget = 100,
fetching_timeout = 100,
throttle = 50,
debounce = 50,
},
}
require("ibl").setup()
require('which-key').setup()
require('nvim-autopairs').setup()
EOF