refactor(nvim): move stuff to lua, fix windows depending on size of win, etc
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-05-08 20:26:57 -04:00
parent a7c57a6501
commit 6753c39ccd
16 changed files with 316 additions and 207 deletions

View file

@ -5,7 +5,6 @@
...
}: let
inherit (config.vars) neovimIde;
inherit (lib) fileContents;
inherit (pkgs) vimPlugins;
in
lib.mkIf neovimIde {
@ -26,11 +25,6 @@ in
lua
*/
''
vim.api.nvim_create_autocmd("FileType", {
pattern = 'hyprlang',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
vim.api.nvim_create_user_command("Format", "call CocAction('format')", {});
-- Always show the signcolumn, otherwise it would shift the text each time
@ -42,7 +36,25 @@ in
{
plugin = vimPlugins.coc-snippets;
type = "viml";
config = fileContents ./plugins/snippets.vim;
config =
/*
vim
*/
''
" use vscode keybinds for snippets completion
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump','''])\<CR>" :
\ CheckBackspace() ? "\<TAB>" :
\ coc#refresh()
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
'';
}
## Fzf
@ -52,6 +64,33 @@ in
vimPlugins.coc-json
vimPlugins.coc-yaml
vimPlugins.coc-toml
{
plugin = vimPlugins.nvim-autopairs;
type = "lua";
config =
/*
lua
*/
''
-- Auto indent when pressing Enter between brackets
local remap = vim.api.nvim_set_keymap
local npairs = require('nvim-autopairs')
npairs.setup({map_cr=false})
_G.MUtils= {}
MUtils.completion_confirm=function()
if vim.fn["coc#pum#visible"]() ~= 0 then
return vim.fn["coc#pum#confirm"]()
else
return npairs.autopairs_cr()
end
end
remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
'';
}
];
};
};

View file

@ -1,15 +1,13 @@
{
config,
pkgs,
lib,
...
}: let
inherit (config.vars) neovimIde;
inherit (lib) fileContents optionals;
inherit (pkgs) vimPlugins;
in {
imports = [
./coc.nix
./git.nix
./langs
./theme.nix
./treesitter.nix
@ -38,59 +36,49 @@ in {
vim.opt.undodir = '${config.xdg.cacheHome}/nvim/';
-- remove highlight on words
vim.cmd[[nnoremap <silent> <esc> :noh<cr><esc>]];
vim.keymap.set('n', '<esc>', ':noh<cr><esc>', { noremap = true, silent = true });
'';
plugins =
[
vimPlugins.fzfWrapper
vimPlugins.fzf-vim
vimPlugins.fugitive
{
plugin = vimPlugins.todo-comments-nvim;
type = "lua";
config =
/*
lua
*/
''
require('todo-comments').setup();
'';
}
{
plugin = vimPlugins.gitsigns-nvim;
type = "lua";
config = fileContents ./plugins/gitsigns.lua;
}
{
plugin = vimPlugins.mini-nvim;
type = "lua";
config = fileContents ./plugins/mini.lua;
}
{
plugin = vimPlugins.codewindow-nvim;
type = "lua";
config =
/*
lua
*/
''
require('codewindow').setup({
auto_enable = true,
minimap_width = 8,
relative = 'editor',
window_border = 'none',
});
'';
}
]
++ optionals neovimIde [
{
plugin = vimPlugins.nvim-autopairs;
type = "lua";
config = fileContents ./plugins/autopairs.lua;
}
];
plugins = [
vimPlugins.fzfWrapper
vimPlugins.fzf-vim
{
plugin = vimPlugins.todo-comments-nvim;
type = "lua";
config =
/*
lua
*/
''
require('todo-comments').setup();
'';
}
{
plugin = vimPlugins.mini-nvim;
type = "lua";
config =
/*
lua
*/
''
-- TODO: see how this works
local ts_input = require('mini.surround').gen_spec.input.treesitter;
require('mini.surround').setup({
custom_surroundings = {
-- Use tree-sitter to search for function call
f = {
input = ts_input({
outer = '@call.outer',
inner = '@call.inner',
});
},
},
});
'';
}
];
};
};
}

View file

@ -0,0 +1,35 @@
{pkgs, ...}: let
inherit (pkgs) vimPlugins;
in {
programs = {
neovim = {
plugins = [
vimPlugins.fugitive
{
plugin = vimPlugins.gitsigns-nvim;
type = "lua";
config =
/*
lua
*/
''
local gitsigns = require("gitsigns");
local function visual_stage()
local first_line = vim.fn.line('v');
local last_line = vim.fn.getpos('.')[2];
gitsigns.stage_hunk({ first_line, last_line });
end
vim.keymap.set("v", "gs", function()
visual_stage()
end);
gitsigns.setup();
'';
}
];
};
};
}

View file

@ -32,7 +32,6 @@ in
'';
coc.settings = {
# Bash
bashIde.shellcheckPath = "${pkgs.shellcheck}/bin/shellcheck";
};

View file

@ -2,6 +2,7 @@
imports = [
./bash.nix
./clang.nix
./hyprlang.nix
./java.nix
./lua.nix
./markdown.nix

View file

@ -0,0 +1,27 @@
{
config,
lib,
...
}: let
inherit (config.vars) neovimIde;
in
lib.mkIf neovimIde {
programs = {
neovim = {
extraLuaConfig =
/*
lua
*/
''
vim.filetype.add({
pattern = { [".*/hypr/.*%.conf"] = "hyprlang" },
});
vim.api.nvim_create_autocmd("FileType", {
pattern = 'hyprlang',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
'';
};
};
}

View file

@ -0,0 +1,64 @@
-- Override netrw
vim.g.loaded_netrw = 0
vim.g.loaded_netrwPlugin = 0
require('neo-tree').setup({
close_if_last_window = true,
enable_refresh_on_write = true,
window = {
width = 22,
},
filesystem = {
use_libuv_file_watcher = true,
group_empty_dirs = true,
filtered_items = {
visible = false,
hide_dotfiles = false,
hide_gitignored = true,
hide_by_name = {},
hide_by_pattern = {},
always_show = {},
never_show = {},
never_show_by_pattern = {},
},
},
source_selector = {
winbar = true,
statusline = false
},
follow_current_file = {
enabled = true,
leave_dirs_open = true,
}
})
local function is_neotree_open()
local manager = require("neo-tree.sources.manager")
local renderer = require("neo-tree.ui.renderer")
local state = manager.get_state("filesystem")
local window_exists = renderer.window_exists(state)
return window_exists
end
-- Auto open Neo-Tree on big enough window
vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResized' }, {
pattern = '*',
callback = function()
if vim.api.nvim_eval([[&columns]]) > 100 then
if is_neotree_open() == false then
vim.cmd [[Neotree show]];
vim.cmd [[Neotree close]];
vim.cmd [[Neotree show]];
end
else
if is_neotree_open() then
vim.cmd [[Neotree close]];
end
end
end,
});

View file

@ -1,16 +0,0 @@
-- Auto indent when pressing Enter between brackets
local remap = vim.api.nvim_set_keymap
local npairs = require('nvim-autopairs')
npairs.setup({map_cr=false})
_G.MUtils= {}
MUtils.completion_confirm=function()
if vim.fn["coc#pum#visible"]() ~= 0 then
return vim.fn["coc#pum#confirm"]()
else
return npairs.autopairs_cr()
end
end
remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})

View file

@ -1,13 +0,0 @@
local gitsigns = require("gitsigns")
local function visual_stage()
local first_line = vim.fn.line('v')
local last_line = vim.fn.getpos('.')[2]
gitsigns.stage_hunk({ first_line, last_line })
end
vim.keymap.set("v", "gs", function()
visual_stage()
end)
gitsigns.setup();

View file

@ -1,26 +0,0 @@
local highlight = {
"RainbowRed",
"RainbowYellow",
"RainbowBlue",
"RainbowOrange",
"RainbowGreen",
"RainbowViolet",
"RainbowCyan",
}
local hooks = require('ibl.hooks')
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
end)
require('ibl').setup({
indent = {
highlight = highlight,
char = "",
},
})

View file

@ -1,9 +0,0 @@
local ts_input = require('mini.surround').gen_spec.input.treesitter
require('mini.surround').setup({
custom_surroundings = {
-- Use tree-sitter to search for function call
f = {
input = ts_input({ outer = '@call.outer', inner = '@call.inner' })
},
}
})

View file

@ -1,38 +0,0 @@
-- Override netrw
vim.g.loaded_netrw = 0
vim.g.loaded_netrwPlugin = 0
require('neo-tree').setup({
close_if_last_window = true,
enable_refresh_on_write = true,
window = {
width = 22,
},
filesystem = {
use_libuv_file_watcher = true,
group_empty_dirs = true,
filtered_items = {
visible = false,
hide_dotfiles = false,
hide_gitignored = true,
hide_by_name = {},
hide_by_pattern = {},
always_show = {},
never_show = {},
never_show_by_pattern = {},
},
},
source_selector = {
winbar = true,
statusline = false
},
follow_current_file = {
enabled = true,
leave_dirs_open = true,
}
})

View file

@ -1,10 +0,0 @@
" Auto open Neo-Tree on big enough window
function! OpenTree() abort
if &columns > 100
Neotree show
Neotree close
Neotree show
endif
endfunction
autocmd VimEnter * call OpenTree()

View file

@ -1,13 +0,0 @@
" use vscode keybinds for snippets completion
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ CheckBackspace() ? "\<TAB>" :
\ coc#refresh()
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'

View file

@ -28,21 +28,59 @@ in {
*/
''
-- set dot icon in place of trailing whitespaces
vim.cmd[[set list listchars=tab:\ \ ,nbsp:,trail:,extends:,precedes:]]
vim.opt.listchars = {
tab = ' ',
trail = '',
extends = '',
precedes = '',
nbsp = '',
};
vim.opt.list = true;
-- Add visual indicator for trailing whitespaces
vim.opt.fillchars = {eob = " "}
vim.opt.fillchars = { eob = " " };
vim.fn.matchadd('errorMsg', [[\s\+$]]);
vim.cmd[[colorscheme dracula]]
vim.cmd.colorscheme('dracula');
'';
}
{
plugin = vimPlugins.indent-blankline-nvim;
type = "lua";
config = fileContents ./plugins/indent.lua;
config =
/*
lua
*/
''
local highlight = {
"RainbowRed",
"RainbowYellow",
"RainbowBlue",
"RainbowOrange",
"RainbowGreen",
"RainbowViolet",
"RainbowCyan",
};
local hooks = require('ibl.hooks');
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
end);
require('ibl').setup({
indent = {
highlight = highlight,
char = "",
},
});
'';
}
]
++ optionals neovimIde [
{
plugin = vimPlugins.lualine-nvim;
type = "lua";
@ -62,16 +100,65 @@ in {
});
'';
}
]
++ optionals neovimIde [
{
plugin = vimPlugins.neo-tree-nvim;
type = "viml";
config = ''
${fileContents ./plugins/neotree.vim}
type = "lua";
config = fileContents ./neotree.lua;
}
{
plugin = vimPlugins.codewindow-nvim;
type = "lua";
config =
/*
lua
*/
''
local codewindow = require('codewindow');
lua << EOF
${fileContents ./plugins/neotree.lua}
EOF
'';
codewindow.setup({
auto_enable = false,
minimap_width = 8,
relative = 'editor',
window_border = 'none',
exclude_filetypes = { 'help' },
});
vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResized' }, {
pattern = '*',
callback = function()
if vim.api.nvim_win_get_width(0) < 88 then
codewindow.close_minimap();
else
codewindow.open_minimap();
end
end,
});
'';
}
{
plugin = vimPlugins.transparent-nvim;
type = "lua";
config =
/*
lua
*/
''
require("transparent").setup({
groups = {
'Normal', 'NormalNC', 'Comment', 'Constant',
'Special', 'Identifier', 'Statement', 'PreProc',
'Type', 'Underlined', 'Todo', 'String', 'Function',
'Conditional', 'Repeat', 'Operator', 'Structure',
'LineNr', 'NonText', 'SignColumn', 'CursorLine',
'CursorLineNr', 'StatusLine', 'StatusLineNC',
'EndOfBuffer',
},
extra_groups = {},
exclude_groups = {},
});
'';
}
];
};

View file

@ -18,9 +18,7 @@ in {
min_window_height = 20,
});
vim.cmd(
'hi TreesitterContextBottom gui=underline guisp=Grey'
);
vim.cmd.hi('TreesitterContextBottom', 'gui=underline guisp=Grey');
'';
}
@ -37,10 +35,6 @@ in {
highlight = { enable = true },
indent = { enable = true },
});
vim.filetype.add({
pattern = { [".*/hypr/.*%.conf"] = "hyprlang" },
});
'';
plugin = vimPlugins.nvim-treesitter.withPlugins (p: [
p.awk