aboutsummaryrefslogtreecommitdiffstats
path: root/init.lua
diff options
context:
space:
mode:
authorphilw <dscr@duck.com>2025-01-13 17:58:09 +0100
committerphilw <dscr@duck.com>2025-01-13 17:58:09 +0100
commit86598b431645895bd808eb2c15ba6b1eb4628a6c (patch)
tree69ba4f810ebd99866c68e7c69fa4bee75fd7bf4e /init.lua
parent5f71d25b9fd26b5eee7858e126a5d143e850fc02 (diff)
downloadneovim-86598b431645895bd808eb2c15ba6b1eb4628a6c.tar.gz
neovim-86598b431645895bd808eb2c15ba6b1eb4628a6c.zip
Rewrite config in pure lua
Diffstat (limited to '')
-rw-r--r--init.lua412
1 files changed, 212 insertions, 200 deletions
diff --git a/init.lua b/init.lua
index d5e104d..d8813b9 100644
--- a/init.lua
+++ b/init.lua
@@ -1,6 +1,8 @@
1---@diagnostic disable: undefined-global, 1---@diagnostic disable: undefined-global,
2local option = vim.opt 2local option = vim.opt
3local keymap = vim.keymap 3local keymap = vim.keymap
4local api = vim.api
5local fn = vim.fn
4 6
5vim.loader.enable() 7vim.loader.enable()
6 8
@@ -9,11 +11,15 @@ vim.g.netrw_liststyle = 3
9vim.g.netrw_altv = 0 11vim.g.netrw_altv = 0
10vim.g.netrw_winsize = 25 12vim.g.netrw_winsize = 25
11vim.g.netrw_browse_split = 4 13vim.g.netrw_browse_split = 4
12
13vim.g.rustfmt_autosave = 1 14vim.g.rustfmt_autosave = 1
14vim.g.mkdp_auto_start = 1 15vim.g.mkdp_auto_start = 1
16vim.g.vimtex_view_method = "zathura"
17vim.g.vimtex_compiler_method = "latexmk"
18vim.g.vimtex_quickfix_mode = 0
19vim.g.tex_conceal = "abdmg"
20vim.g.tex_flavor = "latex"
21vim.g.gitgutter_set_sign_backgrounds = 1
15 22
16--Basic Editor Setup
17option.nu = true 23option.nu = true
18option.tabstop = 2 24option.tabstop = 2
19option.softtabstop = 2 25option.softtabstop = 2
@@ -31,232 +37,238 @@ option.signcolumn = "number"
31option.autoindent = true 37option.autoindent = true
32option.clipboard = "unnamedplus" 38option.clipboard = "unnamedplus"
33option.termguicolors = true 39option.termguicolors = true
34option.fillchars = 'eob: ' 40option.fillchars = "eob: "
35option.autoindent = true 41option.autoindent = true
36option.lazyredraw = false 42option.lazyredraw = false
37option.updatetime = 300 43option.updatetime = 300
38option.timeoutlen = 500 44option.timeoutlen = 500
39 45
40 46
41vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]] 47-- Format on save
42 48api.nvim_create_autocmd(
43vim.cmd([[ 49 "BufWritePre",
44augroup RunPfOnSave 50 {
45autocmd! 51 callback = function()
46autocmd BufWritePost *.js,*.ts,*.jsx,*json,*.tsx,*.css,*.html,*.yaml,*.md silent! !prettier --write % 52 vim.lsp.buf.format()
47autocmd BufWritePost *.tex silent! :VimtexCompile 53 end
48augroup END 54 }
49]]) 55)
50 56
57-- Run prettier and compile tex on save
58api.nvim_create_augroup("RunPfOnSave", {clear = true})
59api.nvim_create_autocmd(
60 "BufWritePost",
61 {
62 group = "RunPfOnSave",
63 pattern = {"*.js", "*.ts", "*.jsx", "*.json", "*.tsx", "*.css", "*.html", "*.yaml", "*.md"},
64 command = "silent! !prettier --write %"
65 }
66)
67api.nvim_create_autocmd(
68 "BufWritePost",
69 {
70 group = "RunPfOnSave",
71 pattern = "*.tex",
72 command = "silent! VimtexCompile"
73 }
74)
51 75
52vim.cmd([[ 76-- Auto-delete Netrw hidden buffers
53augroup AutoDeleteNetrwHiddenBuffers 77api.nvim_create_augroup("AutoDeleteNetrwHiddenBuffers", {clear = true})
54au! 78api.nvim_create_autocmd(
55au FileType netrw setlocal bufhidden=wipe 79 "FileType",
56augroup end 80 {
57]]) 81 group = "AutoDeleteNetrwHiddenBuffers",
82 pattern = "netrw",
83 callback = function()
84 vim.opt_local.bufhidden = "wipe"
85 end
86 }
87)
58 88
59vim.cmd([[ 89-- Toggle VExplorer
60function! ToggleVExplorer() 90function ToggleVExplorer()
61if exists("t:expl_buf_num") 91 if vim.t.expl_buf_num then
62 let expl_win_num = bufwinnr(t:expl_buf_num) 92 local expl_win_num = fn.bufwinnr(vim.t.expl_buf_num)
63 if expl_win_num != -1 93 if expl_win_num ~= -1 then
64 let cur_win_id = win_getid() 94 local cur_win_id = fn.win_getid()
65 exec expl_win_num . 'windo close' 95 vim.cmd(expl_win_num .. "windo close")
66 let prev_win_num = win_id2win(cur_win_id) 96 local prev_win_num = fn.win_id2win(cur_win_id)
67 if prev_win_num != 0 97 if prev_win_num ~= 0 then
68 exec prev_win_num . 'wincmd w' 98 vim.cmd(prev_win_num .. "wincmd w")
69 endif 99 end
70 endif 100 end
71 unlet t:expl_buf_num 101 vim.t.expl_buf_num = nil
72 else 102 else
73 exec '1wincmd w' 103 vim.cmd("1wincmd w")
74 Vexplore 104 vim.cmd("Vexplore")
75 let t:expl_buf_num = bufnr("%") 105 vim.t.expl_buf_num = fn.bufnr("%")
76 endif 106 end
77 endfunction 107end
78 ]]) 108
79 109local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
80 110if not vim.loop.fs_stat(lazypath) then
81 -- Gui options 111 vim.fn.system(
82 vim.g.vimtex_view_method = "zathura" 112 {
83 vim.g.vimtex_compiler_method = "latexmk" 113 "git",
84 vim.g.vimtex_quickfix_mode = 0 114 "clone",
85 vim.g.tex_conceal = "abdmg" 115 "--filter=blob:none",
86 vim.g.tex_flavor = "latex" 116 "https://github.com/folke/lazy.nvim.git",
87 vim.g.gitgutter_set_sign_backgrounds = 1 117 "--branch=stable",
88 118 lazypath
89 119 }
90 local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" 120 )
91 if not vim.loop.fs_stat(lazypath) then 121end
92 vim.fn.system({
93 "git",
94 "clone",
95 "--filter=blob:none",
96 "https://github.com/folke/lazy.nvim.git",
97 "--branch=stable",
98 lazypath,
99 })
100 end
101 122
102 vim.opt.rtp:prepend(lazypath) 123vim.opt.rtp:prepend(lazypath)
103 require("lazy").setup({ 124require("lazy").setup(
125 {
104 "airblade/vim-gitgutter", 126 "airblade/vim-gitgutter",
105 {"lervag/vimtex", lazy = true}, 127 {"lervag/vimtex", lazy = true},
106 "norcalli/nvim-colorizer.lua", 128 {"norcalli/nvim-colorizer.lua"},
107 "nvim-treesitter/nvim-treesitter", 129 "nvim-treesitter/nvim-treesitter",
108 { 130 {
109 "neovim/nvim-lspconfig", 131 "neovim/nvim-lspconfig",
110 lazy = false, 132 lazy = false,
111 dependencies = { 133 dependencies = {
112 { "ms-jpq/coq_nvim", branch = "coq" }, 134 {"ms-jpq/coq_nvim", branch = "coq"},
113 { "ms-jpq/coq.artifacts", branch = "artifacts" }, 135 {"ms-jpq/coq.artifacts", branch = "artifacts"},
114 { 'ms-jpq/coq.thirdparty', branch = "3p" }, 136 {"ms-jpq/coq.thirdparty", branch = "3p"},
115 "williamboman/mason.nvim", 137 {"williamboman/mason.nvim"},
116 "williamboman/mason-lspconfig.nvim", 138 {"williamboman/mason-lspconfig.nvim"}
117 }, 139 },
118 init = function() 140 init = function()
119 vim.g.coq_settings = { 141 vim.g.coq_settings = {auto_start = "shut-up"}
120 auto_start = 'shut-up' 142 end
121 }
122 end,
123 config = function()
124 end,
125 }, 143 },
126 'nvim-telescope/telescope.nvim',
127 lazy = true,
128 tag = '0.1.5',
129 dependencies = { 'nvim-lua/plenary.nvim' },
130 { 144 {
131 'nvim-telescope/telescope-fzf-native.nvim', 145 "nvim-telescope/telescope.nvim",
132 lazy = true, 146 lazy = false,
133 build = 147 tag = "0.1.5",
134 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build', 148 dependencies = {"nvim-lua/plenary.nvim"}
135 keys = { 149 },
136 { "<leader>/", false },
137 { "<leader>f", "<cmd>Telescope find_files<cr>", desc = "Find Files" },
138 { "<leader>g", "<cmd>Telescope live_grep<cr>", desc = "Grep" },
139 { "<leader>b", "<cmd>Telescope buffers<cr>", desc = "Grep" },
140 { "<leader>s", "<cmd>Telescope buffers<cr>", desc = "Grep" },
141 }
142 }},
143 { 150 {
144 'windwp/nvim-autopairs', 151 "nvim-telescope/telescope-fzf-native.nvim",
145 event = "InsertEnter", 152 lazy = false,
146 opts = {} 153 build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build",
154 },
155 {
156 "windwp/nvim-autopairs",
157 event = "InsertEnter",
158 opts = {}
147 } 159 }
160 }
148) 161)
162require("colorizer").setup()
149 163
150 require("colorizer").setup() 164vim.api.nvim_create_autocmd(
151 165 "BufWritePre",
152 vim.api.nvim_create_autocmd("BufWritePre", { 166 {
153 callback = function() 167 callback = function()
154 vim.lsp.buf.format() 168 vim.lsp.buf.format()
155 end, 169 end
156 }) 170 }
171)
157 172
158 local lsp_servers = { 173local lsp_servers = {
159 rust_analyzer = { 174 rust_analyzer = {
160 imports = { 175 imports = {
161 granularity = { 176 granularity = {
162 group = 'module', 177 group = "module"
163 }, 178 },
164 prefix = 'self', 179 prefix = "self"
165 }, 180 },
166 cargo = { 181 cargo = {
167 buildScripts = { 182 buildScripts = {
168 enable = true, 183 enable = true
169 }, 184 }
170 },
171 procMacro = {
172 enable = true,
173 },
174 }, 185 },
175 } 186 procMacro = {
187 enable = true
188 }
189 }
190}
176 191
177 require("mason").setup({ 192require("mason").setup(
193 {
178 ui = { 194 ui = {
179 icons = { 195 icons = {
180 package_installed = "✓", 196 package_installed = "✓",
181 package_pending = "➜", 197 package_pending = "➜",
182 package_uninstalled = "✗" 198 package_uninstalled = "✗"
183 } 199 }
184 } 200 }
185 }) 201 }
186 202)
187 local server_maps = function(opts)
188 end
189
190 for lsp, settings in pairs(lsp_servers) do
191 require("lspconfig")[lsp].setup(coq.lsp_ensure_capabilities({
192 on_attach = function(_, buffer)
193 server_maps({ buffer = buffer })
194 end,
195 settings = settings,
196 }))
197 end
198
199 vim.cmd([[
200 highlight GitGutterAdd ctermbg=none guibg=none
201 highlight GitGutterDelete guibg=none ctermbg=none
202 highlight GitGutterChange guibg=none ctermbg=none
203 highlight GitGutterChangeAdd guibg=none ctermbg=none
204 highlight GitGutterChangeDelete guibg=none ctermbg=none
205 highlight NonText guifg=none
206 highlight EndOfBuffer ctermfg=none ctermbg=none
207 highlight Normal ctermbg=none guibg=none
208 highlight signcolumn ctermbg=none guibg=none
209 highlight StatusLine ctermbg=none guibg=none
210 highlight DiagnosticError ctermbg=none guibg=none
211 highlight DiagnosticWarn ctermbg=none guibg=none
212 highlight DiagnosticInfo ctermbg=none guibg=none
213 highlight DiagnosticHint ctermbg=none guibg=none
214 highlight Pmenu ctermbg=none guibg=none
215
216 highlight DiagnosticVirtualError ctermbg=none guibg=none
217 highlight DiagnosticVirtualWarn ctermbg=none guibg=none
218 highlight DiagnosticVirtualInfo ctermbg=none guibg=none
219 highlight DiagnosticVirtualHint ctermbg=none guibg=none
220
221 highlight LspFloatWinNormal ctermbg=none guibg=none
222 highlight NormalFloat ctermbg=none guibg=none
223
224 highlight LineNr ctermbg=none guibg=none
225 highlight StatusLineNc ctermbg=none guibg=none
226 highlight StatusLineNc ctermfg=none guifg=none
227 highlight StatusLine ctermbg=none guibg=none
228 highlight StatusLine ctermfg=none guifg=none
229
230 highlight NvimTreeWinSeparator ctermfg=none guifg=none
231 highlight CursorColumn ctermfg=none guifg=none
232 highlight CursorLine ctermbg=none guibg=none
233
234 highlight VertSplit ctermbg=none guibg=none
235
236 highlight DiagnosticVirtualTextError ctermbg=none guibg=none
237 highlight DiagnosticVirtualTextWarn ctermbg=none guibg=none
238 highlight DiagnosticVirtualTextInfo ctermbg=none guibg=none
239 highlight DiagnosticVirtualTextHint ctermbg=none guibg=none
240 ]])
241
242
243
244 vim.g.mapleader = " "
245 keymap.set("n", "<leader>e", "<cmd>:call ToggleVExplorer() <cr>")
246 keymap.set("n", "<leader>z", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
247 keymap.set("n", "<leader>a", "ggVG")
248 keymap.set("n", "<leader>y", "cc")
249 keymap.set("n", "<C-c>", "yy")
250 keymap.set("n", "<C-v>", "p")
251 keymap.set("n", "<C-z>", "u")
252 keymap.set("v", "J", ":m '>+1<CR>gv=gv")
253 keymap.set("n", "j", "5j")
254 keymap.set("n", "k", "5k")
255 keymap.set("v", "K", ":m '<-2<CR>gv=gv")
256 keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<cr>")
257 keymap.set("n", "<leader>f", "<cmd>Telescope find_files<cr>")
258 keymap.set("n", "<leader>g", "<cmd>Telescope live_grep<cr>")
259 keymap.set("n", "<leader>t", "<cmd>Lspsaga term_toggle <cr>")
260 keymap.set("n", "<leader>d", vim.lsp.buf.definition, opts) -- goto def
261 keymap.set("n", "<leader>k", vim.lsp.buf.hover, opts)
262 203
204local server_maps = function(opts)
205end
206
207for lsp, settings in pairs(lsp_servers) do
208 require("lspconfig")[lsp].setup(
209 coq.lsp_ensure_capabilities(
210 {
211 on_attach = function(_, buffer)
212 server_maps({buffer = buffer})
213 end,
214 settings = settings
215 }
216 )
217 )
218end
219
220local highlights = {
221 {"GitGutterAdd", {bg = "none"}},
222 {"GitGutterDelete", {bg = "none"}},
223 {"GitGutterChange", {bg = "none"}},
224 {"GitGutterChangeAdd", {bg = "none"}},
225 {"GitGutterChangeDelete", {bg = "none"}},
226 {"NonText", {fg = "none"}},
227 {"EndOfBuffer", {fg = "none", bg = "none"}},
228 {"Normal", {bg = "none"}},
229 {"SignColumn", {bg = "none"}},
230 {"StatusLine", {bg = "none", fg = "none"}},
231 {"StatusLineNc", {bg = "none", fg = "none"}},
232 {"NvimTreeWinSeparator", {fg = "none"}},
233 {"CursorColumn", {fg = "none"}},
234 {"CursorLine", {bg = "none"}},
235 {"VertSplit", {bg = "none"}},
236 {"DiagnosticError", {bg = "none"}},
237 {"DiagnosticWarn", {bg = "none"}},
238 {"DiagnosticInfo", {bg = "none"}},
239 {"DiagnosticHint", {bg = "none"}},
240 {"Pmenu", {bg = "none"}},
241 {"DiagnosticVirtualTextError", {bg = "none"}},
242 {"DiagnosticVirtualTextWarn", {bg = "none"}},
243 {"DiagnosticVirtualTextInfo", {bg = "none"}},
244 {"DiagnosticVirtualTextHint", {bg = "none"}},
245 {"LspFloatWinNormal", {bg = "none"}},
246 {"NormalFloat", {bg = "none"}},
247 {"LineNr", {bg = "none"}},
248 {"DiagnosticVirtualError", {bg = "none"}},
249 {"DiagnosticVirtualWarn", {bg = "none"}},
250 {"DiagnosticVirtualInfo", {bg = "none"}},
251 {"DiagnosticVirtualHint", {bg = "none"}}
252}
253
254for _, hl in ipairs(highlights) do
255 vim.api.nvim_set_hl(0, hl[1], hl[2])
256end
257
258vim.g.mapleader = " "
259
260keymap.set("n", "<leader>e", ToggleVExplorer, {desc = "Toggle VExplorer"})
261keymap.set("n", "<leader>z", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
262keymap.set("n", "<leader>a", "ggVG")
263keymap.set("n", "<leader>y", "cc")
264keymap.set("n", "<C-c>", "yy")
265keymap.set("n", "<C-v>", "p")
266keymap.set("n", "<C-z>", "u")
267keymap.set("v", "J", ":m '>+1<CR>gv=gv")
268keymap.set("n", "j", "5j")
269keymap.set("n", "k", "5k")
270keymap.set("v", "K", ":m '<-2<CR>gv=gv")
271keymap.set("n", "<leader>f", "<cmd>Telescope find_files<cr>")
272keymap.set("n", "<leader>g", "<cmd>Telescope live_grep<cr>")
273keymap.set("n", "<leader>d", vim.lsp.buf.definition, opts)
274keymap.set("n", "<leader>k", vim.lsp.buf.hover, opts)