Last active
November 27, 2025 00:33
-
-
Save sigzegv/d2e39e51e23c8b25817aa56c0c1c8c8d to your computer and use it in GitHub Desktop.
vimrc for vim9+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- | |
| local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | |
| if not (vim.uv or vim.loop).fs_stat(lazypath) then | |
| local lazyrepo = "https://github.com/folke/lazy.nvim.git" | |
| local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) | |
| if vim.v.shell_error ~= 0 then | |
| vim.api.nvim_echo({ | |
| { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, | |
| { out, "WarningMsg" }, | |
| { "\nPress any key to exit..." }, | |
| }, true, {}) | |
| vim.fn.getchar() | |
| os.exit(1) | |
| end | |
| end | |
| vim.opt.rtp:prepend(lazypath) | |
| vim.g.mapleader = "ù" | |
| vim.o.autoread = true | |
| vim.o.backspace = "indent,eol,start" | |
| vim.o.backup = false | |
| vim.o.clipboard = "unnamedplus" | |
| vim.o.colorcolumn = "120" | |
| vim.o.cursorline = true | |
| vim.o.directory = "/tmp" | |
| vim.o.encoding = "UTF-8" | |
| vim.o.fcs = "eob: " -- removes empty line's with tilde prefix '~' | |
| vim.o.hidden = true | |
| vim.o.jumpoptions = "stack" | |
| vim.o.mouse = a | |
| vim.o.number = true | |
| vim.o.pumheight = 15 | |
| vim.o.showcmd = true | |
| vim.o.smartcase = true | |
| vim.o.termguicolors = true | |
| vim.o.timeout = true | |
| vim.o.timeoutlen = 1000 | |
| vim.o.ttimeout = true | |
| vim.o.ttimeoutlen = 10 | |
| vim.o.wildignore = "*/tmp/*,*.so,*.swp,*.zip,*/cache/*,.tags" | |
| vim.o.wildmenu = true | |
| vim.o.wrap = false | |
| vim.o.writebackup = false | |
| vim.o.expandtab = true | |
| vim.o.tabstop = 4 | |
| vim.o.shiftwidth = 4 | |
| vim.o.softtabstop = 4 | |
| vim.o.smartindent = true | |
| vim.api.nvim_set_keymap("i", ":w", "<esc>:w<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "x", '"_x', { noremap = true }) | |
| vim.api.nvim_set_keymap("n", "X", '"_X', { noremap = true }) | |
| vim.api.nvim_set_keymap("n", "dD", '"_dd', { noremap = true }) | |
| vim.api.nvim_set_keymap("n", "<pageup>", "<c-u>", { noremap = true }) | |
| vim.api.nvim_set_keymap("n", "<pagedown>", "<c-d>", { noremap = true }) | |
| vim.api.nvim_set_keymap("n", "μ", ":lua print 'A'<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "<S-μ>", ":lua print 'B'<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "qq", ":bd!<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "qb", ":bp|bd#<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "qa", ":qa!<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "<C-down>", ":wincmd w<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "<leader>o", "o<esc>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "yp", ":let @+ = expand('%') .. ':' .. line('.')<cr>", { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "<tab>", ">>_", { noremap = true }) | |
| vim.api.nvim_set_keymap("n", "<s-tab>", "<<_", { noremap = true }) | |
| vim.api.nvim_set_keymap("i", "<s-tab>", "<c-d>", { noremap = true }) | |
| vim.api.nvim_set_keymap("v", "<tab>", ">gv", { noremap = true }) | |
| vim.api.nvim_set_keymap("v", "<s-tab>", "<gv", { noremap = true }) | |
| function is_plugin_loaded(plugin_name) | |
| return require("lazy.core.config").plugins[plugin_name]._.loaded | |
| end | |
| -- https://github.com/folke/lazy.nvim | |
| require("lazy").setup({ | |
| checker = { enabled = false }, | |
| spec = { -- https://lazy.folke.io/spec | |
| { | |
| -- https://github.com/sainnhe/gruvbox-material | |
| "sainnhe/gruvbox-material", | |
| lazy = false, | |
| priority = 99, | |
| config = function() | |
| vim.g.gruvbox_material_better_performance = 1 | |
| vim.g.gruvbox_material_background = "medium" | |
| vim.g.gruvbox_material_menu_selection_background = "aqua" | |
| vim.g.gruvbox_material_sign_column_background = "none" | |
| vim.g.gruvbox_material_diagnostic_virtual_text = "colored" | |
| vim.g.gruvbox_material_statusline_style = "default" | |
| vim.g.gruvbox_material_disable_italic_comment = 1 | |
| vim.g.gruvbox_material_transparent_background = 1 | |
| vim.api.nvim_create_autocmd("ColorScheme", { | |
| group = vim.api.nvim_create_augroup("GruvboxMaterialCustom", { clear = true }), | |
| pattern = "gruvbox-material", | |
| callback = function() | |
| vim.api.nvim_set_hl(0, "StatusLine", { fg = "#161b1c", bg = "#161b1c" }) | |
| vim.api.nvim_set_hl(0, "StatusLineNc", { fg = "#87ff87", bg = "#161b1c" }) | |
| vim.api.nvim_set_hl(0, "User1", { fg = "#d7af87", bg = "#161b1c" }) | |
| vim.api.nvim_set_hl(0, "User2", { fg = "#87ff87", bg = "#161b1c" }) | |
| vim.api.nvim_set_hl(0, "User3", { fg = "#ffaf00", bg = "#161b1c" }) | |
| vim.api.nvim_set_hl(0, "User4", { fg = "#808080", bg = "#161b1c" }) | |
| vim.api.nvim_set_hl(0, "User5", { fg = "#ff0000", bg = "#161b1c" }) | |
| vim.api.nvim_set_hl(0, "DiagnosticsVirtualTextError", { fg = "#ff5555", bg = "#151515" }) | |
| vim.api.nvim_set_hl(0, "DiagnosticsVirtualTextWarning", { fg = "#ff5555", bg = "#151515" }) | |
| vim.api.nvim_set_hl(0, "DiagnosticsVirtualTextInformation", { fg = "#aaaaff", bg = "#151515" }) | |
| vim.api.nvim_set_hl(0, "DiagnosticsVirtualTextHint", { fg = "#aaffaa", bg = "#151515" }) | |
| end, | |
| }) | |
| vim.o.background = "dark" | |
| vim.cmd([[ colorscheme gruvbox-material ]]) | |
| end | |
| }, | |
| { | |
| -- https://github.com/tpope/vim-vinegar | |
| "tpope/vim-vinegar", | |
| }, | |
| { | |
| -- https://github.com/chentoast/marks.nvim | |
| "chentoast/marks.nvim", | |
| event = "VeryLazy", | |
| opts = { | |
| force_write_shada = true, | |
| }, | |
| }, | |
| { | |
| -- https://github.com/tpope/vim-surround | |
| "tpope/vim-surround", | |
| event = "VeryLazy", | |
| }, | |
| { | |
| -- https://github.com/windwp/nvim-autopairs | |
| "windwp/nvim-autopairs", | |
| event = "InsertEnter", | |
| opts = { | |
| fast_wrap = { | |
| map = "<M-e>", | |
| chars = { '{', '[', '(', '"', "'", }, | |
| end_key = '$', | |
| keys = "qwertyuiopzxcvbnmasdfghjkl", | |
| check_comma = true, | |
| manual_position = true, | |
| highlight = "Search", | |
| highlight_grey = "Comment", | |
| }, | |
| disable_filetypes = { "TelescopePrompt", "vim" }, | |
| }, | |
| }, | |
| { | |
| -- https://github.com/t9md/vim-quickhl | |
| "t9md/vim-quickhl", | |
| init = function() | |
| vim.api.nvim_set_keymap("n", "*", "<Plug>(quickhl-manual-this-whole-word)", { silent = true }) | |
| vim.api.nvim_set_keymap("n", "g*", "<Plug>(quickhl-manual-this)", { silent = true }) | |
| vim.api.nvim_set_keymap("x", "g*", "<Plug>(quickhl-manual-this)", { silent = true }) | |
| vim.api.nvim_set_keymap("n", "n", "<Plug>(quickhl-manual-go-to-next)", { silent = true }) | |
| vim.api.nvim_set_keymap("n", "<S-n>", "<Plug>(quickhl-manual-go-to-prev)", { silent = true }) | |
| vim.api.nvim_set_keymap("n", "μ", "<Plug>(quickhl-manual-reset):nohlsearch<cr>", | |
| { noremap = true, silent = true }) | |
| vim.api.nvim_set_keymap("n", "<S-μ>", "<Plug>(quickhl-manual-reset):nohlsearch<cr>", | |
| { noremap = true, silent = true }) | |
| end | |
| }, | |
| { | |
| -- https://github.com/easymotion/vim-easymotion | |
| "easymotion/vim-easymotion", | |
| keys = { | |
| { "s", "<Plug>(easymotion-overwin-f2)", desc = "", mode = "n" }, | |
| { "<leader>l", "<Plug>(easymotion-overwin-line)", desc = "", mode = "n" }, | |
| { "<leader>w", "<Plug>(easymotion-bd-w)", desc = "", mode = "n" }, | |
| }, | |
| }, | |
| { | |
| -- https://github.com/b0o/schemastore.nvim | |
| "b0o/schemastore.nvim", | |
| }, | |
| { | |
| -- https://github.com/mfussenegger/nvim-dap/ | |
| "mfussenegger/nvim-dap", | |
| config = function() | |
| local dap = require("dap") | |
| dap.adapters.delve = { | |
| type = "server", | |
| port = 33947, | |
| executable = { | |
| command = "dlv", | |
| args = { "dap", "-l", "127.0.0.1:33947", '--log', '--log-output=dap' }, | |
| } | |
| } | |
| -- output issues in Go | |
| -- https://github.com/mfussenegger/nvim-dap/discussions/1407 (best solution) | |
| -- https://github.com/mfussenegger/nvim-dap/issues/232 | |
| dap.configurations.go = { | |
| { | |
| type = "delve", | |
| name = "Debug test", | |
| request = "launch", | |
| mode = "test", | |
| program = "${file}", | |
| args = { "-test.v" }, | |
| outputMode = "remote", | |
| }, | |
| { | |
| type = "delve", | |
| name = "Debug test (go.mod)", | |
| request = "launch", | |
| mode = "test", | |
| program = "./${relativeFileDirname}", | |
| args = { "-test.v" }, | |
| outputMode = "remote", | |
| }, | |
| { | |
| -- run client outsite with : | |
| -- dlv test -l 127.0.0.1:33947 --headless | |
| -- dlv test -l 127.0.0.1:33947 --headless -- -test.run TestYourPattern | |
| type = "delve", | |
| name = "Headless Remote", | |
| request = "attach", | |
| mode = "remote", | |
| args = { "-test.v" }, | |
| } | |
| } | |
| dap.adapters.php = { | |
| type = 'executable', | |
| command = 'php-debug-adapter', | |
| } | |
| dap.configurations.php = { | |
| { | |
| type = "php", | |
| request = "launch", | |
| name = "Listen for XDebug", | |
| port = 9001, | |
| pathMappings = { | |
| ["/var/www"] = "/Users/calvarez/projects", | |
| }, | |
| }, | |
| } | |
| vim.fn.sign_define('DapBreakpoint', { text = '◆', texthl = "Title" }) | |
| vim.fn.sign_define('DapStopped', { text = '▶️', texthl = "Constant" }) | |
| end, -- end config | |
| init = function() | |
| vim.keymap.set('n', '<F7>', require 'dap'.run_last) | |
| vim.keymap.set('n', '<F8>', require 'dap'.repl.toggle) | |
| vim.keymap.set('n', '<Leader>df', function() | |
| local widgets = require('dap.ui.widgets') | |
| widgets.centered_float(widgets.frames) | |
| end) | |
| end | |
| keys = { | |
| { ",b", function() require("dap").toggle_breakpoint() end, desc = "DAP breakpoint" }, | |
| { ",c", function() require("dap").continue() end, desc = "DAP continue" }, | |
| { ",C", function() require("dap").terminate() end, desc = "DAP terminate" }, | |
| { ",x", function() require("dap").run_to_cursor() end, desc = "DAP run to cursor" }, | |
| { ",p", function() require("dap").step_over() end, desc = "DAP step" }, | |
| { ",i", function() require("dap").step_into() end, desc = "DAP step in" }, | |
| { ",o", function() require("dap").step_out() end, desc = "DAP step out" }, | |
| { ',h', function() require("dap").up() end, desc = "Frm Up" }, | |
| { ',n', function() require("dap").down() end, desc = "Frm Dwn" }, | |
| { ',f', function() require("dap").down() end, desc = "Frm Dwn" }, | |
| } | |
| }, | |
| { | |
| -- https://github.com/igorlfs/nvim-dap-view", | |
| "igorlfs/nvim-dap-view", | |
| priority = 49, | |
| opts = { | |
| winbar = { | |
| default_section = "scopes", | |
| controls = { | |
| enabled = true, | |
| buttons = { | |
| "play", | |
| "to_cursor", | |
| "step_over", | |
| "step_into", | |
| "step_out", | |
| "run_last", | |
| "terminate", | |
| }, | |
| custom_buttons = { | |
| to_cursor = { | |
| render = function() return "∇" end, | |
| action = function() | |
| require('dap').run_to_cursor() | |
| end, | |
| }, | |
| }, | |
| }, | |
| }, | |
| windows = { | |
| terminal = { | |
| hide = { "delve", "php" }, | |
| }, | |
| anchor = function() | |
| -- Anchor to the first terminal window found in the current tab | |
| -- Tweak according to your needs | |
| local windows = vim.api.nvim_tabpage_list_wins(0) | |
| for _, win in ipairs(windows) do | |
| local bufnr = vim.api.nvim_win_get_buf(win) | |
| if vim.bo[bufnr].buftype == "terminal" then | |
| return win | |
| end | |
| end | |
| end, | |
| }, | |
| }, | |
| keys = { | |
| { ",v", function() require("dap-view").toggle() end, desc = "DAP View" }, | |
| { | |
| ",k", | |
| function() | |
| require("dap-view").open() | |
| require("dap-view").show_view("scopes") | |
| end, | |
| desc = "DAP Scopes" | |
| }, | |
| { | |
| ",l", | |
| function() | |
| require("dap-view").open() | |
| require("dap-view").show_view("repl") | |
| end, | |
| desc = "DAP REPL" | |
| }, | |
| } | |
| }, | |
| { | |
| -- https://github.com/nvim-treesitter/nvim-treesitter | |
| "nvim-treesitter/nvim-treesitter", | |
| build = ":TSUpdate", | |
| config = function() | |
| require("nvim-treesitter.configs").setup({ | |
| ensure_installed = { | |
| "bash", | |
| "c", | |
| "cpp", | |
| "go", | |
| "rust", | |
| "lua", | |
| "python", | |
| "json", | |
| "php", | |
| "html", | |
| "markdown", | |
| }, | |
| sync_install = false, | |
| auto_install = true, | |
| highlight = { | |
| enable = true, | |
| -- disable = { "yaml" }, | |
| additional_vim_regex_highlighting = false, | |
| }, | |
| incremental_selection = { | |
| enable = true, | |
| keymaps = { | |
| init_selection = false, | |
| node_incremental = "v", | |
| node_decremental = "<c-l>", | |
| scope_incremental = false, | |
| }, | |
| }, | |
| }) | |
| end | |
| }, | |
| { | |
| "williamboman/mason.nvim", | |
| build = ":MasonUpdate", | |
| config = function() | |
| require("mason").setup({}) | |
| end, | |
| }, | |
| { | |
| "mason-org/mason-lspconfig.nvim", | |
| config = function() | |
| require("mason-lspconfig").setup({ | |
| ensure_installed = { "lua_ls", "vimls", "pylsp", "phpactor" }, | |
| }) | |
| end, | |
| }, | |
| { | |
| -- https://github.com/hrsh7th/nvim-cmp | |
| "hrsh7th/nvim-cmp", | |
| dependencies = { | |
| "hrsh7th/cmp-nvim-lsp", | |
| "hrsh7th/cmp-buffer", | |
| "hrsh7th/cmp-path", | |
| "hrsh7th/cmp-cmdline", | |
| "hrsh7th/cmp-nvim-lsp-signature-help", | |
| }, | |
| config = function() | |
| local cmp = require("cmp") | |
| cmp.setup({ | |
| sources = { | |
| { name = "nvim_lsp" }, | |
| { name = "nvim_lsp_signature_help" }, | |
| { name = "nvim_lua" }, | |
| { name = "buffer" }, | |
| { name = "path" }, | |
| }, | |
| formatting = { | |
| format = function(entry, vim_item) | |
| -- vim_item.kind = symbol_icons[vim_item.kind] | |
| vim_item.menu = ({ | |
| buffer = "Buf", | |
| nvim_lsp = "LSP", | |
| snippy = "Snip", | |
| nvim_lua = "Lua", | |
| latex_symbols = "Latex", | |
| })[entry.source.name] | |
| return vim_item | |
| end, | |
| }, | |
| mapping = { | |
| ["<cr>"] = cmp.mapping.confirm({ | |
| behavior = cmp.ConfirmBehavior.Replace, | |
| select = false, -- true to select first entry in completion popup automatically | |
| }), | |
| ["<tab>"] = cmp.mapping(function(fallback) | |
| if cmp.visible() then | |
| cmp.select_next_item() | |
| else | |
| fallback() | |
| end | |
| end, { "i", "s" }), | |
| ["<S-tab>"] = cmp.mapping(function(fallback) | |
| if cmp.visible() then | |
| cmp.select_prev_item() | |
| else | |
| fallback() | |
| end | |
| end, { "i", "s" }), | |
| }, | |
| }) | |
| end, | |
| }, | |
| { | |
| "neovim/nvim-lspconfig", | |
| config = function() | |
| vim.lsp.config('lua_ls', { | |
| settings = { | |
| Lua = { | |
| runtime = { | |
| version = "LuaJIT", | |
| path = vim.split(package.path, ";"), | |
| }, | |
| diagnostics = { | |
| globals = { "vim" }, | |
| }, | |
| workspace = { | |
| library = vim.api.nvim_get_runtime_file("lua", true), | |
| }, | |
| } | |
| }, | |
| }) | |
| vim.lsp.config('pylsp', { | |
| settings = { | |
| pylsp = { | |
| plugins = { | |
| pycodestyle = { | |
| ignore = { "W391" }, | |
| maxLineLength = 120, | |
| } | |
| } | |
| } | |
| } | |
| }) | |
| vim.lsp.config('jsonls', { | |
| settings = { | |
| json = { | |
| schemas = require("schemastore").json.schemas(), | |
| validate = { enable = true }, | |
| }, | |
| }, | |
| }) | |
| vim.lsp.config('yamlls', { | |
| settings = { | |
| yaml = { | |
| schemaStore = { | |
| enable = false, | |
| }, | |
| schemas = require("schemastore").yaml.schemas(), | |
| } | |
| }, | |
| }) | |
| end | |
| }, | |
| { | |
| -- https://github.com/stevearc/conform.nvim | |
| -- code formatter | |
| "stevearc/conform.nvim", | |
| lazy = false, | |
| opts = { | |
| notify_on_error = false, | |
| format_on_save = function(bufnr) | |
| local disable_filetypes = { c = true, cpp = true, json = true } | |
| return { | |
| timeout_ms = 5000, | |
| lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], | |
| } | |
| end, | |
| formatters_by_ft = { | |
| go = { "goimports", "gofmt" }, | |
| php = { "php-cs-fixer" }, | |
| }, | |
| }, | |
| }, | |
| { | |
| -- https://github.com/ibhagwan/fzf-lua | |
| "ibhagwan/fzf-lua", | |
| config = function() | |
| require("fzf-lua").setup({ | |
| winopts = { | |
| border = "single", | |
| split = "belowright 15new", | |
| height = 0.3, | |
| row = 0.3, | |
| preview = { | |
| hidden = true, | |
| }, | |
| }, | |
| buffers = { | |
| prompt = 'Buffers > ', | |
| }, | |
| }) | |
| end, | |
| init = function() | |
| vim.api.nvim_set_keymap("n", "<leader>:", ":FzfLua files<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "<leader>;", ":FzfLua git_files<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "<leader>!", ":FzfLua buffers<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "<leader>*", ":FzfLua grep_cword<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "<leader>f", ":FzfLua live_grep_resume<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "<leader>d", ":FzfLua live_grep_resume<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "<leader>F", ":FzfLua grep_last<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "gm", ":FzfLua marks<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "gk", ":FzfLua keymaps<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "ge", ":FzfLua lsp_definitions {sync=true, jump1=false}<cr>", | |
| { silent = true }) | |
| vim.api.nvim_set_keymap("n", "gr", | |
| ":FzfLua lsp_references jump1=false ignore_current_line=true includeDeclaration=false<cr>", | |
| {silent = true}) | |
| vim.api.nvim_set_keymap("n", "gR", ":FzfLua lsp_implementations<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "gz", ":FzfLua lsp_document_diagnostics<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "gZ", ":FzfLua lsp_workspace_diagnostics<cr>", {}) | |
| vim.api.nvim_set_keymap("n", "gs", ":FzfLua lsp_document_symbols<cr>", {}) | |
| end, | |
| } | |
| }, | |
| }) | |
| -- diagnostics | |
| vim.diagnostic.config({ | |
| signs = { | |
| text = { | |
| [vim.diagnostic.severity.ERROR] = "", | |
| [vim.diagnostic.severity.WARN] = "", | |
| [vim.diagnostic.severity.INFO] = "", | |
| [vim.diagnostic.severity.HINT] = "", | |
| }, | |
| }, | |
| virtual_text = false, | |
| underline = false, | |
| update_in_insert = false, | |
| severity_sort = true, | |
| float = { | |
| focusable = false, | |
| border = "rounded", | |
| close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, | |
| source = "always", | |
| prefix = "", | |
| scope = "line", | |
| }, | |
| }) | |
| vim.keymap.set("n", "gd", vim.lsp.buf.hover, { silent = true }) | |
| vim.keymap.set("n", "gf", vim.lsp.buf.type_definition, { silent = true }) | |
| vim.keymap.set("n", "g<space>", vim.lsp.buf.rename, {}) | |
| -- debugger | |
| if is_plugin_loaded("nvim-dap-view") and is_plugin_loaded("nvim-dap") then | |
| local dap = require("dap") | |
| local dv = require("dap-view") | |
| dap.listeners.before.attach["dap-view-config"] = function() | |
| dv.open() | |
| end | |
| dap.listeners.before.launch["dap-view-config"] = function() | |
| vim.notify("Test started.") | |
| dv.open() | |
| end | |
| dap.listeners.before.event_terminated["dap-view-config"] = function() | |
| vim.notify("Test completed.") | |
| end | |
| end | |
| -- Set Statusline | |
| function has_diagnotics_errors(b) | |
| local sev = vim.lsp.protocol.DiagnosticSeverity["Error"] | |
| local errcount = #vim.diagnostic.get(b, { severity = sev }) | |
| if errcount > 0 then | |
| return "[Err: " .. errcount .. "]" | |
| end | |
| return "" | |
| end | |
| function is_read_only() | |
| if vim.o.ro == true or not vim.o.modifiable then | |
| return " " | |
| end | |
| return "" | |
| end | |
| local s = "%1* " .. "%n" -- buffer number | |
| s = s .. "%4* ::" -- separator | |
| s = s .. "%3* %q" | |
| s = s .. "%1*" .. is_read_only() -- readonly status | |
| s = s .. "%2*%f" -- filename | |
| s = s .. "%3* %m" -- dirty flag | |
| s = s .. '%5* %{luaeval("has_diagnotics_errors(bufnr)")}' | |
| s = s .. "%*%=" -- line spacer | |
| s = s .. "%1*%y" -- filetype | |
| s = s .. "%4* ::" -- separator | |
| s = s .. '%1* %{luaeval("vim.o.encoding")}' -- file encoding | |
| s = s .. "%4* ::" -- separator | |
| s = s .. "%1* %l,%c" -- line,column | |
| s = s .. "%4* ::" -- separator | |
| s = s .. "%3* %p%%" -- cursor line position in percent | |
| vim.o.statusline = s .. "%*" -- end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vim9script | |
| # https://vimhelp.org/vim9.txt.html | |
| set nocompatible | |
| if has("mac") | |
| set clipboard=unnamed | |
| else | |
| set clipboard=unnamedplus # requires vim-gui-common | |
| endif | |
| set directory=/tmp | |
| set nobackup | |
| set mouse=a | |
| set nowritebackup | |
| set sessionoptions-=options | |
| set hidden | |
| set showcmd | |
| set pumheight=15 | |
| set wildmenu | |
| set wildoptions=pum,fuzzy | |
| set colorcolumn=80 | |
| set nocursorline | |
| set display=truncate | |
| set encoding=utf-8 | |
| set fileencoding=utf-8 | |
| set fillchars=stl:\ ,stlnc:\ ,vert:\|,fold:-,diff:-,eob:\ | |
| set helplang=fr | |
| set history=2048 | |
| set hlsearch | |
| set incsearch | |
| set langnoremap | |
| set laststatus=2 | |
| set nolangremap | |
| set nomodeline | |
| set nrformats=bin,hex | |
| set number | |
| set omnifunc=syntaxcomplete#Complete | |
| set printoptions=paper:a4 | |
| set ruler | |
| set scrolloff=2 | |
| set sidescroll=1 | |
| set sidescrolloff=2 | |
| set ttimeout | |
| set ttimeoutlen=100 | |
| set ttymouse=sgr | |
| set viewoptions-=options | |
| set viminfo^=! | |
| set nowrap | |
| set splitbelow | |
| set splitright | |
| set smartindent | |
| set autoindent | |
| set expandtab | |
| set shiftwidth=4 | |
| set softtabstop=4 | |
| set tabstop=4 | |
| set smarttab | |
| filetype on | |
| filetype plugin on | |
| filetype indent on | |
| syntax on | |
| runtime! macros/matchit.vim | |
| runtime! ftplugin/man.vim | |
| set backspace=indent,eol,start | |
| g:mapleader = 'ù' | |
| tnoremap <C-i> <C-\><C-n> | |
| nnoremap <leader>: :20Lex<CR> | |
| nnoremap <leader>p :register<cr> | |
| ## custom shortcuts | |
| # delete without copying | |
| nnoremap x "_x | |
| nnoremap X "_X | |
| # new lines | |
| # nnoremap <cr> o<esc> | |
| nnoremap <leader><cr> O<esc> | |
| # pane switch | |
| nmap <silent> <C-down> :wincmd w<cr> | |
| # tab movements | |
| nnoremap <tab> >>_ | |
| nnoremap <S-tab> <<_ | |
| inoremap <S-tab> <c-d> | |
| vnoremap <tab> >gv | |
| vnoremap <S-tab> <gv | |
| inoremap <expr> <tab> pumvisible() ? "\<c-n>" : "\<Tab>" | |
| inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<c-d>" | |
| inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<cr>" | |
| # quick save without going back to normal mode | |
| inoremap <silent> :w <esc>:w<cr> | |
| # unhighlight | |
| nmap <silent> µ :nohlsearch<cr> | |
| # leave insert mode alternate | |
| inoremap ii <esc> | |
| nnoremap <pageup> <c-u> | |
| nnoremap <pagedown> <c-d> | |
| # https://www.reddit.com/r/vim/comments/1er93oq/cursor_in_vim/ | |
| # Todo convert to vim9script | |
| &t_SI = "\<Esc>[5 q" | |
| &t_SR = "\<Esc>[4 q" | |
| &t_EI = "\<Esc>[2 q" | |
| ## kinds icons for LSPs | |
| g:Kinds = { | |
| "Class": " ", | |
| "Color": " ", | |
| "Constant": " ", | |
| "Constructor": " ", | |
| "Enum": " ", | |
| "EnumMember": " ", | |
| "Event": "", | |
| "Field": " ", | |
| "File": " ", | |
| "Folder": " ", | |
| "Function": " ", | |
| "Interface": " ", | |
| "Keyword": " ", | |
| "Method": "ƒ ", | |
| "Module": "", | |
| "Operator": "", | |
| "Property": " ", | |
| "Snippet": " ", | |
| "Reference": " ", | |
| "Struct": " ", | |
| "Text": " ", | |
| "TypeParameter": " ", | |
| "Unit": " ", | |
| "Value": " ", | |
| "Variable": " " | |
| } | |
| g:polyglot_disabled = ['autoindent'] | |
| plug#begin() | |
| Plug 'sainnhe/gruvbox-material' | |
| Plug 'tpope/vim-sleuth' | |
| Plug 'sheerun/vim-polyglot' | |
| Plug 'moll/vim-bbye' | |
| Plug 'jlanzarotta/bufexplorer' | |
| Plug 't9md/vim-quickhl' | |
| Plug 'vim-scripts/argtextobj.vim' | |
| Plug 'romainl/vim-qf' | |
| Plug 'MarcWeber/vim-addon-qf-layout' | |
| Plug 'tmsvg/pear-tree' | |
| Plug 'tpope/vim-vinegar' | |
| Plug 'tpope/vim-commentary' | |
| Plug 'tpope/vim-surround' | |
| Plug 'easymotion/vim-easymotion' | |
| Plug 'lervag/wiki.vim' | |
| Plug 'kshenoy/vim-signature' | |
| Plug 'prabirshrestha/vim-lsp' | |
| Plug 'mattn/vim-lsp-settings' | |
| Plug 'prabirshrestha/asyncomplete.vim' | |
| Plug 'prabirshrestha/asyncomplete-lsp.vim' | |
| Plug 'prabirshrestha/asyncomplete-file.vim' | |
| Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
| Plug 'junegunn/fzf.vim' | |
| plug#end() | |
| # list loaded plugins: :echo keys(g:plugs) | |
| legacy if exists(':PlugInstall') | |
| command! PI so ~/.vim/vimrc | PlugInstall | |
| endif | |
| legacy if exists(':PlugUpdate') | |
| command! PU so ~/.vim/vimrc | PlugUpdate | |
| endif | |
| legacy if exists(':PlugClean') | |
| command! PC so ~/.vim/vimrc | PlugClean | |
| endif | |
| def PlugList() | |
| echo keys(g:plugs) | |
| enddef | |
| command! -bang PlugList PlugList() | |
| def IsPluginLoaded(p: string): bool | |
| return len(filter(keys(g:plugs), 'v:val == "' .. p .. '"')) > 0 | |
| enddef | |
| def g:SyntaxInfo() | |
| var l = line(".") | |
| var c = col(".") | |
| var id = synID(l, c, 1) | |
| var name = synIDattr(id, "name") | |
| var idt = synID(l, c, 0) | |
| var namet = synIDattr(idt, "name") | |
| var id2 = synIDtrans(id) | |
| var name2 = synIDattr(id2, "name") | |
| echom "Syn [" .. name .. " " .. namet .. " " .. name2 .. "]" | |
| enddef | |
| command! -bang SyntaxInfo g:SyntaxInfo() | |
| def YankCursorPositionInfo() | |
| @* = expand('%') .. ":" .. line('.') | |
| enddef | |
| command! -bang YankCursorPositionInfo YankCursorPositionInfo() | |
| nnoremap yp :YankCursorPositionInfo<CR> | |
| def YankCursorLineInfo() | |
| @* = expand('%') .. ":" .. line('.') .. ": " .. getline('.') | |
| enddef | |
| command! -bang YankCursorLineInfo YankCursorLineInfo() | |
| nnoremap yl :YankCursorLineInfo<CR> | |
| def GitBlame() | |
| var l = line('.') | |
| var output = system(printf("git blame -L %d,%d %s", l, l, expand('%'))) | |
| echom output | |
| enddef | |
| command! -bang GitBlame GitBlame() | |
| ## https://github.com/sainnhe/gruvbox-material | |
| if IsPluginLoaded("gruvbox-material") | |
| g:gruvbox_material_background = 'medium' | |
| g:gruvbox_material_better_performance = 1 | |
| g:gruvbox_material_disable_italic_comment = 1 | |
| g:gruvbox_material_transparent_background = 1 | |
| augroup GruvboxMaterialCustom | |
| autocmd! | |
| autocmd ColorScheme gruvbox-material { | |
| highlight! CursorLine guibg=#202020 | |
| highlight! Visual guibg=#101010 | |
| highlight! StatusLine guifg=#87ff87 guibg=#161b1c | |
| highlight! StatusLineNc guifg=#228855 guibg=#161b1c | |
| highlight! User1 guifg=#d7af87 guibg=#161b1c | |
| highlight! User2 guifg=#87ff87 guibg=#161b1c | |
| highlight! User3 guifg=#ffaf00 guibg=#161b1c | |
| highlight! User4 guifg=#808080 guibg=#161b1c | |
| highlight! User5 guifg=#ff0000 guibg=#161b1c | |
| highlight! LspErrorText gui=NONE guifg=#FF3333 | |
| highlight! LspWarningText gui=NONE guifg=#FFBB00 | |
| highlight! LspHintText gui=NONE guifg=#00CCFF | |
| highlight! LspInformationText gui=NONE guifg=#CCFFCC | |
| highlight! ScopeMenuMatch gui=NONE guifg=LimeGreen | |
| highlight! ScopeMenuVirtualText gui=NONE guifg=#FF0000 | |
| # highlight! ScopeMenuSubtle gui=NONE guifg=NONE | |
| } | |
| augroup END | |
| augroup goSyntax | |
| autocmd! | |
| autocmd BufReadPost,BufNewFile *.go { | |
| hi! goBuiltins gui=NONE guifg=#d25d5d | |
| hi! goType gui=NONE guifg=#d7875f | |
| hi! goParen guifg=#FFAA00 | |
| syn match goParen /[({})]/ | |
| } | |
| augroup END | |
| set background=dark | |
| set termguicolors | |
| colorscheme gruvbox-material | |
| endif | |
| ## https://github.com/moll/vim-bbye | |
| if IsPluginLoaded("vim-bbye") | |
| nnoremap <silent> <leader>x :Bdelete!<cr> | |
| endif | |
| ## https://github.com/jlanzarotta/bufexplorer | |
| if IsPluginLoaded("bufexplorer") | |
| g:bufExplorerDefaultHelp = 0 | |
| g:bufExplorerDisableDefaultKeyMapping = 1 | |
| g:bufExplorerShowDirectories = 1 | |
| g:bufExplorerSplitOutPathName = 0 | |
| g:bufExplorerShowRelativePath = 1 | |
| nnoremap <silent> <leader>! :ToggleBufExplorer<CR> | |
| endif | |
| ## https://github.com/t9md/vim-quickhl | |
| if IsPluginLoaded("vim-quickhl") | |
| nnoremap <silent> * <Plug>(quickhl-manual-this-whole-word) | |
| nnoremap <silent> g* <Plug>(quickhl-manual-this) | |
| xnoremap <silent> g* <Plug>(quickhl-manual-this) | |
| nnoremap <silent> µ <Plug>(quickhl-manual-reset):nohlsearch<Bar>:echo<cr> | |
| nnoremap <silent> <S-µ> <Plug>(quickhl-manual-reset):nohlsearch<Bar>:echo<cr> | |
| nnoremap <silent> n <Plug>(quickhl-manual-go-to-next) | |
| nnoremap <silent> <S-n> <Plug>(quickhl-manual-go-to-prev) | |
| endif | |
| ## https://github.com/romainl/vim-qf | |
| if IsPluginLoaded("vim-qf") | |
| g:qf_auto_open_quickfix = 0 | |
| g:qf_auto_open_loclist = 0 | |
| g:qf_mapping_ack_style = 1 | |
| g:qf_max_height = 15 | |
| g:qf_auto_resize = 1 | |
| g:qf_shorten_path = 3 | |
| nmap ,l <Plug>(qf_loc_next) | |
| nmap ,, <Plug>(qf_qf_switch) | |
| endif | |
| ## https://github.com/MarcWeber/vim-addon-qf-layout | |
| if IsPluginLoaded("vim-addon-qf-layout") | |
| g:vim_addon_qf_layout = {} | |
| g:vim_addon_qf_layout.quickfix_formatters = [ | |
| 'vim_addon_qf_layout#DefaultFormatter', | |
| 'vim_addon_qf_layout#FormatterNoFilename', | |
| 'vim_addon_qf_layout#Reset', | |
| ] | |
| endif | |
| ### https://github.com/vim-scripts/argtextobj.vim | |
| # if IsPluginLoaded("argtextobj.vim") | |
| # endif | |
| ## https://github.com/tmsvg/pear-tree | |
| if IsPluginLoaded("pear-tree") | |
| g:pear_tree_repeatable_expand = 0 | |
| g:pear_tree_smart_openers = 1 | |
| g:pear_tree_smart_closers = 1 | |
| g:pear_tree_smart_backspace = 1 | |
| endif | |
| ### https://github.com/tpope/vim-vinegar | |
| # alternative lambdalisue/vim-fern | |
| # if IsPluginLoaded("tpope/vim-vinegar") | |
| # endif | |
| ### https://github.com/tpope/vim-commentary | |
| # if IsPluginLoaded("vim-commentary") | |
| # endif | |
| ### https://github.com/tpope/vim-surround | |
| # todo: check https://github.com/machakann/vim-sandwich | |
| # if IsPluginLoaded("vim-surround") | |
| # endif | |
| ## https://github.com/sheerun/vim-polyglot | |
| # if IsPluginLoaded("vim-polyglot") | |
| # g:polyglot_disabled = ['autoindent'] | |
| # endif | |
| ## https://github.com/easymotion/vim-easymotion | |
| if IsPluginLoaded("vim-easymotion") | |
| nmap s <Plug>(easymotion-overwin-f2) | |
| nmap <Leader>l <Plug>(easymotion-overwin-line) | |
| nmap <Leader>w <Plug>(easymotion-bd-w) | |
| endif | |
| ## https://github.com/sebdah/vim-delve | |
| if IsPluginLoaded("vim-delve") | |
| nmap <leader>b :DlvToggleBreakpoint<CR> | |
| endif | |
| ## https://github.com/junegunn/fzf.vim | |
| ## had to build the vim plugged fzf to have correct binary version | |
| ## !rg --column --line-number --no-heading --color=always --smart-case ./* LspCodeAction | |
| if IsPluginLoaded("fzf.vim") | |
| g:fzf_vim = { | |
| preview_window: [], | |
| } | |
| $FZF_DEFAULT_OPTS = '--reverse' | |
| g:vimlspkinds = { | |
| 6: "method", | |
| 8: "property", | |
| 11: "interface", | |
| 12: "func", | |
| 13: "variable", | |
| 14: "const", | |
| 23: "struct", | |
| } | |
| g:fzf_layout = { | |
| 'down': 10 | |
| } | |
| def BufWithDel() | |
| def DeleteBuffer(lines: list<string>) | |
| if len(lines) < 2 | |
| return | |
| endif | |
| var bufnr = matchstr(lines[1], '\[\zs[0-9]*\ze\]') | |
| if lines[0] == 'ctrl-d' | |
| execute 'silent! bdelete' bufnr | |
| BufWithDel() | |
| else | |
| execute 'buffer' bufnr | |
| endif | |
| enddef | |
| fzf#vim#buffers('', { | |
| down: 10, | |
| 'sink*': DeleteBuffer, | |
| options: ['--expect=ctrl-d', '--header', 'Enter: open | CTRL-D: delete'] | |
| }, 0) | |
| enddef | |
| command! -bang PromptBuffers BufWithDel() | |
| if !exists('*FzfLspDiagnostics') | |
| def FzfLspDiagnostics() | |
| if !exists('*LspSendRequest') | |
| echo "FzfLspDiagnostic error: LspSendRequest: function missing" | |
| return | |
| endif | |
| var items = LspDiagnostics((d) => { | |
| return FormatDiagnostic(d) | |
| }) | |
| if len(items) == 0 | |
| echo "No diagnostics found" | |
| return | |
| endif | |
| fzf#run(fzf#wrap({ | |
| source: items, | |
| sink: (m) => { | |
| var parts = split(m, ':') | |
| execute "e " .. fnameescape(parts[0]) | |
| cursor(str2nr(parts[1]), str2nr(parts[2])) | |
| }, | |
| #down: len(items) + 3, | |
| options: [ | |
| '--ansi', | |
| '--prompt', 'Diagnostics> ', | |
| '--delimiter', ':', | |
| # '--preview', 'batcat -p --color=always {1}', | |
| # '--preview-window', '+{2}-/2', | |
| ] | |
| })) | |
| enddef | |
| command! -bang Diagnostics FzfLspDiagnostics() | |
| nmap <silent> gz :Diagnostics<CR> | |
| endif | |
| if !exists('FzfLspReferences') | |
| def FzfLspReferences() | |
| if !exists('*LspSendRequest') | |
| echo "FzfLspReferences error: LspSendRequest: function missing" | |
| return | |
| endif | |
| def PopupSel(ctx: dict<any>, server: string, operation: string, data: any) | |
| echo "Retrieving references..." | |
| if has_key(data['response'], 'error') | |
| echo "No references found: " .. data['response']['error']['message'] | |
| return | |
| endif | |
| var items = [] | |
| for r in data["response"]["result"] | |
| var filename = lsp#utils#uri_to_path(r["uri"]) | |
| var ftxt = readfile(filename) | |
| var msg = trim(ftxt[r["range"]["start"]["line"]]) | |
| add(items, printf( | |
| "\e[32m%s\e[0m:\e[35m%s\e[0m:\e[34m%s\e[0m %s", | |
| substitute(filename, getcwd() .. "/", "", ""), | |
| r["range"]["start"]["line"] + 1, | |
| r["range"]["start"]["character"], | |
| msg | |
| )) | |
| endfor | |
| if empty(items) | |
| echo "No references found." | |
| return | |
| endif | |
| fzf#run(fzf#wrap({ | |
| source: items, | |
| sink: (m) => { | |
| var parts = split(m, ':') | |
| execute "e " .. fnameescape(parts[0]) | |
| cursor(str2nr(parts[1]), str2nr(parts[2])) | |
| }, | |
| #down: len(items) + 3, | |
| options: [ | |
| '--ansi', | |
| '--prompt', 'References> ', | |
| '--delimiter', ':', | |
| ] | |
| })) | |
| enddef # LspSendRequest | |
| LspSendRequest('references', PopupSel) | |
| enddef # FzfLspReferences | |
| command! -bang References FzfLspReferences() | |
| nmap <silent> gr :References<CR> | |
| endif | |
| if !exists('FzfLspImplementations') | |
| def FzfLspImplementations() | |
| def PopupSel(ctx: dict<any>, server: string, operation: string, data: any) | |
| echo "Retrieving implementations..." | |
| if has_key(data['response'], 'error') | |
| echo "No implementations found: " .. data['response']['error']['message'] | |
| return | |
| endif | |
| var items = [] | |
| for r in data["response"]["result"] | |
| var filename = lsp#utils#uri_to_path(r["uri"]) | |
| var ftxt = readfile(filename) | |
| var msg = trim(ftxt[r["range"]["start"]["line"]]) | |
| add(items, printf( | |
| "\e[32m%s\e[0m:\e[35m%s\e[0m:\e[34m%s\e[0m %s", | |
| substitute(filename, getcwd() .. "/", "", ""), | |
| r['range']['start']['line'] + 1, | |
| r['range']['start']['character'], | |
| msg, | |
| )) | |
| endfor | |
| if len(items) == 0 | |
| echo "No implementations found" | |
| return | |
| endif | |
| fzf#run(fzf#wrap({ | |
| source: items, | |
| sink: (m) => { | |
| var parts = split(m, ':') | |
| cursor(str2nr(parts[1]), 1) | |
| }, | |
| options: [ | |
| '--ansi', | |
| '--reverse', | |
| '--prompt', 'Implementations> ', | |
| ] | |
| })) | |
| enddef | |
| LspSendRequest('implementation', PopupSel) | |
| enddef | |
| command! -bang Implementations FzfLspImplementations() | |
| nmap <silent> gR :Implementations<CR> | |
| endif | |
| g:vimlspkinds = { | |
| 13: 'variable', | |
| 14: 'const', | |
| } | |
| if !exists('FzfLspDocumentSymbols') | |
| def FzfLspDocumentSymbols() | |
| def PopupSel(ctx: dict<any>, server: string, operation: string, data: any) | |
| var items = [] | |
| for r in data["response"]["result"] | |
| add(items, printf( | |
| "\e[35m%s\e[0m\t%-50s \e[33m%s\e[0m", | |
| r['range']['start']['line'] + 1, | |
| r['name'], | |
| has_key(r, 'detail') ? r['detail'] : g:vimlspkinds[r['kind']] | |
| )) | |
| if has_key(r, 'children') | |
| for r2 in r['children'] | |
| var cname = printf(" %s.%s", r['name'], r2['name']) | |
| add(items, printf( | |
| "\e[35m%s\e[0m\t%-50s \e[33m%s\e[0m", | |
| r2['range']['start']['line'] + 1, | |
| cname, | |
| has_key(r2, 'detail') ? r2['detail'] : g:vimlspkinds[r['kind']] | |
| )) | |
| endfor | |
| endif | |
| endfor | |
| if len(items) == 0 | |
| echo "No symbols found" | |
| return | |
| endif | |
| fzf#run(fzf#wrap({ | |
| source: items, | |
| sink: (m) => { | |
| var parts = split(m, ':') | |
| cursor(str2nr(parts[0]), 0) | |
| }, | |
| down: 10, | |
| options: [ | |
| '--ansi', | |
| '--reverse', | |
| '--prompt', 'DocumentSymbols> ', | |
| '--delimiter', ':', | |
| ] | |
| })) | |
| enddef | |
| LspSendRequest('documentSymbol', PopupSel) | |
| enddef | |
| command! -bang DocumentSymbols FzfLspDocumentSymbols() | |
| nmap <silent> gs :DocumentSymbols<CR> | |
| endif | |
| def PrepareCalls(ctx: dict<any>, server: string, operation: string, data: any) | |
| def PopupSel(sctx: dict<any>, s: string, soperation: string, sdata: any) | |
| if has_key(sdata['response'], 'error') && sdata['response']['error']['code'] != 0 | |
| echom "ERR: " .. sdata['response']['error']['message'] | |
| return | |
| endif | |
| var items = [] | |
| for r in sdata["response"]["result"] | |
| add(items, sctx['rowformat'](r)) | |
| endfor | |
| if len(items) == 0 | |
| echo "No " .. ctx["prompt"] .. " found" | |
| return | |
| endif | |
| fzf#run(fzf#wrap({ | |
| source: items, | |
| sink: (m) => { | |
| var fp = split(m, ']') | |
| var parts = split(fp[1], ':') | |
| execute "e " .. fnameescape(trim(parts[0])) | |
| cursor(str2nr(parts[1]) + 1, 1) | |
| }, | |
| down: 10, | |
| options: [ | |
| '--ansi', | |
| '--reverse', | |
| '--prompt', ctx["prompt"] .. " > ", | |
| ] | |
| })) | |
| enddef | |
| if data['response']['result'] == null | |
| echom "No calls found for method " .. ctx['method'] | |
| return | |
| endif | |
| var capabilities_func = printf('lsp#capabilities#has_call_hierarchy_provider(v:val)') | |
| var servers = filter(lsp#get_allowed_servers(), capabilities_func) | |
| if len(servers) == 0 | |
| echo printf('WARN: LSP: call_hierarchy for outgoing call is not supported') | |
| return | |
| endif | |
| var method = "callHierarchy/" .. ctx['method'] | |
| var subctx = ctx | |
| var params = { 'item': data['response']['result'][0] } | |
| for s in servers | |
| lsp#send_request(s, { | |
| 'method': method, | |
| 'params': params, | |
| 'on_notification': function(PopupSel, [subctx, s, method]), | |
| }) | |
| endfor | |
| enddef | |
| if !exists('FzfLspOutgoingCalls') | |
| def FzfLspOutgoingCalls() | |
| LspSendRequest('prepareCallHierarchy', PrepareCalls, { | |
| ctx: { | |
| method: "outgoingCalls", | |
| prompt: "outgoing calls", | |
| rowformat: (r) => { | |
| var filename = lsp#utils#uri_to_path(r["to"]["uri"]) | |
| return printf("\e[35m%-4d\e[0m %-20s \e[33m[%s] \e[32m%s:%d\e[0m", | |
| r['fromRanges'][0]["start"]["line"], | |
| r['to']['name'], | |
| r['to']['detail'], | |
| filename, | |
| r["to"]["range"]["start"]["line"], | |
| ) | |
| }, | |
| } | |
| }) | |
| enddef | |
| command! -bang OutgoingCalls FzfLspOutgoingCalls() | |
| nmap <silent> go :OutgoingCalls<CR> | |
| endif | |
| if !exists('FzfLspIncomingCalls') | |
| def FzfLspIncomingCalls() | |
| LspSendRequest('prepareCallHierarchy', PrepareCalls, { | |
| ctx: { | |
| method: "incomingCalls", | |
| prompt: "incoming calls", | |
| rowformat: (r) => { | |
| var filename = lsp#utils#uri_to_path(r["from"]["uri"]) | |
| return printf("\e[35m%-4d\e[0m %-20s \e[33m[%s] \e[32m%s:%d\e[0m", | |
| r['fromRanges'][0]["start"]["line"], | |
| r['from']['name'], | |
| r['from']['detail'], | |
| filename, | |
| r["from"]["range"]["start"]["line"], | |
| ) | |
| }, | |
| } | |
| }) | |
| enddef | |
| command! -bang IncomingCalls FzfLspIncomingCalls() | |
| nmap <silent> gi :IncomingCalls<CR> | |
| endif | |
| nmap <leader>! :PromptBuffers<cr> | |
| nmap <leader>: :Files<cr> | |
| nmap <leader>; :GFiles<cr> | |
| nmap <leader>c :BCommits<cr> | |
| nmap <leader>m :Marks<cr> | |
| nmap <leader>j :Jumps<cr> | |
| nmap <leader>* :Rg <c-r><c-w><cr> | |
| endif | |
| ## https://github.com/prabirshrestha/vim-lsp | |
| ## https://github.com/mattn/vim-lsp-settings | |
| ## https://github.com/prabirshrestha/asyncomplete.vim | |
| ## https://github.com/prabirshrestha/asyncomplete-lsp.vim | |
| ## completion alternative : 'girishji/vimcomplete' | |
| if IsPluginLoaded("vim-lsp") | |
| g:lsp_peek_alignment = 'top' | |
| g:lsp_document_code_action_signs_enabled = 0 | |
| g:lsp_document_highlight_enabled = 0 | |
| g:lsp_diagnostics_echo_cursor = 0 | |
| g:lsp_diagnostics_echo_delay = 200 | |
| g:lsp_diagnostics_float_cursor = 0 | |
| g:lsp_diagnostics_float_delay = 400 | |
| g:lsp_diagnostics_virtual_text_enabled = 0 | |
| g:lsp_diagnostics_virtual_text_prefix = "## " | |
| g:lsp_diagnostics_virtual_text_align = "right" | |
| g:lsp_diagnostics_highlights_enabled = 1 | |
| g:lsp_diagnostics_signs_error = { 'text': "" } | |
| g:lsp_diagnostics_signs_warning = { 'text': "" } | |
| g:lsp_diagnostics_signs_information = { 'text': "" } | |
| g:lsp_diagnostics_signs_hint = { 'text': "" } | |
| g:lsp_preview_max_height = 15 | |
| g:lsp_settings_servers_dir = "~/.vim/lspservers" | |
| g:lsp_settings_root_markers = [ | |
| '.git', | |
| '.git/', | |
| '.svn', | |
| '.hg', | |
| '.bzr', | |
| 'go.mod', | |
| ] | |
| g:lsp_settings = { | |
| 'vim-language-server': {'disabled': true}, | |
| 'rls': {'disabled': true}, | |
| } | |
| if IsPluginLoaded("asyncomplete-file.vim") | |
| au User asyncomplete_setup asyncomplete#register_source(asyncomplete#sources#file#get_source_options({name: 'file', allowlist: ['*'], priority: 10, completor: function('asyncomplete#sources#file#completor')})) | |
| endif | |
| augroup lsp_install | |
| autocmd! | |
| autocmd User lsp_buffer_enabled { | |
| setlocal omnifunc=lsp#complete | |
| setlocal signcolumn=yes | |
| nmap <buffer> ge <plug>(lsp-peek-definition) | |
| nmap <buffer> gE <plug>(lsp-definition) | |
| nmap <buffer> gf <plug>(lsp-peek-type-definition) | |
| nmap <buffer> gF <plug>(lsp-type-definition) | |
| nmap <buffer> gd <plug>(lsp-hover) | |
| if IsPluginLoaded("vim-lspfuzzy") && IsPluginLoaded("fzf.vim") | |
| nmap <buffer> gr :FzfLspReferences<CR> | |
| endif | |
| } | |
| augroup END | |
| augroup LspBufWriteFmt | |
| autocmd! | |
| autocmd BufWritePre *.go execute('LspDocumentFormatSync') | execute('LspCodeActionSync source.organizeImports') | |
| augroup END | |
| ## manual tab completion | |
| # g:asyncomplete_auto_popup = 0 | |
| # g:asyncomplete_auto_completeopt = 0 | |
| # def g:Check_back_space(): bool | |
| # var col = col('.') - 1 | |
| # return !col || getline('.')[col - 1] =~ '\s' | |
| # enddef | |
| # inoremap <silent><expr> <TAB> | |
| # \ pumvisible() ? "\<C-n>" : | |
| # \ g:Check_back_space() ? "\<TAB>" : | |
| # \ asyncomplete#force_refresh() | |
| #### LSP additions | |
| # bulk lsp request function over vim-lsp | |
| if !exists('*LspSendRequest') | |
| def LspSendRequest(op: string, Callback: func(dict<any>, string, string, any), conf: dict<any> = {}) | |
| var operations = { | |
| 'references': { | |
| provider: 'references', | |
| command: 'textDocument/references', | |
| params: {context: {'includeDeclaration': v:true }}, | |
| }, | |
| 'documentSymbol': { | |
| provider: 'document_symbol', | |
| command: 'textDocument/documentSymbol', | |
| }, | |
| 'diagnostic': { | |
| provider: 'diagnostic', | |
| command: 'textDocument/diagnostic', | |
| }, | |
| 'publishDiagnostics': { | |
| provider: 'publish_diagnostics', | |
| command: 'textDocument/publishDiagnostics', | |
| }, | |
| 'implementation': { | |
| provider: 'implementation', | |
| command: 'textDocument/implementation', | |
| }, | |
| 'workspaceSymbol': { | |
| provider: 'document_symbol', | |
| command: 'workspace/symbol', | |
| }, | |
| 'prepareCallHierarchy': { | |
| provider: 'call_hierarchy', | |
| command: 'textDocument/prepareCallHierarchy', | |
| }, | |
| 'incomingCalls': { | |
| provider: 'call_hierarchy', | |
| command: 'callHierarchy/incomingCalls', | |
| }, | |
| 'outgoingCalls': { | |
| provider: 'call_hierarchy', | |
| command: 'callHierarchy/outgoingCalls', | |
| } | |
| } | |
| var capabilities_func = printf('lsp#capabilities#has_%s_provider(v:val)', operations[op].provider) | |
| var servers = filter(lsp#get_allowed_servers(), capabilities_func) | |
| if len(servers) == 0 | |
| echo printf('Lsp %s not supported', op) | |
| return | |
| endif | |
| if lsp#_new_command() != lsp#_last_command() | |
| return | |
| endif | |
| var ctx = { | |
| 'list': [], | |
| 'jump_if_one': 1, | |
| 'mods': '', | |
| 'in_preview': 0, | |
| } | |
| var params = { | |
| 'textDocument': lsp#get_text_document_identifier(), | |
| 'position': lsp#get_position(), | |
| } | |
| if !empty(conf) | |
| if has_key(conf, "ctx") | |
| extend(ctx, conf["ctx"]) | |
| endif | |
| if has_key(conf, "params") | |
| extend(params, conf["params"]) | |
| endif | |
| endif | |
| for server in servers | |
| lsp#send_request(server, { | |
| 'method': operations[op].command, | |
| 'params': params, | |
| 'on_notification': function(Callback, [ctx, server, op]), | |
| }) | |
| endfor | |
| enddef # LspSendRequest | |
| endif | |
| if !exists('*LspDiagnostics') | |
| # extract vimlsp diagnostics | |
| def LspDiagnostics(FormatFn: func(dict<any>): any): list<any> | |
| var bufnr = bufnr() | |
| if !lsp#internal#diagnostics#state#_is_enabled_for_buffer(bufnr) | |
| return [] | |
| endif | |
| var items = [] | |
| var uri = lsp#utils#get_buffer_uri(bufnr) | |
| for [_, response] in items(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(uri)) | |
| for d in lsp#utils#iteratable(response['params']['diagnostics']) | |
| # add(items, d) | |
| add(items, FormatFn(d)) | |
| endfor | |
| endfor | |
| return items | |
| enddef | |
| endif | |
| if !exists('*FormatDiagnostic') | |
| # format a single diagnostic to common vimgrep format | |
| def FormatDiagnostic(d: dict<any>): string | |
| var code = '' | |
| if exists('d.code') | |
| code = printf("[%s]", d.code) | |
| endif | |
| return printf( | |
| "%s:%d:%d\t%s %s", | |
| bufname(), | |
| d.range.start.line + 1, | |
| d.range.start.character + 1, | |
| code, | |
| d.message | |
| ) | |
| enddef | |
| endif | |
| endif | |
| #### | |
| ## Statusbar | |
| def g:LspNbErrors(): string | |
| var errNb = 0 | |
| if exists('lsp#get_buffer_diagnostics_counts') | |
| errNb = lsp#get_buffer_diagnostics_counts()['error'] | |
| endif | |
| return errNb > 0 ? '[' .. errNb .. ']' : '' | |
| enddef | |
| # status line conf | |
| set statusline=%1*%n | |
| set statusline+=%4*\ ::\ | |
| set statusline+=%2*%f | |
| set statusline+=%5*\ %{g:LspNbErrors()} | |
| set statusline+=%3*\ %m | |
| set statusline+=%*%=\ | |
| set statusline+=%1*%y | |
| set statusline+=%4*\ ::\ | |
| set statusline+=%1*%{strlen(&fenc)?&fenc:&enc} | |
| set statusline+=%4*\ ::\ | |
| set statusline+=%1*%l,%c\ %3*%p%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment