/
init.lua
282 lines (264 loc) · 9.54 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
local vim = vim
-- boot Plug
local Plug = vim.fn['plug#']
vim.call('plug#begin')
-- mason.nvm: installs and manages LSP & tools (outside of Plug)
Plug('williamboman/mason.nvim')
Plug('williamboman/mason-lspconfig.nvim')
-- UI
Plug('morhetz/gruvbox')
Plug('vim-airline/vim-airline')
-- features
Plug('scrooloose/nerdtree')
Plug('tpope/vim-fugitive')
Plug('airblade/vim-gitgutter')
-- telescope
Plug('nvim-lua/plenary.nvim')
Plug('nvim-telescope/telescope.nvim', { ['tag'] = '0.1.5' })
Plug('stevearc/dressing.nvim') -- improve the default vim.ui interfaces
-- LSP
Plug('neovim/nvim-lspconfig')
Plug('l3MON4D3/LuaSnip')
Plug('saadparwaiz1/cmp_luasnip') -- LusSnip completion source for nvim-cmp
Plug('hrsh7th/cmp-nvim-lsp') -- LSP source for nvim-cmp
Plug('hrsh7th/nvim-cmp') -- A Lua auto-completion plugin
Plug('hrsh7th/cmp-path') -- LSP cmp source for filesystem paths
Plug('hrsh7th/cmp-buffer') -- LSP cmp source for text in buffer(s)
-- code linting
Plug('mfussenegger/nvim-lint')
-- code highlighting
Plug('slashmili/alchemist.vim') -- Elixir Integration
Plug('HerringtonDarkholme/yats.vim') -- .tsx syntax highlighting
Plug('MaxMEllon/vim-jsx-pretty') -- .jsx syntax highlighting
Plug('editorconfig/editorconfig-vim')
Plug('hail2u/vim-css3-syntax')
Plug('elzr/vim-json')
Plug('elixir-lang/vim-elixir')
Plug('mhinz/vim-mix-format')
Plug('jparise/vim-graphql')
Plug('mustache/vim-mustache-handlebars')
Plug('vim-pandoc/vim-pandoc-syntax')
-- code formatting
Plug('stevearc/conform.nvim')
vim.call('plug#end')
-- vim options
vim.opt.ruler = true -- show the cursor position
vim.opt.selection = "exclusive" -- visual mode selection to exlusive (rather than inclusive)
vim.opt.clipboard = "unnamed" -- Use the OS clipboard by default (on versions compiled with `+clipboard`)
vim.opt.wildmenu = true -- Enhance command-line completion
vim.opt.backspace = "indent,eol,start" -- Allow backspace in insert mode
vim.opt.ttyfast = true -- optimize for fast terminal connections
vim.opt.gdefault = true -- Add the g flag to search/replace by default
vim.opt.encoding = "utf-8" -- use UTF-8
vim.opt.binary = true -- don't add empty newlines at the end of files
vim.opt.modeline = true -- Respect modeline in files
vim.opt.modelines = 4
vim.opt.exrc = true -- enable per-directory .vimrc files and disable unsafe commands in them
vim.opt.secure = true
vim.opt.number = true -- enable line numbers
vim.opt.tabstop = 4 -- tabs as wide as four spaces
vim.opt.shiftwidth = 4 -- make shift indent operation add four spaces
vim.opt.expandtab = true -- convert tabs to spaces upon tabpress
vim.opt.list = true
vim.opt.hlsearch = true -- highlight searches
vim.opt.incsearch = true -- highlight dynamically as pattern is typed
vim.opt.laststatus = 2 -- always show status line
vim.opt.mouse = "a" -- enable mouse in all modes
vim.opt.shortmess = "atI" -- don’t show the intro message when starting vim
vim.opt.showmode = true -- show the current mode
vim.opt.title = true -- show the filename in the window titlebar
vim.opt.showcmd = true -- show the (partial) command as it’s being typed
vim.opt.scrolloff = 4 -- start scrolling three lines before the horizontal window border
vim.opt.foldmethod = "indent" -- code folding
vim.opt.foldnestmax = 10
vim.opt.foldlevel = 2
vim.o.lcs = [[tab:▸\ ,trail:·,eol:↲,nbsp:_]] -- :help litchars
vim.g.mapleader = " " -- Change mapleader from "\" (default) to space
vim.cmd.syntax("on") -- enable syntax highlighting
vim.cmd.filetype("plugin indent on") --enable plugins
-- legacy shit
vim.cmd("set noeol nofoldenable nocursorline noerrorbells nostartofline")
vim.cmd("let &colorcolumn=join(range(120,666),',')") -- highlight at column 121
-- mason.nvim
require("mason").setup()
require('mason-lspconfig').setup({
ensure_installed = {
"bashls",
"cssls",
"cssmodules_ls",
"ember",
"elixirls",
"eslint",
"graphql",
"html",
"jsonls",
"tailwindcss",
"tsserver",
"vimls",
"yamlls",
},
automatic_installation = true, -- auto-install with lspconfig
})
-- conform.nvim for auto code formatting
local conform = require('conform')
local conformFormatOpts = {
async = false,
lsp_fallback = true,
timeout_ms = 500,
}
conform.setup({
formatters_by_ft = {
javascript = { { "prettierd", "prettier" } }, -- Use a sub-list to run only the first available formatter
typescript = { { "prettierd", "prettier" } },
javascriptreact = { "prettierd" },
typescriptreact = { "prettierd" },
css = { "prettierd" },
html = { "prettierd" },
json = { "prettierd" },
yaml = { "prettierd" },
markdown = { "prettierd" },
graphql = { "prettierd" },
},
format_on_save = conformFormatOpts,
})
vim.keymap.set({"n", "v"}, "<leader>mp", function() -- enable formatting on ' mp' keymap
conform.format(conformFormatOpts)
end, {desc = "Format file or range (in visual mode)"})
-- nvim-lint
local lint = require("lint")
lint.linters_by_ft = {
javascript = { "eslint", },
javascriptreact = { "eslint" },
typescript = { "eslint" },
typescriptreact = { "eslint" },
css = { "eslint" },
html = { "eslint" },
json = { "eslint" },
yaml = { "eslint" },
markdown = { "eslint" },
graphql = { "eslint" },
}
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end
})
vim.keymap.set({"n"}, "<leader>l", function() -- enable linting on ' l' keymap
lint.try_lint()
end, {desc = "Lint file"})
-- nvim-cmp for code completion
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
completion = {
completeopt = "menu,menuone,preview,noselect"
},
snippet = { -- configure how nvim-cmp interacts with snippet engine
expand = function(args)
luasnip.lsp_extend(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<Tab>'] = cmp.mapping(function(fallback) -- next suggestion
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback) -- previous suggestion
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
['<C-j>'] = cmp.mapping.scroll_docs(-4), -- scroll preview window up
['<C-k>'] = cmp.mapping.scroll_docs(4), -- scroll preview window down
['<C-Space>'] = cmp.mapping.complete(), -- show completion suggestions
['<CR>'] = cmp.mapping.confirm({ select = false }),
['<C-e>'] = cmp.mapping.abort(), -- close completion window
}),
sources = {
{ name = 'nvim_lsp' }, -- LSP
{ name = 'luasnip' }, -- snippets
{ name = 'buffer' }, -- text within buffer
{ name = 'path' }, -- file paths
},
})
-- Gruvbox color palette
vim.cmd.colorscheme("gruvbox")
vim.o.background = "dark"
-- vim-airline
vim.opt.guifont = "Source Code Pro for Powerline:h12"
vim.g["airline_detect_paste"] = 1 -- enable paste detection
vim.g["airline_powerline_fonts"] = 1
vim.g["airline#extensions#branch#enabled"] = 1 -- vim-airline enable branch "fugitive" extension
vim.g["airline#extensions#branch#empty_message"] = ''
vim.g["airline#extensions#branch#displayed_head_limit"] = 10
-- NERDTree
vim.keymap.set('n', '<leader>n', ':NERDTreeFocus<CR>', { noremap = true })
-- HerringtonDarkholme/yats.vim
vim.g["yats_host_keyword"] = 1 -- yats should handle specfic keywords
-- MaxMEllon/vim-jsx-pretty
vim.g["vim_jsx_pretty_disable_tsx"] = 1 -- let yats handle .tsx
-- NERDTree
vim.g["NERDTreeIgnore"] = { "^dist$", "^node_modules$" }
-- vim-mix-format set to run Elixir formatter upon save
vim.g["mix_format_on_save"] = 1
-- nvim-lspconfig
local lspconfig = require('lspconfig')
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local opts = { noremap = true, silent = true } -- useful keymap options
local on_attach = function(client, bufnr)
opts.buffer = bufnr
-- keybindings
opts.desc = "Show documentation for what is under cursor"
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
opts.desc = "Show LSP references"
vim.keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
opts.desc = "Go to declaration"
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
opts.desc = "Show LSP definitions"
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
opts.desc = "Show LSP type definitions"
vim.keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions
opts.desc = "Show line diagnostics"
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line
opts.desc = "Show buffer diagnostics"
vim.keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
client.server_capabilities.semanticTokensProvider = nil -- disable syntax highlighting (let other package do that)
end
-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()
local lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}
local servers = {
'bashls',
'tsserver',
'cssls',
'cssmodules_ls',
'ember',
'html',
'graphql',
'jsonls',
'tailwindcss',
'vimls',
'yamlls',
}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
end
if vim.fn.executable('volta') then
vim.g.node_host_prog = vim.trim(vim.fn.system('volta which neovim-node-host | tr -d "\n"'))
end