fix(nvim): Translate augroups and autocmds to nixvim

This commit is contained in:
Jalil David Salamé Messina 2024-03-02 21:04:02 +01:00
parent 8ea1f67f07
commit b2b9477041
Signed by: jalil
GPG key ID: F016B9E770737A0B
2 changed files with 81 additions and 72 deletions

View file

@ -1,54 +1,61 @@
{ {
highlightOnYank.name = "highlightOnYank"; autoGroups."highlightOnYank" = { };
highlightOnYank.autocmds = [ autoGroups."runLinter" = { };
autoGroups."lspConfig" = { };
autoGroups."restoreCursorPosition" = { };
autoCmd = [
{ {
group = "highlightOnYank";
event = "TextYankPost"; event = "TextYankPost";
pattern = "*"; pattern = "*";
luaCallback = '' callback = {
__raw = ''
function()
vim.highlight.on_yank { vim.highlight.on_yank {
higroup = ( higroup = (
vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch' vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch'
), ),
timeout = 200, timeout = 200,
} }
end
''; '';
};
} }
];
runLinter.name = "runLinter";
runLinter.autocmds = [
{ {
group = "runLinter";
event = "BufWritePost"; event = "BufWritePost";
pattern = "*"; pattern = "*";
luaCallback = '' callback = {
__raw = ''
require("lint").try_lint() require("lint").try_lint()
''; '';
};
} }
];
restoreCursorPosition.name = "restoreCursorPosition";
restoreCursorPosition.autocmds = [
{ {
group = "restoreCursorPosition";
event = "BufReadPost"; event = "BufReadPost";
pattern = "*"; pattern = "*";
luaCallback = '' callback = {
__raw = ''
function()
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then
vim.cmd [[execute "normal! g'\""]] vim.cmd [[execute "normal! g'\""]]
end end
end
''; '';
};
} }
];
lspConfig.name = "lspConfig";
lspConfig.autocmds = [
{ {
group = "lspConfig";
event = "LspAttach"; event = "LspAttach";
pattern = "*"; pattern = "*";
luaCallback = callback =
let let
opts = "noremap = true, buffer = bufnr"; opts = "noremap = true, buffer = bufnr";
in in
'' {
__raw = ''
function(opts)
local bufnr = opts.buf local bufnr = opts.buf
local client = vim.lsp.get_client_by_id(opts.data.client_id) local client = vim.lsp.get_client_by_id(opts.data.client_id)
local capabilities = client.server_capabilities local capabilities = client.server_capabilities
@ -87,7 +94,9 @@
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = '[G]o to [D]efinition', ${opts} }) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = '[G]o to [D]efinition', ${opts} })
vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, { desc = '[G]o to [T]ype Definition', ${opts} }) vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, { desc = '[G]o to [T]ype Definition', ${opts} })
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = '[G]o to [I]mplementation', ${opts} }) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = '[G]o to [I]mplementation', ${opts} })
end
''; '';
};
} }
]; ];
} }

View file

@ -38,8 +38,8 @@ in
# Enable local configuration :h 'exrc' # Enable local configuration :h 'exrc'
options.exrc = true; # safe since nvim 0.9 options.exrc = true; # safe since nvim 0.9
plugins = import ./plugins; plugins = import ./plugins;
augroups = import ./augroups.nix;
keymaps = import ./mappings.nix; keymaps = import ./mappings.nix;
inherit (import ./augroups.nix) autoGroups autoCmd;
extraPlugins = extraPlugins =
(with pkgs.vimExtraPlugins; [ (with pkgs.vimExtraPlugins; [
dressing-nvim dressing-nvim