-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
311 lines (272 loc) · 8.46 KB
/
init.lua
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
---- EXPERIMENTAL
-- options
vim.opt.number = true
vim.opt.tabstop = 2 -- Width of a <tab>
vim.opt.shiftwidth = 2 -- Number of spaces to use for each step of auto-indent
vim.opt.expandtab = true -- Use the appropriate number of spaces to insert a tab
vim.opt.signcolumn = "yes" -- always draw sign column
vim.opt.list = true -- show "-" for trailing whitespace, ">" for tab
vim.opt.termguicolors = true -- without this, WSL and ssh colors are wack
vim.opt.ignorecase = true -- by default, case insensitive search
vim.opt.smartcase = true -- if there exist any upper case, search case sensitive
-- better splits
vim.opt.splitbelow = true
vim.opt.splitright = true
-- Disable netrw banner
vim.g.netrw_banner = false
-- tree style
vim.g.netrw_liststyle = 3
---- COMMANDS
vim.api.nvim_create_user_command(
'NVimrc',
function(opts)
if vim.fn.has("win32") == 1 then
vim.cmd("edit ~\\AppData\\Local\\nvim\\init.lua")
else
vim.cmd("edit ~/.config/nvim/init.lua")
end
end,
{}
)
vim.api.nvim_create_user_command(
'Gl',
function(opts)
-- note vim buffers don't support terminal escapes, thus no color
vim.cmd([[
:Git log --format=format:'%h - %cs%d%n %s - %aN'
]])
end,
{}
)
vim.api.nvim_create_user_command(
'Gh',
function(opts)
vim.cmd([[
:Git log --graph --all --format=format:'%h - %cs%d%n %s - %aN'
]])
end,
{}
)
---- MAPPINGS
-- disable middle mouse paste
vim.keymap.set({"n", "v", "i"}, "<MiddleMouse>", "<Nop>", {noremap=true})
vim.keymap.set({"n", "v", "i"}, "<2-MiddleMouse>", "<Nop>", {noremap=true})
vim.keymap.set({"n", "v", "i"}, "<3-MiddleMouse>", "<Nop>", {noremap=true})
vim.keymap.set({"n", "v", "i"}, "<4-MiddleMouse>", "<Nop>", {noremap=true})
vim.keymap.set("n", "<c-p>", ":Files<cr>", {noremap=true})
vim.keymap.set("n", "<c-t>", ":tabe<cr>", {noremap=true})
---- PLUGINS
-- Bootstrap plugin manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup(
-- plugins
{
-- Chris Kempson's Base16 colorschemes, see `colorscheme...`
"RRethy/base16-nvim",
"neovim/nvim-lspconfig",
"mfussenegger/nvim-dap",
-- Shows git diff in gutter
"airblade/vim-gitgutter",
-- :Rename, :Move, :Delete
"tpope/vim-eunuch",
-- cs'"
"tpope/vim-surround",
-- auto-bracket pairing
"windwp/nvim-autopairs",
-- auto-complete
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
-- git
'tpope/vim-fugitive',
'tpope/vim-rhubarb',
'junegunn/fzf',
'junegunn/fzf.vim',
'junegunn/goyo.vim',
},
-- options
{}
)
-- For fzf.vim
-- Use rip grep for finding files, respect .gitignore
vim.fn.setenv("FZF_DEFAULT_COMMAND", "rg --files")
vim.cmd.colorscheme("base16-eighties")
require("nvim-autopairs").setup {
disable_filetype = {},
}
-- lsp
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', 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 }
-- Will jump to interface files in OCaml
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', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format {async = true } end, bufopts)
end
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local dartBinary
if vim.fn.has('win32') == 1 then
dartBinary = 'dart.bat'
else
dartBinary = 'dart'
end
require('lspconfig').dartls.setup {
--cmd = { "dart", "language-server", "--protocol=lsp", "--instrumentation-log-file=/usr/local/google/home/fujino/dart-lsp.log" },
cmd = {"dart", "language-server", "--protocol=lsp"},
on_attach = on_attach,
capabilities = capabilities,
-- https://github.com/dart-lang/sdk/blob/main/pkg/analysis_server/tool/lsp_spec/README.md
init_options = {
-- When set to true, workspace folders will be ignored and analysis will be performed based on the open files, as if no workspace was open at all. This allows opening large folders without causing them to be completely analyzed. Defaults to false.
onlyAnalyzeProjectsWithOpenFiles = true,
-- When set to false, completion will not include symbols that are not already imported into the current file. Defaults to true, though the client must additionally support workspace/applyEdit for these completions to be included.
suggestFromUnimportedLibraries = true,
closingLabels = true,
outline = true,
flutterOutline = true,
},
settings = {
dart = {
showTodos = false,
-- Whether to include code snippets (such as class, stful, switch) in code completion. When unspecified, snippets will be included.
enableSnippets = false,
},
},
}
require('lspconfig').bashls.setup {
on_attach = on_attach,
capabilities = capabilities,
}
require('lspconfig').gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
}
require('lspconfig').tsserver.setup {
on_attach = on_attach,
capabilities = capabilities,
}
require('lspconfig').ruby_lsp.setup {
on_attach = on_attach,
capabilities = capabilities,
}
require('lspconfig').zls.setup {
on_attach = on_attach,
capabilities = capabilities,
}
require('lspconfig').ocamllsp.setup {
on_attach = on_attach,
capabilities = capabilities,
filetypes = { 'ocaml' },
root_dir = require('lspconfig.util').root_pattern('*.opam'),
}
require('lspconfig').clangd.setup {
on_attach = on_attach,
capabilities = capabilities,
}
require('lspconfig').cmake.setup {
on_attach = on_attach,
capabilities = capabilities,
}
-- Auto-complete
local cmp = require 'cmp'
cmp.setup {
mapping = cmp.mapping.preset.insert({
['<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()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { 'i', 's' }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
})
}
-- Debug Adapter
-- https://github.com/mfussenegger/nvim-dap/blob/master/doc/dap.txt
local dap = require('dap')
dap.adapters.dart = {
type = "executable",
command = "dart",
args = {"debug_adapter"}
}
dap.configurations.dart = {
{
type = "dart",
request = "launch",
name = "Launch Dart Program",
program = "${workspaceFolder}/main.dart",
cwd = "${workspaceFolder}",
--args = {"run", "-d", "web-server"},
}
}
-- See :help dap-widgets
local cmd = vim.api.nvim_create_user_command
local widgets = require('dap.ui.widgets')
-- widgets.sidebar could be widgets.centered_float
cmd(
'DapShowScopes',
function()
widgets.sidebar(widgets.scopes).open()
end,
{}
)
cmd(
'DapShowFrames',
function()
widgets.sidebar(widgets.frames).open()
end,
{}
)
-- Syntaxes
-- autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) | execute 'cd' argv()[0] | endif
vim.api.nvim_create_autocmd(
"VimEnter",
{
pattern = "*",
command = "if argc() == 1 && isdirectory(argv()[0]) | execute 'cd' argv()[0] | endif",
}
)
vim.cmd([[
autocmd FileType python set shiftwidth=4 tabstop=4
autocmd FileType cs set shiftwidth=4 tabstop=4
autocmd FileType go set noexpandtab nosmarttab
]])