this repo has no description
at master 19 kB view raw
1-- https://neovim.io/doc/user/options.html#options 2vim.o.autowrite = true 3vim.o.clipboard = "unnamedplus" 4vim.o.colorcolumn = "100" 5vim.o.completeopt = "fuzzy,menuone,noinsert,noselect,popup" 6vim.o.confirm = true 7vim.o.ignorecase = true 8vim.o.inccommand = "split" 9vim.o.incsearch = true 10vim.o.mousefocus = true 11vim.o.scrolloff = 4 12vim.o.shortmess = "aoOstTWAIcC" 13vim.o.sidescrolloff = 4 14vim.o.smartcase = true 15vim.o.smarttab = true 16vim.o.termguicolors = true 17vim.o.updatetime = 300 18vim.o.wildignorecase = true 19vim.o.wildmode = "longest,list:longest,full" 20 21vim.wo.breakindent = true 22vim.wo.foldlevel = 99 23vim.wo.number = true 24-- vim.wo.spell = true 25vim.wo.statusline = "%-F %-r %-m %= %{&fileencoding} | %y | %3.l/%3.L:%3.c" 26 27vim.bo.copyindent = true 28vim.bo.expandtab = true 29vim.bo.modeline = false 30vim.bo.shiftwidth = 0 31vim.bo.smartindent = true -- tbd: messes with yaml? 32vim.bo.swapfile = false 33vim.bo.tabstop = 4 34vim.bo.undofile = true 35-- 36-- indenting 37local ft_tab_width = { 38 [2] = { "html", "javascript", "markdown", "toml", "yaml" }, 39 [8] = { "go" }, 40} 41for k, v in pairs(ft_tab_width) do 42 vim.api.nvim_create_autocmd("FileType", { 43 pattern = v, 44 callback = function() 45 vim.opt_local.shiftwidth = k 46 vim.opt_local.softtabstop = k 47 vim.opt_local.tabstop = k 48 end, 49 }) 50end 51 52-- 53-- common typo 54vim.keymap.set("c", "WQ", "wq", { desc = "write and quit" }) 55vim.keymap.set("c", "Wq", "wq", { desc = "write and quit" }) 56-- easier to remember delete without yank 57vim.keymap.set("v", "s", '"_d', { desc = "delete selection without yank" }) 58vim.keymap.set("n", "ss", '"_dd', { desc = "delete line without yank" }) 59-- less shifting 60vim.keymap.set("n", ";", ":", { silent = true }) 61 62-- :W write with sudo 63vim.api.nvim_create_user_command("W", function() 64 local tmpfilename = os.tmpname() 65 local tmpfile = io.open(tmpfilename, "w") 66 if not tmpfile then 67 vim.api.nvim_echo({ { "failed to open tmp file" }, { tmpfilename } }, false, { 68 err = true 69 }) 70 return 71 end 72 for _, line in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do 73 tmpfile:write(line .. "\n") 74 end 75 tmpfile:close() 76 local curfilename = vim.api.nvim_buf_get_name(0) 77 os.execute(string.format("sudo tee %s < %s > /dev/null", curfilename, tmpfilename)) 78 vim.cmd([[ edit! ]]) 79 os.remove(tmpfilename) 80end, {}) 81 82vim.api.nvim_create_autocmd("BufWritePre", { 83 pattern = "*", 84 callback = function() 85 for i, line in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do 86 local trimmed = string.gsub(line, "%s+$", "") 87 vim.api.nvim_buf_set_lines(0, i - 1, i, false, { trimmed }) 88 end 89 end, 90}) 91vim.api.nvim_create_autocmd("BufWritePre", { 92 pattern = { "*.md" }, 93 command = "%!prettier --parser markdown", 94}) 95 96-- setup remote copy/paste through ssh osc52 97if vim.env.SSH_CONNECTION ~= nil then 98 vim.g.clipboard = { 99 name = "osc52clip", 100 copy = { 101 ["+"] = "osc52clip copy", 102 }, 103 paste = { 104 ["+"] = "osc52clip paste", 105 }, 106 } 107 108 local config_dir = vim.env.XDG_CONFIG_HOME or "~/.config" 109 local bin_dir = config_dir .. "/bin" 110 local osc52clip = io.open(bin_dir .. "/osc52clip", "w") 111 if osc52clip ~= nil then 112 osc52clip:write([[#!/bin/bash 113: ${TTY:=$((tty || tty </proc/$PPID/fd/0) 2>/dev/null | grep /dev/)} 114 115case $1 in 116copy) 117buffer=$(base64) 118[ -n "$TTY" ] && printf $'\e]52;c;%s\a' "$buffer" > "$TTY" 119;; 120paste) 121exit 1 122;; 123esac 124]]) 125 osc52clip:close() 126 os.execute("chmod +x " .. bin_dir .. "/osc52clip") 127 end 128end 129 130-- 131-- lsp configs 132local cap = vim.lsp.protocol.make_client_capabilities() 133local cap_ws = cap.workspace 134if cap_ws ~= nil then 135 cap_ws.didChangeWatchedFiles.dynamicRegistration = true 136end 137vim.lsp.config("*", { 138 root_markers = { ".git" }, 139 capabilities = cap 140}) 141 142vim.lsp.config("bash", { 143 -- https://github.com/bash-lsp/bash-language-server 144 cmd = { "bash-language-server", "start" }, 145 filetypes = { "sh", "bash" }, 146 root_markers = nil, 147}) 148vim.lsp.enable("bash") 149 150vim.lsp.config("buf", { 151 -- https://buf.build/docs/reference/cli/buf/beta/lsp/ 152 -- TODO: compare with https://github.com/coder3101/protols 153 cmd = { "buf", "beta", "lsp", "--timeout=0", "--log-format=text" }, 154 filetypes = { "proto" }, 155 root_markers = { "buf.yaml", ".git" }, 156}) 157vim.lsp.enable("buf") 158 159vim.lsp.config("css", { 160 -- https://github.com/hrsh7th/vscode-langservers-extracted 161 cmd = { 'vscode-css-language-server', '--stdio' }, 162 filetypes = { "css" }, 163 root_markers = nil, 164}) 165vim.lsp.enable("css") 166 167vim.lsp.config("cue", { 168 -- https://github.com/cue-lang/cue/wiki/cue-lsp 169 cmd = { "cue", "lsp" }, 170 filetypes = { "cue" }, 171 root_markers = { "cue.mod", ".git" }, 172}) 173vim.lsp.enable("cue") 174 175vim.lsp.config("docker", { 176 -- https://github.com/rcjsuen/dockerfile-language-server-nodejs 177 cmd = { "docker-langserver", "--stdio" }, 178 filetypes = { "dockerfile" }, 179 root_markers = nil, 180}) 181vim.lsp.enable("docker") 182 183vim.lsp.config("gopls", { 184 -- https://github.com/golang/tools/tree/master/gopls 185 cmd = { "gopls" }, 186 -- cmd = { "gopls", "-rpc.trace", "-logfile=/home/user/gopls.log" }, 187 filetypes = { "go", "gomod", "gowork", "gotmpl" }, 188 root_markers = { "go.mod", "go.sum", "go.work", ".git" }, 189 settings = { 190 gopls = { 191 gofumpt = true, 192 staticcheck = true, 193 templateExtensions = { "gotmpl" }, 194 vulncheck = "Imports", 195 analyses = { 196 shadow = true, 197 }, 198 }, 199 }, 200 on_init = function(client) 201 local path = client.workspace_folders[1].name 202 if path:find("/sdk/") then 203 -- disable gofumpt when working on Go project repos 204 client.config.settings.gopls.gofumpt = false 205 end 206 end, 207}) 208vim.lsp.enable("gopls") 209 210vim.lsp.config('json', { 211 -- https://github.com/hrsh7th/vscode-langservers-extracted 212 cmd = { 'vscode-json-language-server', '--stdio' }, 213 filetypes = { "json" }, 214 root_markers = nil, 215}) 216vim.lsp.enable("json") 217 218vim.lsp.config("html", { 219 -- https://github.com/hrsh7th/vscode-langservers-extracted 220 cmd = { "vscode-html-language-server", "--stdio" }, 221 filetypes = { "html" }, 222 root_markers = nil, 223}) 224vim.lsp.enable("html") 225 226vim.lsp.config("lua", { 227 -- https://github.com/luals/lua-language-server 228 cmd = { "lua-language-server" }, 229 filetypes = { "lua" }, 230 settings = { 231 Lua = { 232 workspace = { 233 library = { 234 vim.env.VIMRUNTIME, 235 }, 236 }, 237 }, 238 }, 239 on_attach = function(client, bufnr) 240 vim.lsp.completion.enable(true, client.id, bufnr, { 241 autotrigger = true, 242 convert = function(item) 243 return { abbr = item.label:gsub("%b()", "") } 244 end, 245 }) 246 end, 247}) 248vim.lsp.enable("lua") 249 250vim.lsp.config("markdown", { 251 -- https://github.com/hrsh7th/vscode-langservers-extracted 252 cmd = { "vscode-markdown-language-server", "--stdio" }, 253 filetypes = { "markdown" }, 254 root_markers = nil, 255}) 256vim.lsp.enable("markdown") 257 258-- get directory name from file path 259function Dirname(str) 260 return str:match("(.*[/\\])") 261end 262 263vim.lsp.config("terraform", { 264 -- https://github.com/hashicorp/terraform-ls 265 cmd = { "terraform-ls", "serve" }, 266 filetypes = { "terraform" }, 267 root_dir = function(bufnr, cb) 268 local bufpath = vim.api.nvim_buf_get_name(bufnr) 269 local bufdir = Dirname(bufpath) 270 cb(bufdir) 271 end 272}) 273vim.lsp.enable("terraform") 274 275vim.lsp.config("typos", { 276 -- https://github.com/tekumara/typos-lsp 277 cmd = { "typos-lsp" }, 278 root_markers = nil, 279}) 280vim.lsp.enable("typos") 281 282vim.lsp.config("yaml", { 283 -- https://github.com/redhat-developer/yaml-language-server 284 cmd = { "yaml-language-server", "--stdio" }, 285 filetypes = { "yaml" }, 286 root_markers = nil, 287 settings = { 288 ['yaml.format.enable'] = true, 289 ['yaml.validate'] = true, 290 ['yaml.hover'] = true, 291 ['yaml.completion'] = true, 292 ['yaml.schemaStore.enable'] = true, 293 }, 294}) 295vim.lsp.enable("yaml") 296 297vim.api.nvim_create_autocmd("LspAttach", { 298 group = vim.api.nvim_create_augroup("my.lsp", {}), 299 callback = function(args) 300 local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) 301 302 vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, { desc = "open diagnostic window" }) 303 vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, { desc = "set diagnostic loclist" }) 304 vim.keymap.set("n", "<space>d", vim.lsp.buf.definition, { silent = true, desc = "go to definition" }) 305 vim.keymap.set("n", "<space>h", vim.lsp.buf.hover, { silent = true, desc = "show hover info" }) 306 vim.keymap.set("n", "<space>i", vim.lsp.buf.implementation, { silent = true, desc = "go to implementation" }) 307 vim.keymap.set("n", "<space>s", vim.lsp.buf.signature_help, { silent = true, desc = "show signature help" }) 308 -- vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, { silent = true, desc = "go to type definition" }) 309 vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, { silent = true, desc = "rename symbol" }) 310 vim.keymap.set("n", "<space>a", vim.lsp.buf.code_action, { silent = true, desc = "show code actions" }) 311 vim.keymap.set("n", "<space>r", vim.lsp.buf.references, { silent = true, desc = "show references" }) 312 313 -- Enable auto-completion. Note: Use CTRL-Y to select an item. |complete_CTRL-Y| 314 if client:supports_method("textDocument/completion") then 315 -- Optional: trigger autocompletion on EVERY keypress. May be slow! 316 local chars = {} 317 for i = 32, 126 do 318 table.insert(chars, string.char(i)) 319 end 320 client.server_capabilities.completionProvider.triggerCharacters = chars 321 vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true }) 322 323 vim.keymap.set("i", "<cr>", function() return vim.fn.pumvisible() == 1 and '<c-y>' or '<cr>' end, 324 { silent = true, expr = true }) 325 end 326 327 -- Auto-format ("lint") on save. 328 -- Usually not needed if server supports "textDocument/willSaveWaitUntil". 329 if 330 not client:supports_method("textDocument/willSaveWaitUntil") 331 and client:supports_method("textDocument/formatting") 332 then 333 vim.api.nvim_create_autocmd("BufWritePre", { 334 group = vim.api.nvim_create_augroup("my.lsp", { clear = false }), 335 buffer = args.buf, 336 callback = function() 337 if client.name == "gopls" then 338 vim.lsp.buf.code_action({ 339 bufnr = args.buf, 340 id = client.id, 341 context = { 342 diagnostics = {}, 343 only = { 'source.organizeImports' }, 344 }, 345 apply = true, 346 }) 347 -- vim.lsp.buf.code_action({ bufnr = args.buf, id = client.id, context = { only = { 'source.fixAll' } }, apply = true }) 348 end 349 350 -- local path = client.workspace_folders[1].name 351 -- if not path:find("/sdk/") then 352 vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) 353 -- end 354 end, 355 }) 356 end 357 end, 358}) 359 360vim.diagnostic.config({ 361 virtual_text = true, 362 -- virtual_lines = true, 363}) 364 365 366-- 367-- load plugins 368local pckr_path = vim.fn.stdpath("data") .. "/pckr/pckr.nvim" 369if not vim.uv.fs_stat(pckr_path) then 370 vim.fn.system({ 371 "git", 372 "clone", 373 "--filter=blob:none", 374 "https://github.com/lewis6991/pckr.nvim", 375 pckr_path, 376 }) 377end 378vim.opt.rtp:prepend(pckr_path) 379 380require("pckr").add({ 381 -- colorscheme 382 { 383 "dasupradyumna/midnight.nvim", 384 config = function() 385 vim.cmd.colorscheme("midnight") 386 -- vim.api.nvim_set_hl(0, "goFormatSpecifier", {fg = "#ffffff" }) -- doesn't work 387 vim.api.nvim_set_hl(0, "Normal", { bg = "#000000" }) 388 end, 389 }, 390 391 -- shared deps 392 { 393 -- generic shared library of lua utils 394 "nvim-lua/plenary.nvim", 395 }, 396 { 397 -- debug highlights with :Telescope highlights 398 "nvim-telescope/telescope.nvim", 399 requires = { "nvim-lua/plenary.nvim" }, 400 }, 401 402 -- system 403 { 404 -- floating notification windows 405 "rcarriga/nvim-notify", 406 config = function() 407 vim.notify = require("notify") 408 end, 409 }, 410 411 -- language support 412 -- { 413 -- -- a lot of filetypes, primarily syntax highlighting 414 -- "sheerun/vim-polyglot", 415 -- config_pre = function() 416 -- vim.g.polyglot_disabled = { "cue" } 417 -- end, 418 -- }, 419 { 420 -- cuelang 421 -- fixes tab issues? 422 "jjo/vim-cue", 423 }, 424 -- { 425 -- "terrastruct/d2-vim", 426 -- filetypes = { "d2" }, 427 -- }, 428 { 429 -- treesitter text objects 430 "nvim-treesitter/nvim-treesitter", 431 -- requires = { "neovim/nvim-lspconfig" }, 432 run = ":TSUpdate", 433 config = function() 434 require("nvim-treesitter.configs").setup({ 435 ensure_installed = "all", 436 highlight = { 437 enable = true, 438 disable = { "dockerfile" }, 439 }, 440 indent = { 441 enable = true, 442 }, 443 }) 444 445 vim.wo.foldmethod = "expr" 446 vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" 447 end, 448 }, 449 -- { 450 -- "ravsii/tree-sitter-d2", 451 -- run = "make nvim-install", 452 -- }, 453 454 -- automagic 455 { 456 -- pair close insertion 457 "windwp/nvim-autopairs", 458 config = function() 459 require("nvim-autopairs").setup({ 460 check_ts = true, 461 }) 462 end, 463 }, 464 465 -- keybind reminder 466 { 467 "folke/which-key.nvim", 468 }, 469 470 -- git integration 471 { 472 -- end of line blame 473 "f-person/git-blame.nvim", 474 }, 475 { 476 -- gutter signs 477 "lewis6991/gitsigns.nvim", 478 config = function() 479 require("gitsigns").setup({ 480 signs = { 481 add = { text = "+" }, 482 change = { text = "~" }, 483 }, 484 }) 485 end, 486 }, 487 { 488 -- link to git host with <space>gl 489 "ruifm/gitlinker.nvim", 490 requires = { "nvim-lua/plenary.nvim" }, 491 config = function() 492 require("gitlinker").setup({ 493 mappings = "<space>gl", 494 callbacks = { 495 ["go.googlesource.com"] = function(url_data) 496 local url = require("gitlinker.hosts").get_base_https_url(url_data) 497 url = url .. "/+/" .. url_data.rev .. "/" .. url_data.file 498 if url_data.lstart then 499 url = url .. "#" .. url_data.lstart 500 end 501 return url 502 end, 503 ["lucid-git"] = function(url_data) 504 url_data.host = "github.com" 505 url_data.repo = "seankhliao/" .. url_data.repo 506 return require("gitlinker.hosts").get_github_type_url(url_data) 507 end, 508 }, 509 }) 510 end, 511 }, 512 513 -- kitty integration 514 { 515 "mikesmithgh/kitty-scrollback.nvim", 516 config = function() 517 require("kitty-scrollback").setup({ 518 { 519 restore_options = true, 520 keymaps_enabled = false, 521 }, 522 }) 523 end, 524 }, 525 526 -- extra info 527 { 528 -- colorize #hex 529 "NvChad/nvim-colorizer.lua", 530 config = function() 531 require("colorizer").setup({}) 532 end, 533 }, 534 { 535 "lukas-reineke/indent-blankline.nvim", 536 config = function() 537 local highlight = { 538 "RainbowRed", 539 "RainbowOrange", 540 "RainbowYellow", 541 "RainbowGreen", 542 "RainbowCyan", 543 "RainbowBlue", 544 "RainbowViolet", 545 } 546 547 local hooks = require("ibl.hooks") 548 -- create the highlight groups in the highlight setup hook, so they are reset 549 -- every time the colorscheme changes 550 hooks.register(hooks.type.HIGHLIGHT_SETUP, function() 551 vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }) 552 vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }) 553 vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }) 554 vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }) 555 vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }) 556 vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }) 557 vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }) 558 end) 559 560 require("ibl").setup({ 561 indent = { 562 highlight = { 563 "RainbowRed", 564 "RainbowOrange", 565 "RainbowYellow", 566 "RainbowGreen", 567 "RainbowCyan", 568 "RainbowBlue", 569 "RainbowViolet", 570 }, 571 }, 572 exclude = { 573 buftypes = { "terminal", "nofile" }, 574 }, 575 scope = { 576 highlight = highlight, 577 }, 578 }) 579 end, 580 }, 581 { 582 -- search hover info 583 "kevinhwang91/nvim-hlslens", -- better search 584 config = function() 585 require("hlslens").setup() 586 vim.keymap.set("n", "n", function() 587 vim.cmd.normal({ "n", bang = true }) 588 require("hlslens").start() 589 end, { silent = true }) 590 vim.keymap.set("n", "N", function() 591 vim.cmd.normal({ "N", bang = true }) 592 require("hlslens").start() 593 end, { silent = true }) 594 end, 595 }, 596})