nix/modules/home-manager/cli/neovim/files/options.lua

195 lines
6.1 KiB
Lua

-- General Option
vim.opt.syntax = "off";
vim.g.mapleader = " "
vim.g.maplocalleader = " "
vim.opt.autoindent = true
vim.opt.background = 'dark'
vim.opt.backupdir = os.getenv("HOME") .. '/.local/tmp/nvim'
vim.opt.clipboard = 'unnamedplus' --Use system clipboard
vim.opt.colorcolumn = '80'
vim.opt.directory = os.getenv("HOME") .. '/.local/tmp/nvim'
vim.opt.expandtab = true
-- Foldling code
-- Based on threesitter
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.opt.foldcolumn = "0"
vim.opt.foldtext = ""
vim.opt.foldlevel = 99 -- I don't wand code to be fold by default
vim.opt.foldlevelstart = 1
vim.opt.foldnestmax = 2 -- max nested fold, 2 seems to be quite sufficient
vim.opt.gdefault = true -- search: all occurrences by default
vim.opt.hlsearch = true -- search: hightlight terms
vim.opt.ignorecase = true
vim.opt.incsearch = true
vim.opt.laststatus = 1
-- show special character
vim.opt.listchars = {
tab = '',
trail = '',
space = '·',
eol = '',
extends = '',
precedes = "<"
}
vim.opt.signcolumn = "yes" -- alway show sign column
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.cursorline = true -- highlight current line
vim.opt.showmatch = true
vim.opt.smartcase = true -- search: try :to be smart about cases
vim.opt.smartindent = true
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.softtabstop = 2
vim.opt.wildmenu = true -- activate enhanced user menu
vim.opt.wildmode = 'lastused:full,list' -- enhance menu
vim.opt.pumheight = 10
vim.opt.pumwidth = 50
vim.opt.pumblend = 10
vim.o.winborder = 'none'
-- manage line break smartly
vim.opt.wrap = true
vim.opt.breakindent = true
vim.opt.linebreak = true
vim.opt.showbreak = string.rep(" ", 3) -- Make it so that long lines wrap smartly
-- need to activate this for cmp
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
-- -- Code Fold
-- "Load and save view atomatocally (save and restore fold)
vim.cmd('au BufWinLeave *.* mkview')
vim.cmd('au BufWinEnter *.* silent! loadview')
-- local signs = { Error = "", Warn = "", Hint = "󰌶", Info = "" }
-- for type, icon in pairs(signs) do
-- local hl = "DiagnosticSign" .. type
-- vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
-- end
-- You will likely want to reduce updatetime which affects CursorHold
-- note: this setting is global and should be set only once
vim.o.updatetime = 250
-- vim.cmd [[autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {scope='cursor', header = "", prefix = "", focus=false})]]
-- Autotype
vim.cmd('au BufRead,BufNewFile *.nix setlocal tabstop=2 shiftwidth=2 ')
vim.cmd('au BufNewFile,BufRead /tmp/neomutt* set tw=72 fo=awq comments+=nb:> noautoindent filetype=mail')
-- Ignore these filenames during enhanced command line completion.
vim.opt.wildignore = {
'*.bak',
'*.class',
'*.aux',
'*.out',
'*.toc',
'*.jpg',
'*.bmp',
'*.gif',
'*.png',
'*.luac',
'*.o',
'*.obj',
'*.exe',
'*.dll',
'*.manifest',
'*.pyc',
'*.spl',
'*.sw?'
}
-- disable lsplog
-- This is not usefull on a daily basis and should positively impact performance
vim.lsp.set_log_level("off")
-- define a timeout for match parens
vim.g.matchparen_timeout = 10
vim.g.matchparen_insert_timeout = 10
-- activate virtual lines for diagnistics
-- no more plugins needed
local x = vim.diagnostic.severity
vim.diagnostic.config({
virtual_lines = true,
-- Alternatively, customize specific options
-- virtual_lines = {
-- -- Only show virtual line diagnostics for the current cursor line
-- current_line = true,
-- },
signs = { text = { [x.ERROR] = "󰅙", [x.WARN] = "", [x.INFO] = "󰋼", [x.HINT] = "󰌵" } },
})
-- LSP
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
local opts = { buffer = ev.buf }
local client = vim.lsp.get_client_by_id(ev.data.client_id)
local bufnr = ev.buf
local function desc(description)
return { noremap = true, silent = true, buffer = bufnr, desc = description }
end
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { buffer = ev.buf, desc = "Go to [D]eclaration" })
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = ev.buf, desc = "Go to [d]efinition" })
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { buffer = ev.buf, desc = "Go to [i]mplementation" })
vim.keymap.set("n", "gr", vim.lsp.buf.references, { buffer = ev.buf, desc = "Go to [r]eferences" })
vim.keymap.set(
"n",
"K",
function()
vim.lsp.buf.hover
{ border = "rounded", max_width = 250 }
end,
opts)
vim.keymap.set(
"n",
"<C-k>",
function()
vim.lsp.buf.signature_help
{ border = "rounded", max_width = 250 }
end,
{buffer = ev.buf, desc = "Signature help"}
)
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set(
"n",
"<leader>wl",
function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end,
opts
)
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, { buffer = ev.buf, desc = "Type [D]efinition" })
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { buffer = ev.buf, desc = "LSP [r]e[n]ame" })
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, { buffer = ev.buf, desc = "Show [c]ode [a]ction"})
vim.keymap.set(
"n",
"<leader>F",
function()
require("conform").format({ bufnr = bufnr })
end,
{ buffer = ev.buf, desc = "[F]ormat file" }
)
if client.server_capabilities.inlayHintProvider then
vim.keymap.set("n", "<space>h", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end, desc("LSP toggle inlay [h]ints"))
end
end,
})