-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.lua
More file actions
369 lines (298 loc) · 12.8 KB
/
init.lua
File metadata and controls
369 lines (298 loc) · 12.8 KB
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
local plug = vim.fn["plug#"]
vim.call("plug#begin", "~/.vim/plugged")
-- Filetype
plug("nathom/filetype.nvim")
-- Mason
plug("williamboman/mason.nvim")
plug("williamboman/mason-lspconfig.nvim")
--LSP
plug("neovim/nvim-lspconfig")
plug("lukas-reineke/lsp-format.nvim")
-- Treesitter
plug("nvim-treesitter/nvim-treesitter", {["do"] = ":TSUpdate"})
-- Easy motion
plug("Lokaltog/vim-easymotion")
-- Nvim Tree
plug("nvim-tree/nvim-web-devicons")
plug("nvim-tree/nvim-tree.lua")
-- Plenary
plug("nvim-lua/plenary.nvim")
-- Ripgrep
plug("BurntSushi/ripgrep")
-- Telescope
plug("nvim-telescope/telescope.nvim", { ["tag"] = "*" })
plug("nvim-telescope/telescope-fzf-native.nvim", { ["do"] = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release" })
plug("sharkdp/fd")
-- Vim test
plug("vim-test/vim-test")
-- Color themes
plug("marko-cerovac/material.nvim")
plug("ellisonleao/gruvbox.nvim")
plug("vigoux/oak")
plug("jnurmine/Zenburn")
plug("petobens/colorish")
plug("dracula/vim", { ["as"] = "dracula" })
plug("NLKNguyen/papercolor-theme")
plug("haishanh/night-owl.vim")
plug("shaunsingh/nord.nvim")
vim.call("plug#end")
------------- Color Schemes ----------------
vim.opt.termguicolors = true
vim.cmd.colorscheme("gruvbox")
-- Disable side scrolling
vim.opt.wrap = true -- Enable line wrapping
vim.opt.sidescroll = 0 -- Disable horizontal scrolling
vim.opt.linebreak = true -- Wrap at word boundaries, not mid-word
vim.opt.breakindent = true -- Preserve indentation in wrapped lines
vim.opt.colorcolumn = "80" -- Show a visual guide at column 80
-- Disable horizontal scrolling via trackpad/mouse
vim.keymap.set({'n', 'i', 'v'}, '<ScrollWheelLeft>', '<Nop>', { noremap = true })
vim.keymap.set({'n', 'i', 'v'}, '<ScrollWheelRight>', '<Nop>', { noremap = true })
-- Map Leader to space
vim.keymap.set("n", "<Space>", "<Nop>", { silent = true, remap = false })
vim.g.mapleader = " "
-- Relative line numbers
vim.opt.relativenumber = true
-- Keymap to sort inside paragraph
vim.keymap.set('n', '<Leader>ss', '!ip sort<CR>', { silent = false })
-- Shortcut to open this file
vim.keymap.set('n', '<Leader>v', function() vim.cmd.edit('~/.config/nvim/init.lua') end, { silent = false })
-- Use jj instead of esc
vim.keymap.set("i", "jj", "<ESC>", { silent = true })
-- Telescore binds
vim.keymap.set('n', '<Leader>f', function() vim.cmd('Telescope find_files') end)
vim.keymap.set('n', '<Leader>r', function() vim.cmd('Telescope live_grep') end)
vim.keymap.set('n', '<Leader>b', function() vim.cmd('Telescope buffers') end)
-- Vim test
vim.keymap.set("n", '<Leader><Leader>t', function() vim.cmd('TestNearest') end)
vim.keymap.set("n", '<Leader><Leader>a', function() vim.cmd('TestFile') end)
vim.keymap.set("n", '<Leader><Leader>l', function() vim.cmd('TestLast') end)
-- NvimTree toggle
require("nvim-tree").setup()
vim.keymap.set("n", '<Leader>n', function() vim.cmd('NvimTreeToggle') end)
-- Panel splitting
vim.keymap.set("n", '<Leader>vs', function() vim.cmd('execute "vsplit " bufname("#")') end)
vim.keymap.set("n", '<Leader>sp', function() vim.cmd('execute "split " bufname("#")') end)
-- Use <C-s> as save
local function save()
vim.cmd.write()
vim.print("Saved")
end
vim.keymap.set({"n", "v", "o", "i"}, "<C-s>", save)
-- buffers
vim.keymap.set("", "gn", vim.cmd.bnext)
vim.keymap.set("", "gp", vim.cmd.bprev)
vim.keymap.set("n", "<Leader>bd", ":bp<bar>sp<bar>bn<bar>bd<CR>")
----------- window navigation
function wincmd(direction)
return function()
vim.cmd.wincmd(direction)
end
end
vim.keymap.set("n", "<C-k>", wincmd("k"), { silent = true })
vim.keymap.set("n", "<C-j>", wincmd("j"), { silent = true })
vim.keymap.set("n", "<C-h>", wincmd("h"), { silent = true })
vim.keymap.set("n", "<C-l>", wincmd("l"), { silent = true })
-- Don't give the intro message when starting
vim.opt.shortmess:append({ I = true })
-- use line numbers
vim.o.number = true
-- Do not highlight all search hits
vim.o.hlsearch = false
-- vim-better-whitespace'
vim.g.better_whitespace_enabled = 0
vim.g.strip_whitespace_on_save = 1
vim.g.strip_whitespace_confirm = 0
-- Enable mouse support in normal and visual modes.
vim.o.mouse = 'nv'
-- Use system clipboard by default
vim.o.clipboard = 'unnamedplus'
-- Tab counts for 4 spaces
vim.o.tabstop = 4
-- Autoindent (>>, <<) will use tabstop value
vim.o.shiftwidth = 0
-- Insert 4 spaces instead of a tab char when pressing the tab key in insert modes
vim.o.expandtab = true
-- Disable swapfiles
vim.o.swapfile = false
-- Disable automatically adding comment leader to the next line
vim.api.nvim_create_autocmd('FileType', {
pattern = '*',
callback = function()
vim.opt.formatoptions:remove({'r', 'o'})
end
})
-- Allow recursive find
vim.opt.path:append('**')
-- No large banner at the top of netwr
vim.g.netrw_banner = 0
-- Open diffs in vertical splits by default
vim.opt.diffopt:append({ internal = false })
vim.opt.diffopt:remove({ 'vertical' })
-- Grep
vim.opt.grepprg = 'grep -RIn $* .'
vim.keymap.set('n', '<Leader>gg', ':grep -r ')
-- keymaps to yank file name
vim.keymap.set('n', '<Leader>yff', ':let @+ = expand("%")<cr>', { silent = true })
vim.keymap.set('n', '<Leader>yf', ':let @+ = expand("%:t")<cr>', { silent = true })
-- Shortcut to open workingMemory.txt
vim.keymap.set('n', '<Leader>wm', function() vim.cmd.edit('~/workingMemory.txt') end, { silent = false })
-- Try to prevent bad habits like using the arrow keys for movement. This is
-- not the only possible bad habit. For example, holding down the h/j/k/l keys
-- for movement, rather than using more efficient movement commands, is also a
-- bad habit. The former is enforceable through a .vimrc, while we don't know
-- how to prevent the latter.
vim.keymap.set('n', '<Left>', ':echoe "Use h"<CR>')
vim.keymap.set('n', '<Right>', ':echoe "Use l"<CR>')
vim.keymap.set('n', '<Up>', ':echoe "Use k"<CR>')
vim.keymap.set('n', '<Down>', ':echoe "Use j"<CR>')
-- Shortcuts to navigate the buffer list
vim.keymap.set('n', ']b', vim.cmd.bnext, { noremap = true, silent = true })
vim.keymap.set('n', '[b', vim.cmd.bprev, { noremap = true, silent = true })
-- Open the altfile
vim.keymap.set('n', '[a', function() vim.cmd.edit("#") end, { noremap = true, silent = true })
-- Shortcuts for navigating quickfix list
vim.keymap.set('n', ']q', ":cnext<CR>", { noremap = true, silent = true })
vim.keymap.set('n', '[q', ":cprev<CR>", { noremap = true, silent = true })
-- Git conflict marker shortcuts
vim.keymap.set('n', '<Leader><', '/<<<<<<<<CR>', { silent = true })
vim.keymap.set('n', '<Leader>>', '/>>>>>>><CR>', { silent = true })
vim.keymap.set('n', '<Leader>=', '/=======<CR>', { silent = true })
-- from https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
-- Multipurpose tab key
function InsertTab()
if (has_words_before()) then
-- There's an identifier before the cursor, so complete the identifier.
return "<c-n>"
end
return "<tab>"
end
vim.keymap.set('i', '<tab>', InsertTab, { expr = true })
vim.keymap.set('i', '<s-tab>', '<c-p>', { noremap = true })
-- telescope
require('telescope').setup({
pickers = {
colorscheme = {
enable_preview = true
}
},
extensions = {
fzf = {}
}
})
-- Treesitter config
require("nvim-treesitter.config").setup {
-- A list of parser names, or "all" (the listed parsers MUST always be installed)
ensure_installed = { "elixir", "elm", "rust", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
-- List of parsers to ignore installing (or "all")
ignore_install = { "javascript" },
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
highlight = {
enable = true,
-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
-- the name of the parser)
-- list of language that will be disabled
disable = { "c" },
-- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
-- 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,
},
}
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'elixir' },
callback = function() vim.treesitter.start() end,
})
-- Mason config
require("mason").setup()
require("mason-lspconfig").setup()
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('my.lsp', {}),
callback = function(args)
-- always show a sign column of width 1
vim.wo.signcolumn = "yes:1"
local opts = { noremap=true, silent=true }
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
-- "gO" is mapped in Normal mode to vim.lsp.buf.document_symbol()
vim.keymap.set('n', '<Leader>d', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[w', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']w', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<Leader>q', vim.diagnostic.setqflist, opts)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
-- "gri" is mapped in Normal mode to vim.lsp.buf.implementation()
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
-- CTRL-S is mapped in Insert mode to vim.lsp.buf.signature_help()
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
-- "grt" is mapped in Normal mode to vim.lsp.buf.type_definition()
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
-- "grn" is mapped in Normal mode to vim.lsp.buf.rename()
vim.keymap.set('n', '<Leader>r', vim.lsp.buf.rename, opts)
-- "gra" is mapped in Normal and Visual mode to vim.lsp.buf.code_action()
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, opts)
-- "grr" is mapped in Normal mode to vim.lsp.buf.references()
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
if not client:supports_method('textDocument/willSaveWaitUntil') and client:supports_method('textDocument/formatting') then
vim.api.nvim_create_autocmd('BufWritePre', {
group = vim.api.nvim_create_augroup('my.lsp', { clear = false }),
buffer = args.buf,
callback = function()
vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 })
end
})
end
end
})
-- configure diagnostics
vim.diagnostic.config({
virtual_text = false,
underline = { severity = vim.diagnostic.severity.ERROR },
update_in_insert = false,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = '>',
[vim.diagnostic.severity.WARN] = 'W',
[vim.diagnostic.severity.INFO] = 'I',
[vim.diagnostic.severity.HINT] = 'H',
},
}
})
-- LSP format config
require("lsp-format").setup {}
-- LSP config
return {
filetypes = { 'elixir', 'eelixir', 'heex', 'surface' },
cmd = { 'expert', '--stdio' },
root_dir = function(bufnr, on_dir)
local fname = vim.api.nvim_buf_get_name(bufnr)
--- Elixir workspaces may have multiple `mix.exs` files, for an "umbrella" layout or monorepo.
--- So we specify `limit=2` and treat the highest one (if any) as the root of an umbrella app.
local matches = vim.fs.find({ 'mix.exs' }, { upward = true, limit = 2, path = fname })
local child_or_root_path, maybe_umbrella_path = unpack(matches)
local root_dir = vim.fs.dirname(maybe_umbrella_path or child_or_root_path)
on_dir(root_dir)
end,
}