-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
392 lines (366 loc) · 11.5 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
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
-- map leader to <Space>
vim.keymap.set("n", " ", "<Nop>", { silent = true, remap = false })
vim.g.mapleader = " "
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",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local telescope = require('telescope')
local actions = require('telescope.actions')
telescope.setup {
pickers = {
find_files = {
hidden = true
}
},
extensions = {
live_grep_args = {
mappings = {
i = {
['<C-n>'] = actions.cycle_history_next,
['<C-p>'] = actions.cycle_history_prev,
},
},
},
},
}
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader><leader>', builtin.find_files, {})
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fs', builtin.lsp_document_symbols, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', function() builtin.buffers({ sort_mru = true }) end, {})
vim.keymap.set('n', '<leader>bb', function() builtin.buffers({ sort_mru = true }) end, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
vim.keymap.set('n', '<leader>f.',
':Telescope file_browser path=%:p:h select_buffer=true hidden=true<CR>', {})
vim.keymap.set('n', '<leader>.',
':Telescope file_browser path=%:p:h select_buffer=true hidden=true<CR>', {})
vim.keymap.set('n', '<leader>sb', ':Telescope current_buffer_fuzzy_find<CR>', {})
vim.keymap.set('n', '<leader>ss', ':Telescope current_buffer_fuzzy_find<CR>', {})
vim.keymap.set('n', '<leader>fbd',
function() builtin.find_files({ cwd = require('telescope.utils').buffer_dir() }) end,
{})
end
},
{
"nvim-telescope/telescope-file-browser.nvim",
dependencies = {
"nvim-telescope/telescope.nvim",
"nvim-lua/plenary.nvim"
},
config = function()
require("telescope").load_extension('file_browser')
end
},
{
'nvim-telescope/telescope-live-grep-args.nvim',
version = "^1.0.0",
dependencies = {
'nvim-telescope/telescope.nvim',
},
config = function()
require("telescope").load_extension("live_grep_args")
vim.keymap.set('n', '<leader>fG',
function() require("telescope").extensions.live_grep_args.live_grep_args() end, {})
end
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "fidl", "cpp", "rust", "markdown", "lua" },
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,
},
})
end
},
{
'hrsh7th/nvim-cmp',
dependencies = {
'neovim/nvim-lspconfig',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline',
'hrsh7th/cmp-vsnip',
'hrsh7th/vim-vsnip',
},
config = function()
local cmp = require('cmp')
cmp.setup({
view = {
entries = "custom" -- can be "custom", "wildmenu" or "native"
},
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<CR>"] = cmp.config.disable,
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
end
},
'nvim-lua/plenary.nvim',
{
'williamboman/mason.nvim',
config = true,
},
{
'neovim/nvim-lspconfig',
dependencies = {
'hrsh7th/cmp-nvim-lsp',
{
'williamboman/mason-lspconfig.nvim',
opts = {
-- TODO: pyright requires npm
ensure_installed = { "lua_ls", "rust_analyzer", "clangd", "starlark_rust" },
},
dependencies = {
'williamboman/mason.nvim',
}
}
},
config = function()
-- Capabilities for lspconfig.
-- Use default vim.lsp capabilities and apply some tweaks on capabilities.completion for nvim-cmp
local capabilities = vim.tbl_deep_extend("force",
vim.lsp.protocol.make_client_capabilities(),
require('cmp_nvim_lsp').default_capabilities()
)
-- Large workspace scanning may freeze the UI; see https://github.com/neovim/neovim/issues/23291
capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = false
-- Setup language servers.
local lspconfig = require('lspconfig')
lspconfig.pyright.setup {
capabilities = capabilities
}
lspconfig.clangd.setup {
capabilities = capabilities,
cmd = {
"clangd",
"-header-insertion=never",
}
}
-- local is_fuchsia = string.find(vim.loop.cwd() or "", "/fuchsia")
lspconfig.rust_analyzer.setup {
capabilities = capabilities,
-- Server-specific settings. See `:help lspconfig-setup`
settings = {
['rust-analyzer'] = {
diagnostics = {
enable = true,
remapPrefix = {
["../../"] = "~/fuchsia",
},
experimental = {
enable = true,
}
},
check = {
-- overrideCommand = { "fx", "clippy", "--all", "--raw"}
-- overrideCommand = { "fx", "clippy", "--all", "-f", "$saved_file"}
}
},
},
}
lspconfig.starlark_rust.setup {
capabilities = capabilities,
}
lspconfig.lua_ls.setup {
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then
return
end
client.config.settings.Lua = vim.tbl_deep_extend('force',
client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
-- library = {
-- vim.env.VIMRUNTIME
-- -- Depending on the usage, you might want to add additional paths here.
-- -- "${3rd}/luv/library"
-- -- "${3rd}/busted/library",
-- }
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {
format = {
enable = true,
-- Put format options here
-- NOTE: the value should be STRING!!
defaultConfig = {
indent_style = "space",
indent_size = "2",
}
},
}
}
}
end
},
{
'stevearc/overseer.nvim',
config = function()
require('overseer').setup()
vim.keymap.set('n', '<leader>pt', function() vim.cmd('OverseerRun') end, {})
end
},
{
'stevearc/oil.nvim',
opts = {},
config = function()
require("oil").setup({
view_options = {
show_hidden = true,
}
})
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
end
},
'airblade/vim-gitgutter',
'tpope/vim-fugitive',
'raimondi/delimitmate',
})
-- Theme
vim.cmd [[colorscheme eink]]
-- Git
vim.keymap.set('n', '<leader>gg', function() vim.cmd('Git') end, {})
-- Enable line numbers
vim.wo.number = true
-- Don't wrap lines
vim.wo.wrap = false
-- Terminal
vim.keymap.set('t', '<C-space>', '<C-\\><C-n>', {}) -- exit terminal mode
-- window keymap
vim.keymap.set('n', '<leader>wh', '<C-w>h', {})
vim.keymap.set('n', '<leader>wj', '<C-w>j', {})
vim.keymap.set('n', '<leader>wk', '<C-w>k', {})
vim.keymap.set('n', '<leader>wl', '<C-w>l', {})
-- 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,
},
}
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = {}
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', 'gh', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gk', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', '<leader>bf', function()
vim.lsp.buf.format { async = true }
end, opts)
-- LSP format on save
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
callback = function()
vim.lsp.buf.format()
end,
})
-- misc keymaps
vim.keymap.set('n', '<leader>bp', '<C-^>', opts)
-- FIDL
vim.filetype.add({ extension = { fidl = "fidl" } })
-- highlight trailing whitespace
vim.opt.listchars = { eol = '↵', trail = '~', tab = '>-', nbsp = '␣' }
vim.cmd [[set notermguicolors]]
vim.cmd [[set bg=light]]