358 lines
11 KiB
Nix
358 lines
11 KiB
Nix
{pkgs, ...}: {
|
|
programs.neovim = {
|
|
enable = false;
|
|
defaultEditor = true;
|
|
viAlias = true;
|
|
vimAlias = true;
|
|
vimdiffAlias = true;
|
|
withRuby = false;
|
|
withPython3 = false;
|
|
|
|
plugins = with pkgs.vimPlugins; [
|
|
vim-commentary
|
|
plenary-nvim
|
|
cmp-nvim-lsp
|
|
cmp-buffer
|
|
cmp-path
|
|
nvim-web-devicons
|
|
lsp_extensions-nvim
|
|
lsp_signature-nvim
|
|
telescope-nvim
|
|
onedark-nvim
|
|
{
|
|
plugin = fidget-nvim;
|
|
type = "lua";
|
|
config =
|
|
/*
|
|
lua
|
|
*/
|
|
''
|
|
require('fidget').setup {}
|
|
'';
|
|
}
|
|
{
|
|
plugin = symbols-outline-nvim;
|
|
type = "lua";
|
|
config =
|
|
/*
|
|
lua
|
|
*/
|
|
''
|
|
require('symbols-outline').setup()
|
|
'';
|
|
}
|
|
{
|
|
plugin = nvim-treesitter.withAllGrammars;
|
|
type = "lua";
|
|
config =
|
|
/*
|
|
lua
|
|
*/
|
|
''
|
|
require('nvim-treesitter.configs').setup {
|
|
highlight = {
|
|
enable = true, -- false will disable the whole extension
|
|
},
|
|
incremental_selection = {
|
|
enable = false,
|
|
keymaps = {
|
|
init_selection = 'gnn',
|
|
node_incremental = 'grn',
|
|
scope_incremental = 'grc',
|
|
node_decremental = 'grm',
|
|
},
|
|
},
|
|
indent = {
|
|
enable = true,
|
|
}
|
|
}
|
|
'';
|
|
}
|
|
{
|
|
plugin = nvim-tree-lua;
|
|
type = "lua";
|
|
config =
|
|
/*
|
|
lua
|
|
*/
|
|
''
|
|
local function my_on_attach(bufnr)
|
|
local api = require "nvim-tree.api"
|
|
|
|
local function opts(desc)
|
|
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
|
|
end
|
|
|
|
-- default mappings
|
|
api.config.mappings.default_on_attach(bufnr)
|
|
|
|
-- custom mappings
|
|
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
|
|
vim.keymap.set('n', 's', api.node.open.horizontal, opts('Paste File'))
|
|
vim.keymap.set('n', 'ma', api.fs.create, opts('New File'))
|
|
vim.keymap.set('n', 'md', api.fs.remove, opts('Delete File'))
|
|
vim.keymap.set('n', 'me', api.fs.rename_node, opts('Rename File'))
|
|
vim.keymap.set('n', 'yy', api.fs.copy.node, opts('Copy File'))
|
|
vim.keymap.set('n', 'mp', api.fs.paste, opts('Paste File'))
|
|
end
|
|
|
|
require("nvim-tree").setup {
|
|
on_attach = my_on_attach,
|
|
}
|
|
'';
|
|
}
|
|
{
|
|
plugin = nvim-cmp;
|
|
type = "lua";
|
|
config =
|
|
/*
|
|
lua
|
|
*/
|
|
''
|
|
-- local luasnip = require 'luasnip'
|
|
local cmp = require 'cmp'
|
|
|
|
cmp.setup {
|
|
-- snippet = {
|
|
-- expand = function(args)
|
|
-- require('luasnip').lsp_expand(args.body)
|
|
-- end,
|
|
-- },
|
|
window = {
|
|
-- documentation = true,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
['<C-e>'] = cmp.mapping.close(),
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = true,
|
|
},
|
|
['<Tab>'] = function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
['<S-Tab>'] = function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
}),
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
-- { name = 'luasnip' },
|
|
{ name = 'buffer' },
|
|
{ name = 'path' },
|
|
-- { name = 'latex_symbols' },
|
|
},
|
|
}
|
|
'';
|
|
}
|
|
{
|
|
plugin = nvim-lspconfig;
|
|
type = "lua";
|
|
config =
|
|
/*
|
|
lua
|
|
*/
|
|
''
|
|
function hi(name, opts)
|
|
local options = ""
|
|
for k, v in pairs(opts) do
|
|
options = options.." "..k.."="..v
|
|
end
|
|
vim.cmd("highlight "..name..options)
|
|
end
|
|
|
|
local u = require('utils')
|
|
local lspc = require('lspconfig')
|
|
local ih = require("inlay-hints")
|
|
ih.setup()
|
|
|
|
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
|
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
buf_set_keymap('n', '<c-]>', ':lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()<CR>', opts)
|
|
buf_set_keymap('n', 'gD', ':lua vim.lsp.buf.implementation()<CR>', opts)
|
|
buf_set_keymap('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
buf_set_keymap('n', '1gD', ':lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
buf_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()<CR>', opts)
|
|
buf_set_keymap('n', 'g0', ':lua vim.lsp.buf.document_symbol()<CR>', opts)
|
|
buf_set_keymap('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()<CR>', opts)
|
|
buf_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'ga', ':lua vim.lsp.buf.code_action()<CR>', opts)
|
|
buf_set_keymap('n', 'ff', ':lua vim.lsp.buf.format({async = true})<CR>', opts)
|
|
buf_set_keymap('n', 'gn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
|
--require'completion'.on_attach(client)
|
|
|
|
-- Set highlight colors
|
|
local highlights = {
|
|
Error = "Red",
|
|
Warning = "Yellow",
|
|
Information = "Blue",
|
|
Hint = "Green",
|
|
}
|
|
|
|
for typ, color in pairs(highlights) do
|
|
hi('LspDiagnosticsDefault'..typ, {ctermfg = color})
|
|
hi('LspDiagnosticsUnderline'..typ, {cterm = 'underline'})
|
|
end
|
|
|
|
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(
|
|
vim.lsp.diagnostic.on_publish_diagnostics,
|
|
{
|
|
virtual_text = true,
|
|
signs = true,
|
|
update_in_insert = true,
|
|
underline = true
|
|
}
|
|
)
|
|
require "lsp_signature".on_attach({doc_lines = 0})
|
|
ih.on_attach(client, bufnr)
|
|
end
|
|
|
|
-- nvim-cmp supports additional completion capabilities
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
|
|
|
|
|
local config = {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
flags = {debounce_text_changes = 150}
|
|
}
|
|
|
|
lspc.bashls.setup(config)
|
|
lspc.nixd.setup(config)
|
|
lspc.solargraph.setup(config)
|
|
|
|
lspc.rust_analyzer.setup{
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
flags = {debounce_text_changes = 150},
|
|
settings = {
|
|
['rust-analyzer'] = {
|
|
assist = {
|
|
importGranularity = "module",
|
|
importPrefix = "by_self",
|
|
},
|
|
cargo = {
|
|
loadOutDirsFromCheck = true
|
|
},
|
|
procMacro = {
|
|
enable = true
|
|
},
|
|
checkOnSave = {
|
|
command = "clippy"
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
-- Set completeopt to have a better completion experience
|
|
vim.o.completeopt = 'menuone,noselect'
|
|
'';
|
|
}
|
|
];
|
|
|
|
extraLuaConfig =
|
|
/*
|
|
lua
|
|
*/
|
|
''
|
|
local onedark = require('onedark')
|
|
onedark.setup { style = 'warmer' }
|
|
onedark.load()
|
|
vim.cmd('set background=dark')
|
|
|
|
local llc = require('lualine').get_config()
|
|
llc.options.theme = 'onedark'
|
|
require('lualine').setup(llc)
|
|
|
|
local key = vim.api.nvim_set_keymap
|
|
local o = vim.o
|
|
local wo = vim.wo
|
|
local bo = vim.bo
|
|
local cmd = vim.cmd
|
|
|
|
vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float({focusable = false})]])
|
|
|
|
key('n', ';', ':Telescope find_files<CR>', {})
|
|
key('n', '<C-n>', ':NvimTreeToggle<CR>', {})
|
|
key('n', 'gh', '/<c-r>=expand("<cword>")<CR><CR>N', {})
|
|
|
|
key('i', '<TAB>', 'pumvisible() ? "<C-n>" : "<Tab>"', { expr = true, silent = true })
|
|
key('i', '<S-TAB>', 'pumvisible() ? "<C-p>" : "<S-Tab>"', { expr = true, silent = true })
|
|
key('n', '<leader>g', ':lua require"telescope.builtin".live_grep{}<CR>', {})
|
|
key('v', '<leader>c', ':w !wl-copy<CR><CR>', { silent = true })
|
|
|
|
vim.api.nvim_exec(
|
|
[[
|
|
augroup YankHighlight
|
|
autocmd!
|
|
autocmd TextYankPost * silent! lua vim.highlight.on_yank()
|
|
augroup end
|
|
]] ,
|
|
false
|
|
)
|
|
|
|
vim.api.nvim_create_autocmd("BufEnter", {
|
|
nested = true,
|
|
callback = function()
|
|
if #vim.api.nvim_list_wins() == 1 and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil then
|
|
vim.cmd 'quit'
|
|
end
|
|
end
|
|
})
|
|
|
|
cmd('syntax on')
|
|
cmd('set number')
|
|
cmd('set completeopt=menuone,noinsert,noselect')
|
|
cmd('set shortmess+=c')
|
|
cmd("autocmd CursorHold,CursorHoldI *.rs :lua require'lsp_extensions'.inlay_hints{ only_current_line = true }")
|
|
|
|
o.startofline = true
|
|
wo.cursorline = true
|
|
|
|
o.updatetime = 300
|
|
wo.signcolumn='yes'
|
|
o.showcmd = true
|
|
|
|
o.shell = 'bash'
|
|
o.mouse = 'a'
|
|
|
|
o.smarttab = true
|
|
bo.tabstop = 2
|
|
bo.shiftwidth = 2
|
|
bo.expandtab = true
|
|
|
|
wo.relativenumber = true
|
|
o.hidden = true
|
|
|
|
'';
|
|
|
|
extraPackages = with pkgs; [
|
|
shfmt
|
|
nixd
|
|
nodePackages.bash-language-server
|
|
];
|
|
};
|
|
}
|