nixconf/modules/home/neovim/nvim.lua

161 lines
5.5 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

if vim.g.neovide then
vim.o.guifont = "FantasqueSansM Nerd Font:h10"
vim.g.neovide_cursor_animation_length = 0.1
vim.g.neovide_cursor_trail_size = 0.2
vim.g.neovide_cursor_vfx_mode = "sonicboom"
vim.g.neovide_cursor_animate_command_line = false
end
vim.go.mouse = "a"
vim.go.showmode = false
vim.go.termguicolors = true
vim.go.shell = "fish"
vim.go.completeopt = "menuone,noinsert,noselect,preview"
vim.go.expandtab = false -- Tabs over spaces because accessibility.
vim.go.shiftwidth = 2
vim.go.tabstop = 2
vim.go.listchars="tab:⇤–⇥,space:·,trail:·,precedes:⇠,extends:⇢,nbsp:×"
vim.wo.list = true
vim.wo.number = true
-- Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.hlsearch = false
vim.g.mapleader = " "
local lsp_servers = {
clangd = {},
biome = {},
nil_ls = {},
pylsp = {
pylsp = {
configurationSources = "flake8",
plugins = {
pycodestyle = {
enabled = false
}
}
}
},
rust_analyzer = {
checkOnSave = {
command = "clippy",
},
},
}
vim.api.nvim_create_autocmd("TermOpen", {
command = "setlocal nonumber",
})
vim.api.nvim_create_autocmd("TermOpen", {
command = "startinsert"
})
vim.keymap.set("n", "<leader>t", "<cmd>below split | terminal<cr>", { desc = "open terminal" })
vim.keymap.set("n", "<leader>e", "<cmd>Neotree toggle reveal<cr>", { desc = "Reveal neotree" })
vim.keymap.set("n", "<leader>wv", "<cmd>vsplit<cr>", { desc = "tall split" })
vim.keymap.set("n", "<leader>ws", "<cmd>split<cr>", { desc = "wide split" })
vim.keymap.set("n", "<leader>wr", "<cmd>winc r<cr>", { desc = "swap windows" })
vim.keymap.set("n", "<leader>ww", "<cmd>winc w<cr>", { desc = "next window" })
vim.keymap.set("n", "<leader>wn", "<cmd>winc w<cr>", { desc = "next window" })
vim.keymap.set("n", "<leader>wd", "<cmd>quit<cr>", { desc = "close window" })
vim.keymap.set("n", "<leader>wq", "<cmd>quit<cr>", { desc = "close window" })
vim.keymap.set("n", "<leader>bn", "<cmd>bn<cr>", { desc = "next buffer" })
vim.keymap.set("n", "<leader>bp", "<cmd>bp<cr>", { desc = "prev buffer" })
vim.keymap.set("n", "<leader>bd", "<cmd>bd<cr>", { desc = "close buffer" })
vim.keymap.set("n", "<leader>bc", "<cmd>bd<cr>", { desc = "close buffer" })
vim.keymap.set("n", "<leader>bl", require('telescope.builtin').buffers, { desc = "list buffers" })
vim.keymap.set("n", "<leader>/", require('telescope.builtin').live_grep, { desc = "grep" })
vim.keymap.set('n', '<leader>d', require('telescope.builtin').diagnostics, { desc = "diagnostics"})
vim.keymap.set("n", "<leader>ff", require('telescope.builtin').find_files, { desc = "find files" })
vim.keymap.set("n", "<leader>fd", require('telescope').extensions.zoxide.list, { desc = "change directory" })
vim.keymap.set("n", "<leader>fr", require('telescope.builtin').oldfiles, { desc = "recent files" })
local custom_attach = function(client, bufnr)
-- Mapping helper function.
local kmap = function(key, cmd, desc)
vim.keymap.set("n", key, cmd, {silent = true, buffer = bufnr, desc = desc })
end
kmap('K', vim.lsp.buf.hover, 'Hover Documentation')
kmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
kmap("gd", vim.lsp.buf.definition, "goto definition")
kmap("gr", require('telescope.builtin').lsp_references, "show references")
kmap("<leader>lr", vim.lsp.buf.rename, "rename variable")
kmap("<leader>ls", require('telescope.builtin').lsp_workspace_symbols, "search symbols")
kmap("<leader>la", vim.lsp.buf.code_action, "code action")
kmap("<leader>lwa", vim.lsp.buf.add_workspace_folder, "add workspace folder")
kmap("<leader>lwr", vim.lsp.buf.remove_workspace_folder, "remove workspace folder")
kmap("<leader>lwl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, "list workspace folder")
-- Set some key bindings conditional on server capabilities
if client.server_capabilities.documentFormattingProvider then
kmap("<leader>lf", vim.lsp.buf.format, "format code")
end
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
vim.api.nvim_buf_set_option(bufnr, "completefunc", "v:lua.vim.lsp.omnifunc")
vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local float_opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = "rounded",
source = "always", -- show source in diagnostic popup window
prefix = " ",
}
if #vim.diagnostic.get() > 0 then
vim.diagnostic.open_float(nil, float_opts)
end
end
})
if vim.g.logging_level == "debug" then
local msg = string.format("Language server %s started!", client.name)
vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" })
end
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- Configure each server
local lspconfig = require 'lspconfig'
for server_name, config in pairs(lsp_servers) do
lspconfig[server_name].setup {
capabilities = capabilities,
on_attach = custom_attach,
settings = config,
}
end
-- Change diagnostic signs.
vim.fn.sign_define("DiagnosticSignError", { text = "", texthl = "DiagnosticSignError" })
vim.fn.sign_define("DiagnosticSignWarn", { text = "!", texthl = "DiagnosticSignWarn" })
vim.fn.sign_define("DiagnosticSignInformation", { text = "", texthl = "DiagnosticSignInfo" })
vim.fn.sign_define("DiagnosticSignHint", { text = ">", texthl = "DiagnosticSignHint" })
-- global config for diagnostic
vim.diagnostic.config {
underline = false,
virtual_text = false,
signs = true,
severity_sort = true,
}
-- vim: ts=2 sw=2