" vim: fdm=marker:fdl=0:noml: set rtp^=$XDG_CONFIG_HOME/vim set rtp+=$XDG_CONFIG_HOME/vim/after set pp^=$XDG_CONFIG_HOME/vim set pp+=$XDG_CONFIG_HOME/vim/after let &packpath=&runtimepath if filereadable(expand('$XDG_CONFIG_HOME/vim/vimrc')) so $XDG_CONFIG_HOME/vim/vimrc endif " for faster startup lua vim.loader.enable() "lua<ar', 'lua vim.lsp.buf.rename()') " map('n', 's', 'lua vim.lsp.buf.format({ async = true })') " map('n', 'K', 'lua vim.lsp.buf.hover()') "end lua <I', vim.diagnostic.setloclist) vim.keymap.set('n', 'T', vim.treesitter.inspect_tree, { desc = 'Show the inspected syntax tree for the whole document.' }) vim.keymap.set('n', 'K', function() vim.diagnostic.open_float{ scope = "line", header = '', focus = false } end, { desc = 'show information about line diagnostics in a float' }) local triggers = {'.'} vim.api.nvim_create_autocmd('InsertCharPre', { buffer = vim.api.nvim_get_current_buf(), callback = function() if vim.fn.pumvisible() == 1 or vim.fn.state('m') == 'm' then return end local char = vim.v.char if vim.list_contains(triggers, char) then local key = vim.keycode('') vim.api.nvim_feedkeys(key, 'm', false) end end }) vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { group = vim.api.nvim_create_augroup("float_diagnostic_cursor", { clear = true }), callback = function() vim.diagnostic.open_float(nil, { focus = false, scope = "cursor" }) end, }) local function peek_definition() local params = vim.lsp.util.make_position_params() return vim.lsp.buf_request(0, 'textDocument/definition', params, function(_, result, _) if result == nil or vim.tbl_isempty(result) then vim.notify('No definition found.') return nil end if vim.islist(result) then result = result[1] end vim.lsp.util.preview_location(result, { border = 'single' }) end) end vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) -- vim.bo[args.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' local bufnr = args.buf local client = vim.lsp.get_client_by_id(args.data.client_id) -- local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) if client:supports_method("textDocument/completion") then -- trigger auto-complete on every alpha character local chars = {} for i = 65, 122 do table.insert(chars, string.char(i)) end table.insert(chars, ".") table.insert(chars, ">") client.server_capabilities.completionProvider.triggerCharacters = chars vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true }) end local opts = { noremap = true, buffer = bufnr } vim.keymap.set('n', 'gb', vim.lsp.buf.implementation, opts) vim.keymap.set('n', 'gK', peek_definition, opts) if client.supports_method('textDocument/formatting') then vim.keymap.set('n', 'z', vim.lsp.buf.format, opts) end if client.supports_method('textDocument/typeDefinition') then vim.keymap.set('n', 'gy', vim.lsp.buf.type_definition, opts) end if client.supports_method('textDocument/codeAction') then vim.keymap.set('n', 'a', vim.lsp.buf.code_action, opts) vim.keymap.set('i', '', vim.lsp.buf.code_action, opts) end if client.supports_method('textDocument/codeLens') then vim.keymap.set('n', 'Le', vim.lsp.codelens.display, opts) vim.keymap.set('n', 'Ln', vim.lsp.codelens.run, opts) vim.api.nvim_create_autocmd({ 'BufEnter', 'CursorHold', 'InsertLeave' }, { buffer = bufnr, callback = function() vim.lsp.codelens.refresh{ bufnr = bufnr } end, }) end if client.supports_method('textDocument/inlayHint') then -- vim.cmd [[hi link LspInlayHint SpecialComment]] vim.keymap.set({ 'n', 'i' }, '', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled{ bufnr = bufnr }, { bufnr = bufnr }) end, opts) end end }) EOF " }}} " runtime! init.d/* "---------------------------------------------------------------------------- " for faster startup | lua vim.loader.enable() lua<< vim.loader.enable() -- vim.api.nvim_create_autocmd('BufWritePre', { -- pattern = '*.go', -- callback = function() -- vim.lsp.buf.format() -- vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true }) -- end -- }) -- auto-format *.rs (rust) files prior to saving them -- (async = false is the default for format) -- autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false }) -- auto-format ("lint") on save. -- usually not needed if server supports "textDocument/willSaveWaitUntil". -- 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('lspconf', {clear=false}), -- buffer = args.buf, -- callback = function() -- vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) -- end, -- }) -- end -- vim.keymap.set("n", "c", function() -- vim.ui.input({}, function(c) -- if c and c~="" then -- vim.cmd("noswapfile vnew") -- vim.bo.buftype = "nofile" -- vim.bo.bufhidden = "wipe" -- vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.fn.systemlist(c)) -- end -- end) -- end) -- -- pretty print lua table -- function _G.dump(...) -- local objects = vim.tbl_map(vim.inspect, { ... }) -- print(unpack(objects)) -- end -- _G.nvim = vim.defaulttable(function(k) -- return vim.api[("nvim_%s"):format(k)] -- end) -- . _G.nvim = vim.defaulttable(function(k) return vim.api[("nvim_%s"):format(k)] end) .