---@diagnostic disable: undefined-global vim.o.termguicolors = true vim.o.relativenumber = true vim.o.number = true vim.o.cc = "80" vim.o.updatetime = 1000 vim.o.splitright = true vim.o.splitbelow = true vim.o.signcolumn = "no" vim.o.ignorecase = true vim.o.tabstop = 2 vim.o.shiftwidth = 0 vim.o.expandtab = true vim.o.undofile = true vim.o.scrolloff = 10 vim.o.winborder = "single" vim.o.mouse = "" vim.o.completeopt = "menu,menuone,noselect" vim.o.backup = false vim.o.writebackup = false vim.o.swapfile = false vim.opt.cinoptions:append(":0,N-s,E-s,(s,Ws") vim.g.mapleader = " " vim.pack.add({ "https://github.com/neovim/nvim-lspconfig", "https://github.com/nvim-mini/mini.pick", "https://github.com/stevearc/oil.nvim", {src="https://github.com/nvim-treesitter/nvim-treesitter", version="main"}, }) for _, plugin in ipairs(vim.pack.get()) do if not plugin.active then vim.pack.del({plugin.path:match(".*/(.*)$")}) end end require("mini.pick").setup({ window = { config = { border = "single" }, }, }) require("oil").setup({ view_options = {show_hidden=true}, }) require("nvim-treesitter").install({"c", "cpp", "lua", "odin", "vim", "vimdoc"}) require("nvim-treesitter").setup() vim.api.nvim_create_autocmd("FileType", { pattern = "odin", callback = function() vim.treesitter.start() end, }) vim.keymap.set("t", "", "") vim.keymap.set("n", "t", ":hori term:resize 20") vim.keymap.set("n", "f", ":Pick files tool='rg'") vim.keymap.set("v", "p", '"_dP', opts) -- Switch between semantically related files easily :) local exts = {{"c", "h"}, {"cc", "hh"}, {"cpp", "hpp"}, {"frag", "vert"}} vim.keymap.set("n", "s", function() local bufpath = vim.api.nvim_buf_get_name(0) for _, pair in ipairs(exts) do for i, ext in ipairs(pair) do if bufpath:match("%." .. ext .. "$") then local other = pair[i % #pair + 1] vim.cmd("e " .. bufpath:gsub("%." .. ext .. "$", "." .. other)) return end end end print("no files to swap to") end) local function get_symbols(kind) local bufnr = vim.api.nvim_get_current_buf() local clients = vim.lsp.get_clients({ bufnr = bufnr, }) local client = clients[1] client:request( "textDocument/documentSymbol", {textDocument=vim.lsp.util.make_text_document_params()}, function(_, funcs) local list = {} for _, func in ipairs(funcs) do if func.kind == kind then table.insert(list, { bufnr = bufnr, lnum = func.range.start.line + 1, end_lnum = func.range["end"].line + 1, col = func.range.start.character, end_col = func.range.start.character, text = func.name .. "()", }) end end table.sort(list, function(a, b) return a.lnum < b.lnum end) vim.fn.setqflist(list) vim.cmd[[cope]] vim.cmd[[cfirst]] end ) end vim.keymap.set("n", "o", function() get_symbols(12) end) vim.lsp.enable({"lua_ls", "clangd", "ols"}) vim.diagnostic.config({ virtual_text = true, severity_sort = true, }) vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) local opts = {silent=true, buffer=ev.buf} vim.keymap.set("n", "gD", function() vim.lsp.buf.declaration() end, opts) vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) local client = vim.lsp.get_client_by_id(ev.data.client_id) local chars = {} for i = 32, 126 do table.insert(chars, string.char(i)) end if client:supports_method("textDocument/completion") then client.server_capabilities.completionProvider.triggerCharacters = chars vim.lsp.completion.enable(true, client.id, ev.buf, {autotrigger=true}) end end, }) vim.cmd.colorscheme("lunaperche") vim.api.nvim_create_user_command("Ex", "Oil", {}) -- require('vim._extui').enable({})