nvf time!

This commit is contained in:
Charlie Root 2024-07-06 15:15:37 +02:00
commit 39924faca1
57 changed files with 4076 additions and 217 deletions

View file

@ -1 +1 @@
_: {imports = [./emacs.nix ./helix.nix ./kakoune.nix ./nixvim];}
_: {imports = [./emacs.nix ./helix.nix ./kakoune.nix ./nixvim/nixvim.nix ./nvf];}

View file

@ -0,0 +1,31 @@
{
inputs,
lib,
...
}: let
inherit (builtins) filter map toString elem;
inherit (lib.filesystem) listFilesRecursive;
inherit (lib.strings) hasSuffix;
inherit(lib.lists) concatLists;
mkNeovimModule ={
path,
ingoredPaths ? [./nvf.nix],
}:
filter (hasSuffix ".nix") (
map toString (
filter (path: path != ./default.nix && !elem path ingoredPaths) (listFilesRecursive path)
)
);
nvf = inputs.neovim-flake;
in {
imports = concatLists [
# neovim-flake home-manager module
[nvf.homeManagerModules.default]
# construct this entore directory as a module
# which means all default.nix files will be imported automtically
(mkNeovimModule {path = ./.;})
];
}

View file

@ -0,0 +1,134 @@
-- luacheck: ignore
-- alias for vim.api.nvim_create_autocmd
local create_autocmd = vim.api.nvim_create_autocmd
-- alias for vim.api.nvim_create_augroup
local create_augroup = vim.api.nvim_create_augroup
create_autocmd('BufWritePre', {
pattern = { '/tmp/*', 'COMMIT_EDITMSG', 'MERGE_MSG', '*.tmp', '*.bak' },
callback = function()
vim.opt_local.undofile = false
end,
})
-- Remove whitespaces on save
-- this is normally handled by the formatter
-- but this should help when the formatter
-- is not working or has timed out
-- create_autocmd('BufWritePre', {
-- pattern = '',
-- command = ':%s/\\s\\+$//e',
-- })
-- Disable line wrapping & spell checking
-- for the terminal buffer
create_autocmd({ 'FileType' }, {
pattern = { 'toggleterm' },
callback = function()
vim.opt_local.wrap = false
vim.opt_local.spell = false
end,
})
-- Enable spell checking & line wrapping
-- for git commit messages
create_autocmd({ 'FileType' }, {
pattern = { 'gitcommit' },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})
-- Highlight yank after yanking
local highlight_group = create_augroup('YankHighlight', { clear = true })
create_autocmd({ 'TextYankPost' }, {
pattern = { '*' },
group = highlight_group,
callback = function()
vim.highlight.on_yank({ higroup = 'Visual', timeout = 200 })
end,
})
-- Close terminal window if process exists with code 0
create_autocmd('TermClose', {
callback = function()
if not vim.b.no_auto_quit then
vim.defer_fn(function()
if vim.api.nvim_get_current_line() == '[Process exited 0]' then
vim.api.nvim_buf_delete(0, { force = true })
end
end, 50)
end
end,
})
-- Start insert mode automatically
-- when editing a Git commit message
create_augroup('AutoInsert', { clear = true })
create_autocmd('FileType', {
group = 'AutoInsert',
pattern = 'gitcommit',
command = 'startinsert',
})
-- Disable cursorline in insert mode
create_augroup('CursorLine', { clear = true })
create_autocmd({ 'InsertLeave', 'WinEnter' }, {
group = 'CursorLine',
callback = function()
vim.wo.cursorline = true
end,
})
create_autocmd({ 'InsertEnter', 'WinLeave' }, {
group = 'CursorLine',
callback = function()
vim.wo.cursorline = false
end,
})
-- Create the necessary directory structure for the file being saved.
create_augroup('AutoMkdir', { clear = true })
create_autocmd('BufWritePre', {
group = 'AutoMkdir',
callback = function(event)
local file = vim.loop.fs_realpath(event.match) or event.match
vim.fn.mkdir(vim.fn.fnamemodify(file, ':p:h'), 'p')
end,
})
-- Adjust the window size when the terminal is resized
create_autocmd('VimResized', {
command = 'wincmd =',
})
-- Allow closing certain windows with "q"
-- and remove them from the buffer list
create_augroup('close_with_q', { clear = true })
create_autocmd('FileType', {
group = 'close_with_q',
pattern = {
'help',
'lspinfo',
'TelescopePrompt',
},
callback = function(event)
vim.bo[event.buf].buflisted = false
vim.keymap.set('n', 'q', '<cmd>close<cr>', { buffer = event.buf, silent = true })
end,
})
-- Mark internally when nvim is focused
-- and when it is not
create_autocmd('FocusGained', {
callback = function()
vim.g.nvim_focused = true
end,
})
create_autocmd('FocusLost', {
callback = function()
vim.g.nvim_focused = false
end,
})

View file

@ -0,0 +1,42 @@
local opt = vim.opt
local options = {
showmode = false, -- disable the -- STATUS -- line
showtabline = 0, -- never show the tabline
startofline = true, -- motions like "G" also move to the first char
virtualedit = 'block', -- visual-block mode can select beyond end of line
showmatch = true, -- when closing a bracket, briefly flash the matching one
matchtime = 1, -- duration of that flashing n deci-seconds
signcolumn = 'yes:1', -- static width
report = 9001, -- disable "x more/fewer lines" messages
diffopt = opt.diffopt:append('vertical'), -- diff mode: vertical splits
backspace = { 'indent', 'eol', 'start' }, -- backspace through everything in insert mode
hidden = true, -- Enable background buffers
history = 100, -- Remember N lines in history
lazyredraw = false, -- Faster scrolling if enabled, breaks noice
synmaxcol = 240, -- Max column for syntax highlight
updatetime = 250, -- ms to wait for trigger an event
-- If 0, move cursor line will not scroll window.
-- If 999, cursor line will always be in middle of window.
scrolloff = 0,
}
-- iterate over the options table and set the options
-- for each key = value pair
for key, value in pairs(options) do
opt[key] = value
end
if not vim.g.vscode then
opt.timeoutlen = 300 -- Time out on mappings
end
-- Don't auto-comment new lines automatically
-- that happens when you press enter at the end
-- of a comment line, and comments the next line
-- That's annoying and we don't want it!
-- don't continue comments automagically
-- https://neovim.io/doc/user/options.html#'formatoptions'
opt.formatoptions:remove('c')
opt.formatoptions:remove('r')
opt.formatoptions:remove('o')

View file

@ -0,0 +1,17 @@
-- disable the "how to disable mouse" message
-- in right click popups
vim.cmd.aunmenu([[PopUp.How-to\ disable\ mouse]])
vim.cmd.aunmenu([[PopUp.-1-]])
vim.cmd.amenu([[PopUp.Inspect <Cmd>Inspect<CR>]])
vim.cmd.amenu([[PopUp.Telescope <Cmd>Telescope<CR>]])
vim.cmd.amenu([[PopUp.Code\ action <Cmd>lua vim.lsp.buf.code_action()<CR>]])
vim.cmd.amenu([[PopUp.LSP\ Hover <Cmd>lua vim.lsp.buf.hover()<CR>]])
-- Add a blinking cursor in certain modes.
vim.opt.guicursor = {
'n-c-v:block-Cursor',
'i-ci-ve-r-o:blinkwait250-blinkon250-blinkoff250-Cursor',
'i-ci-ve:ver25-Cursor',
'r-cr-o:hor20-Cursor',
}

View file

@ -0,0 +1,30 @@
-- alias for vim.api.nvim_create_autocmd
local create_autocmd = vim.api.nvim_create_autocmd
-- alias for vim.api.nvim_create_augroup
local create_augroup = vim.api.nvim_create_augroup
-- taken from https://github.com/sitiom/nvim-numbertoggle
-- I would much rather avoid fetching yet another plugin for something
-- that should be done locally - and not as a plugin
local augroup = create_augroup('NumberToggle', {})
create_autocmd({ 'BufEnter', 'FocusGained', 'InsertLeave', 'CmdlineLeave', 'WinEnter' }, {
pattern = '*',
group = augroup,
callback = function()
if vim.o.nu and vim.api.nvim_get_mode().mode ~= 'i' then
vim.opt.relativenumber = true
end
end,
})
create_autocmd({ 'BufLeave', 'FocusLost', 'InsertEnter', 'CmdlineEnter', 'WinLeave' }, {
pattern = '*',
group = augroup,
callback = function()
if vim.o.nu then
vim.opt.relativenumber = false
vim.cmd('redraw')
end
end,
})

View file

@ -0,0 +1,3 @@
-- More natural pane splitting
vim.o.splitbelow = true
vim.o.splitright = true

View file

@ -0,0 +1,93 @@
local opt = vim.opt
-- luacheck: ignore
-- When true, all the windows are automatically made the same size after splitting or closing a window.
-- When false, splitting a window will reduce the size of the current window and leave the other windows the same.
opt.equalalways = false
opt.cmdheight = 1 -- Better display for messages
opt.colorcolumn = '+0' -- Align text at 'textwidth'
opt.showtabline = 2 -- Always show the tabs line
opt.helpheight = 0 -- Disable help window resizing
opt.winwidth = 30 -- Minimum width for active window
opt.winminwidth = 1 -- Minimum width for inactive windows
opt.winheight = 1 -- Minimum height for active window
opt.winminheight = 1 -- Minimum height for inactive window
opt.pumheight = 10 -- Maximum number of items to show in the popup menu
opt.winminwidth = 1 -- min width of inactive window
-- opt.pumblend = 100 -- Popup blend, 100 means transparent
opt.cursorline = true
opt.whichwrap:append('<,>,h,l,[,]')
opt.list = true
-- haracters to fill the statuslines, vertical separators and special
-- lines in the window.opt.whichwrap:append('<,>,h,l,[,]')
opt.fillchars:append({
-- replace window border with slightly thicker characters
-- although taking a bit of more space, it helps me better
-- identify the window borders
horiz = '',
horizup = '',
horizdown = '',
vert = '',
vertleft = '',
vertright = '',
verthoriz = '',
eob = ' ', -- suppress end of buffer lines (~)
diff = '', -- deleted lines of the 'diff' option
msgsep = '',
-- replace fold chars
fold = ' ',
foldopen = '',
foldclose = '',
})
-- List chars that would b shown on all modes
-- better kept simple, because it gets REALLY
-- noisy in an average buffer
local normal_listchars = {
extends = '', -- Alternatives: … ,»
precedes = '', -- Alternatives: … ,«
}
opt.listchars = normal_listchars
-- Show listchars while in Insert mode.
local insert_listchars = {
eol = nil,
tab = '▎·',
lead = '·',
space = '·',
trail = '.',
multispace = '',
nbsp = '¤',
}
-- Show listchars while in Insert mode.
vim.api.nvim_create_augroup('InsertModeListChars', { clear = true })
vim.api.nvim_create_autocmd({ 'InsertEnter', 'InsertLeavePre' }, {
group = 'InsertModeListChars',
pattern = '*',
callback = function(args)
if vim.tbl_contains({ 'quickfix', 'prompt' }, args.match) then
return
end
if args.event == 'InsertEnter' then
vim.opt_local.listchars = insert_listchars
else
vim.opt_local.listchars = normal_listchars
end
-- check if ibl is enabled
-- @diagnostic disable-next-line: no-unknown, unused-local
local status_ok, ibl = pcall(require, 'ibl')
if not status_ok then
return
end
require('ibl').debounced_refresh(0)
end,
})

View file

@ -0,0 +1,18 @@
-- luacheck: ignore
vim.g.markdown_fenced_languages = { 'shell=bash' }
local file_syntax_map = {
{ pattern = '*.rasi', syntax = 'scss' },
{ pattern = 'flake.lock', syntax = 'json' },
{ pattern = '*.ignore', syntax = 'gitignore' }, -- also ignore for fd/ripgrep
{ pattern = '*.ojs', syntax = 'javascript' },
{ pattern = '*.astro', syntax = 'astro' },
{ pattern = '*.mdx', syntax = 'mdx' }
}
for _, elem in ipairs(file_syntax_map) do
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, {
pattern = elem.pattern,
command = 'set syntax=' .. elem.syntax,
})
end

View file

@ -0,0 +1,22 @@
local cmd = vim.cmd
-- luacheck: ignore
local abbreviations = {
Wq = 'wq', -- keep making those typos
WQ = 'wq',
Wqa = 'wqa',
W = 'w',
Q = 'q',
Qa = 'qa',
Bd = 'bd',
E = 'e',
q1 = 'q!', -- this is for when I don't want to reach to shift
qa1 = 'qa!',
mk = 'mark', -- make marks faster
st = 'sort', -- sort
}
-- add more abbreviations
for left, right in pairs(abbreviations) do
cmd.cnoreabbrev(('%s %s'):format(left, right))
end

View file

@ -0,0 +1,13 @@
-- If the cursor has been idle for some time, check if the current buffer
-- has been modified externally. prompt the user to reload it if has.
local bufnr = vim.api.nvim_get_current_buf()
-- luacheck: ignore
vim.opt_local.autoread = true
vim.api.nvim_create_autocmd('CursorHold', {
group = vim.api.nvim_create_augroup('Autoread', { clear = true }),
buffer = bufnr,
callback = function()
vim.cmd('silent! checktime')
end,
})

View file

@ -0,0 +1,68 @@
-- luacheck: ignore
vim.opt.spelllang:append('cjk') -- disable spellchecking for asian characters (VIM algorithm does not support it)
vim.opt.shortmess = {
t = true, -- truncate file messages at start
A = true, -- ignore annoying swap file messages
o = true, -- file-read message overwrites previous
O = true, -- file-read message overwrites previous
T = true, -- truncate non-file messages in middle
f = true, -- (file x of x) instead of just (x of x
F = true, -- Don't give file info when editing a file, NOTE: this breaks autocommand messages
s = true,
c = true,
W = true, -- Don't show [w] or written when writing
}
-- Disable nvim intro
vim.opt.shortmess:append('sI')
-- Some of those are already disasbled in the Neovim wrapper
-- as configured by nvf. I'm just making sure they are disabled
-- here as well.
local disable_distribution_plugins = function()
local disabled_built_ins = {
'2html_plugin',
'getscript',
'getscriptPlugin',
'gzip',
'logipat',
'matchit',
'matchparen',
'tar',
'tarPlugin',
'rrhelper',
'spellfile_plugin',
'vimball',
'vimballPlugin',
'zip',
'zipPlugin',
'tutor',
'rplugin',
'synmenu',
'optwin',
'compiler',
'bugreport',
'ftplugin',
'netrw',
'netrwPlugin',
'netrwSettings',
'netrwFileHandlers',
-- "skip_ts_context_commentstring_module"
}
for _, plugin in pairs(disabled_built_ins) do
g['loaded_' .. plugin] = 1
end
end
-- https://github.com/neovim/neovim/issues/14090#issuecomment-1177933661
-- vim.g.do_filetype_lua = 1
-- vim.g.did_load_filetypes = 0
-- Neovim should not be able to load from those paths since
-- we ultimately want to be able to *only* want the nvf config
-- to be the effective one
vim.opt.runtimepath:remove('/etc/xdg/nvim')
vim.opt.runtimepath:remove('/etc/xdg/nvim/after')
vim.opt.runtimepath:remove('/usr/share/vim/vimfiles')

View file

@ -0,0 +1,22 @@
-- Diagnostic settings:
-- see: `:help vim.diagnostic.config`
vim.diagnostic.config({
update_in_insert = true,
virtual_text = false,
signs = true,
underline = true,
severity_sort = true,
virtual_lines = {
only_current_line = true,
spacing = 2,
},
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
})

View file

@ -0,0 +1,34 @@
-- luacheck: ignore
local float_options = {
border = 'single',
max_width = math.ceil(vim.api.nvim_win_get_width(0) * 0.6),
max_height = math.ceil(vim.api.nvim_win_get_height(0) * 0.8),
}
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = true,
signs = false,
underline = true,
update_in_insert = false,
severity_sort = true,
})
vim.lsp.handlers['textDocument/show_line_diagnostics'] = vim.lsp.with(vim.lsp.handlers.hover, float_options)
-- Prevent show notification
-- <https://github.com/neovim/neovim/issues/20457#issuecomment-1266782345>
vim.lsp.handlers['textDocument/hover'] = function(_, result, ctx, config)
config = config or float_options
config.focus_id = ctx.method
if not result then
return
end
local markdown_lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents)
markdown_lines = vim.lsp.util.trim_empty_lines(markdown_lines)
if vim.tbl_isempty(markdown_lines) then
return
end
return vim.lsp.util.open_floating_preview(markdown_lines, 'markdown', config)
end
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, float_options)

View file

@ -0,0 +1,30 @@
if vim.g.neovide then
local vks = vim.keymap.set
vim.g.neovide_scale_factor = 1.0
vim.g.minianimate_disable = true
vim.g.neovide_window_blurred = true
vim.g.neovide_transparency = 0.80
vim.g.neovide_show_border = true
vim.g.neovide_input_macos_alt_is_meta = true
vim.g.neovide_cursor_animate_command_line = false -- noice incompat
vim.g.neovide_cursor_smooth_blink = true
vim.g.neovide_cursor_vfx_mode = 'ripple'
-- keymaps
vks('v', '<D-c>', '"+y') -- Copy
vks({ 'n', 'v' }, '<D-v>', '"+P') -- Paste
vks({ 'i', 'c' }, '<D-v>', '<C-R>+') -- Paste
vks('t', '<D-v>', [[<C-\><C-N>"+P]]) -- Paste
vks('n', '<D-+>', function()
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 1.1
end)
vks('n', '<D-->', function()
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor / 1.1
end)
vks({ 'n', 'v', 't', 'i' }, '<D-}>', [[<C-\><C-N><Cmd>tabnext<CR>]])
vks({ 'n', 'v', 't', 'i' }, '<D-{>', [[<C-\><C-N><Cmd>tabprev<CR>]])
vks({ 'n', 'v', 't', 'i' }, '<D-l>', [[<C-\><C-N><Cmd>tabnext #<CR>]])
vks({ 'n', 'v', 't', 'i' }, '<D-t>', [[<C-\><C-N><Cmd>tabnew<CR>]])
vks({ 'n', 'v', 't', 'i' }, '<D-w>', [[<C-\><C-N><Cmd>tabclose<CR>]])
end

View file

@ -0,0 +1,33 @@
-- https://github.com/asvetliakov/vscode-neovim#normal-mode-control-keys
-- available by default
-- CTRL-a
-- CTRL-b
-- CTRL-c
-- CTRL-d
-- CTRL-e
-- CTRL-f
-- CTRL-i
-- CTRL-o
-- CTRL-r
-- CTRL-u
-- CTRL-v
-- CTRL-w
-- CTRL-x
-- CTRL-y
-- CTRL-]
-- CTRL-j
-- CTRL-k
-- CTRL-l
-- CTRL-h
-- CTRL-/
if vim.g.vscode then
vim.keymap.set('n', 'H', '<Cmd>Tabprevious<CR>', { noremap = true, silent = true })
vim.keymap.set('n', 'L', '<Cmd>Tabnext<CR>', { noremap = true, silent = true })
vim.keymap.set(
'n',
'<Leader>p',
"<<Cmd>call VSCodeNotify('workbench.action.quickOpen')<CR>>",
{ noremap = true, silent = true }
)
end

View file

@ -0,0 +1,72 @@
local noice = require('noice')
local no_top_text = {
opts = {
border = {
text = { top = '' },
},
},
}
-- luacheck: ignore
noice.setup({
cmdline = {
format = {
cmdline = no_top_text,
filter = no_top_text,
lua = no_top_text,
search_down = no_top_text,
search_up = no_top_text,
},
},
lsp = {
override = {
['cmp.entry.get_documentation'] = true,
['vim.lsp.util.convert_input_to_markdown_lines'] = true,
['vim.lsp.util.stylize_markdown'] = true,
},
progress = {
enabled = false,
},
},
popupmenu = {
backend = 'cmp',
},
routes = {
{
filter = {
event = 'msg_show',
kind = 'search_count',
},
opts = { skip = true },
},
{
-- skip progress messages from noisy servers
filter = {
event = 'lsp',
kind = 'progress',
cond = function(message)
local client = vim.tbl_get(message.opts, 'progress', 'client')
return client == 'ltex'
end,
},
opts = { skip = true },
},
},
views = {
cmdline_popup = {
border = {
style = 'single',
},
},
confirm = {
border = {
style = 'single',
text = { top = '' },
},
},
},
})

View file

@ -0,0 +1,9 @@
{
programs.neovim-flake.settings.vim.maps = {
insert = {
# vsnip
#"<C-jn>".action = "<Plug>(vsnip-jump-next)";
#"<C-jp>".action = "<Plug>(vsnip-jump-prev)";
};
};
}

View file

@ -0,0 +1,59 @@
{
programs.neovim-flake.settings.vim.maps = {
normal = {
# General
"<leader>fd".action = ":lua vim.g.formatsave = not vim.g.formatsave<CR>";
"<leader>zt".action = ":<C-U>let g:default_terminal = v:count1<CR>";
"<leader>e".action = ":NvimTreeToggle<CR>";
"<leader>ld".action = ":lua vim.diagnostic.setqflist({open = true})<CR>";
"<leader>lf".action = ":lua vim.lsp.buf.format()<CR>";
"<leader>li".action = ":lua vim.lsp.buf.implementation()<CR>";
# Diffview
"<leader>gdq".action = ":DiffviewClose<CR>";
"<leader>gdd".action = ":DiffviewOpen ";
"<leader>gdm".action = ":DiffviewOpen<CR>";
"<leader>gdh".action = ":DiffviewFileHistory %<CR>";
"<leader>gde".action = ":DiffviewToggleFiles<CR>";
# Git
"<leader>gu".action = "<cmd>Gitsigns undo_stage_hunk<CR>";
"<leader>g<C-w>".action = "<cmd>Gitsigns preview_hunk<CR>";
"<leader>gp".action = "<cmd>Gitsigns prev_hunk<CR>";
"<leader>gn".action = "<cmd>Gitsigns next_hunk<CR>";
"<leader>gP".action = "<cmd>Gitsigns preview_hunk_inline<CR>";
"<leader>gR".action = "<cmd>Gitsigns reset_buffer<CR>";
"<leader>gb".action = "<cmd>Gitsigns blame_line<CR>";
"<leader>gD".action = "<cmd>Gitsigns diffthis HEAD<CR>";
"<leader>gw".action = "<cmd>Gitsigns toggle_word_diff<CR>";
# Telescope
"<M-f>".action = ":Telescope resume<CR>";
"<leader>fq".action = ":Telescope quickfix<CR>";
"<leader>f/".action = ":Telescope live_grep<cr>";
# Aerial
"<S-O>".action = ":AerialToggle<CR>";
# vsnip
#"<C-jn>".action = "<Plug>(vsnip-jump-next)";
#"<C-jp>".action = "<Plug>(vsnip-jump-prev)";
};
normalVisualOp = {
"<leader>gs".action = ":Gitsigns stage_hunk<CR>";
"<leader>gr".action = ":Gitsigns reset_hunk<CR>";
"<leader>lr".action = "<cmd>lua vim.lsp.buf.references()<CR>";
# ssr.nvim
"<leader>sr".action = ":lua require('ssr').open()<CR>";
# Toggleterm
"<leader>ct" = {
# action = ":<C-U>ToggleTermSendVisualLines v:count<CR>";
action = "':ToggleTermSendVisualLines ' . v:count == 0 ? g:default_terminal : v:count";
expr = true;
};
};
};
}

View file

@ -0,0 +1,9 @@
{
programs.neovim-flake.settings.vim.maps = {
select = {
# vsnip
#"<C-jn>".action = "<Plug>(vsnip-jump-next)";
#"<C-jp>".action = "<Plug>(vsnip-jump-prev)";
};
};
}

View file

@ -0,0 +1,7 @@
{
programs.neovim-flake.settings.vim.maps = {
terminal = {
"<M-x>".action = "<cmd>q<CR>";
};
};
}

View file

@ -1,44 +1,183 @@
{
inputs,
lib,
pkgs,
...
}: {
programs.nvf = {
enable = true;
# Thank your Mr. poz! (https://git.jacekpoz.pl/jacekpoz/niksos)
{ config, inputs, lib, pkgs, ... }:
let
cfg = config.modules.editors.neovim;
inherit (config.modules.other.system) username;
defaultEditor = true;
enableManpages = true;
inherit (lib) mkEnableOption mkIf;
in {
options.modules.editors.neovim.enable = mkEnableOption "neovim";
settings = {
vim = {
# use neovim-unwrapped from nixpkgs
package = pkgs.neovim-unwrapped;
config = mkIf cfg.enable {
environment.sessionVariables = { EDITOR = "nvim"; };
viAlias = true;
vimAlias = true;
home-manager.users.${username} = {
imports = [ inputs.neovim-flake.homeManagerModules.default ];
withNodeJs = false;
withPython3 = false;
withRuby = false;
programs.nvf = {
enable = true;
settings.vim = {
package =
inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
viAlias = false;
vimAlias = false;
enableLuaLoader = true;
scrollOffset = 7;
preventJunkFiles = true;
tabWidth = 4;
autoIndent = false;
cmdHeight = 1;
useSystemClipboard = false;
# Prevent swapfile and backupfile from being created
preventJunkFiles = true;
theme = {
enable = true;
name = "catppuccin";
style = "mocha";
transparent = true;
};
# Make use of the clipboard for default yank and paste operations. Dont use * and +
useSystemClipboard = true;
spellcheck = {
enable = true;
languages = ["en" "de"];
};
maps = {
normal = {
"<leader>v" = {
action = "<CMD>Neotree toggle<CR>";
silent = true;
};
"<leader>m" = {
action = "<CMD>MarkdownPreviewToggle<CR>";
silent = true;
};
};
terminal = {
# get out of terminal mode in toggleterm
"<ESC>" = {
action = "<C-\\><C-n>";
silent = true;
};
};
};
# Whether to enable the experimental Lua module loader to speed up the start up process
enableLuaLoader = true;
enableEditorconfig = true;
statusline.lualine = {
enable = true;
theme = "catppuccin";
};
debugMode = {
enable = false;
logFile = "/tmp/nvim.log";
extraPlugins = with pkgs.vimPlugins; {
zen-mode.package = zen-mode-nvim;
unicode.package = unicode-vim;
};
treesitter = {
enable = true;
fold = true;
context.enable = true;
};
autocomplete = {
enable = true;
alwaysComplete = false;
};
filetree.nvimTree = { enable = true; };
terminal.toggleterm = {
enable = true;
setupOpts.direction = "tab";
mappings.open = "<C-\\>";
# TODO shading_factor
# TODO shade_terminals
# TODO size
};
git = {
enable = true;
gitsigns = {
enable = true;
# TODO enable / disable all the settings
};
};
lsp = {
enable = true;
lspSignature.enable = true;
lspconfig.enable = true;
mappings = {
addWorkspaceFolder = "<leader>wa";
codeAction = "<leader>a";
format = "<C-f>";
goToDeclaration = "gD";
goToDefinition = "gd";
hover = "K";
listImplementations = "gi";
listReferences = "gr";
listWorkspaceFolders = "<leader>wl";
nextDiagnostic = "<leader>k";
previousDiagnostic = "<leader>j";
openDiagnosticFloat = "<leader>e";
removeWorkspaceFolder = "<leader>wr";
renameSymbol = "<leader>r";
signatureHelp = "<C-k>";
};
};
languages = {
enableDAP = true;
enableExtraDiagnostics = true;
enableFormat = true;
enableLSP = true;
enableTreesitter = true;
bash.enable = true;
clang = {
enable = true;
cHeader = true;
};
css.enable = true;
html.enable = true;
java.enable = true;
markdown.enable = true;
nix.enable = true;
ocaml.enable = true;
rust = {
enable = true;
crates.enable = true;
};
ts.enable = true;
};
utility = {
motion.leap.enable = true;
preview.markdownPreview.enable = true;
# TODO settings.theme = "dark";
surround = {
enable = true;
useVendoredKeybindings = true;
};
};
visuals.fidget-nvim.enable = true;
# TODO laytan/cloak.nvim
telescope.enable = true;
comments.comment-nvim.enable = true;
# TODO learn and add harpoon
notes = {
todo-comments = {
enable = true;
mappings.telescope = "<leader>tt";
setupOpts.highlight.pattern = ".*<(KEYWORDS)s*";
};
orgmode = {
enable = true;
setupOpts = {
org_agenda_files = [ "~/Notes/org" ];
org_default_notes_file = "~/Notes/org/refile.org";
};
treesitter.enable = true;
};
};
};
};
};

View file

@ -0,0 +1,141 @@
{
self,
pkgs,
...
}: let
inherit (pkgs.vimPlugins) friendly-snippets aerial-nvim nvim-surround undotree mkdir-nvim ssr-nvim direnv-vim legendary-nvim;
pluginSources = import ./sources {inherit self pkgs;};
in {
programs.neovim-flake.settings.vim.extraPlugins = {
# plugins that are pulled from nixpkgs
direnv = {package = direnv-vim;};
friendly-snippets = {package = friendly-snippets;};
mkdir-nvim = {package = mkdir-nvim;};
aerial = {
package = aerial-nvim;
setup = "require('aerial').setup {}";
};
nvim-surround = {
package = nvim-surround;
setup = "require('nvim-surround').setup {}";
};
undotree = {
package = undotree;
setup = ''
vim.g.undotree_ShortIndicators = true
vim.g.undotree_TreeVertShape = ''
'';
};
ssr-nvim = {
package = ssr-nvim;
setup = "require('ssr').setup {}";
};
legendary = {
package = legendary-nvim;
setup = ''
require('legendary').setup {};
'';
};
# plugins that are built from their sources
regexplainer = {package = pluginSources.regexplainer;};
vim-nftables = {package = pluginSources.vim-nftables;};
data-view = {
package = pluginSources.data-viewer-nvim;
setup = ''
-- open data files in data-viewer.nvim
vim.api.nvim_exec([[
autocmd BufReadPost,BufNewFile *.sqlite,*.csv,*.tsv DataViewer
]], false)
-- keybinds
vim.api.nvim_set_keymap('n', '<leader>dv', ':DataViewer<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<leader>dvn', ':DataViewerNextTable<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<leader>dvp', ':DataViewerPrevTable<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<leader>dvc', ':DataViewerClose<CR>', {noremap = true})
'';
};
slides-nvim = {
package = pluginSources.slides-nvim;
setup = "require('slides').setup {}";
};
hmts = {
package = pluginSources.hmts;
after = ["treesitter"];
};
smart-splits = {
package = pluginSources.smart-splits;
setup = "require('smart-splits').setup {}";
};
neotab-nvim = {
package = pluginSources.neotab-nvim;
setup = ''
require('neotab').setup {
tabkey = "<Tab>",
act_as_tab = true,
behavior = "nested", ---@type ntab.behavior
pairs = { ---@type ntab.pair[]
{ open = "(", close = ")" },
{ open = "[", close = "]" },
{ open = "{", close = "}" },
{ open = "'", close = "'" },
{ open = '"', close = '"' },
{ open = "`", close = "`" },
{ open = "<", close = ">" },
},
exclude = {},
smart_punctuators = {
enabled = false,
semicolon = {
enabled = false,
ft = { "cs", "c", "cpp", "java" },
},
escape = {
enabled = false,
triggers = {}, ---@type table<string, ntab.trigger>
},
},
}
'';
};
specs-nvim = {
package = pluginSources.specs-nvim;
setup = ''
require('specs').setup {
show_jumps = true,
popup = {
delay_ms = 0,
inc_ms = 15,
blend = 15,
width = 10,
winhl = "PMenu",
fader = require('specs').linear_fader,
resizer = require('specs').shrink_resizer
},
ignore_filetypes = {'NvimTree', 'undotree'},
ignore_buftypes = {nofile = true},
}
-- toggle specs using the <C-b> keybind
vim.api.nvim_set_keymap('n', '<C-b>', ':lua require("specs").show_specs()', { noremap = true, silent = true })
-- bind specs to navigation keys
vim.api.nvim_set_keymap('n', 'n', 'n:lua require("specs").show_specs()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', 'N', 'N:lua require("specs").show_specs()<CR>', { noremap = true, silent = true })
'';
};
};
}

View file

@ -0,0 +1,8 @@
{
programs.neovim-flake.settings.vim = {
assistant.copilot = {
enable = true;
cmp.enable = true;
};
};
}

View file

@ -0,0 +1,16 @@
{
programs.neovim-flake.settings.vim = {
autocomplete = {
enable = true;
type = "nvim-cmp";
mappings = {
# close = "<C-e>";
confirm = "<C-y>";
next = "<C-n>";
previous = "<C-p>";
scrollDocsDown = "<C-j>";
scrollDocsUp = "<C-k>";
};
};
};
}

View file

@ -0,0 +1,5 @@
{
programs.neovim-flake.settings.vim = {
autopairs.enable = true;
};
}

View file

@ -0,0 +1,8 @@
{
programs.neovim-flake.settings.vim = {
binds = {
whichKey.enable = true;
cheatsheet.enable = false;
};
};
}

View file

@ -0,0 +1,5 @@
{
programs.neovim-flake.settings.vim = {
comments.comment-nvim.enable = true;
};
}

View file

@ -0,0 +1,7 @@
{
programs.neovim-flake.settings.vim = {
dashboard = {
alpha.enable = true;
};
};
}

View file

@ -0,0 +1,8 @@
{
programs.neovim-flake.settings.vim = {
debugger.nvim-dap = {
enable = true;
ui.enable = true;
};
};
}

View file

@ -0,0 +1,63 @@
{
programs.neovim-flake.settings.vim = {
filetree = {
nvimTree = {
enable = true;
openOnSetup = true;
mappings = {
toggle = "<C-w>";
};
setupOpts = {
disable_netrw = true;
update_focused_file.enable = true;
hijack_unnamed_buffer_when_opening = true;
hijack_cursor = true;
hijack_directories = {
enable = true;
auto_open = true;
};
git = {
enable = true;
show_on_dirs = false;
timeout = 500;
};
view = {
cursorline = false;
width = 35;
};
renderer = {
indent_markers.enable = true;
root_folder_label = false; # inconsistent
icons = {
modified_placement = "after";
git_placement = "after";
show.git = true;
show.modified = true;
};
};
diagnostics.enable = true;
modified = {
enable = true;
show_on_dirs = false;
show_on_open_dirs = true;
};
actions = {
change_dir.enable = false;
change_dir.global = false;
open_file.window_picker.enable = true;
};
};
};
};
};
}

View file

@ -0,0 +1,5 @@
{
programs.neovim-flake.settings.vim = {
gestures.gesture-nvim.enable = false;
};
}

View file

@ -0,0 +1,12 @@
{
programs.neovim-flake.settings.vim = {
git = {
enable = true;
vim-fugitive.enable = true;
gitsigns = {
enable = true;
codeActions.enable = false; # no.
};
};
};
}

View file

@ -0,0 +1,59 @@
{
config,
pkgs,
lib,
...
}: {
programs.neovim-flake.settings.vim = {
languages = {
enableLSP = true;
enableFormat = true;
enableTreesitter = true;
enableExtraDiagnostics = true;
markdown.enable = true;
nix.enable = true;
html.enable = true;
css.enable = true;
tailwind.enable = true;
ts.enable = true;
go.enable = true;
python.enable = true;
bash.enable = true;
typst.enable = true;
zig.enable = true;
dart.enable = false;
elixir.enable = false;
svelte.enable = false;
sql.enable = false;
java = let
jdtlsCache = "${config.xdg.cacheHome}/jdtls";
in {
enable = true;
lsp.package = [
"${lib.getExe pkgs.jdt-language-server}"
"-configuration ${jdtlsCache}/config"
"-data ${jdtlsCache}/workspace"
];
};
lua = {
enable = true;
lsp.neodev.enable = true;
};
rust = {
enable = true;
crates.enable = true;
};
clang = {
enable = true;
lsp = {
enable = true;
server = "clangd";
};
};
};
};
}

View file

@ -0,0 +1,15 @@
{
programs.neovim-flake.settings.vim = {
lsp = {
formatOnSave = true;
lspkind.enable = true;
lsplines.enable = true;
lightbulb.enable = true;
lspsaga.enable = false;
lspSignature.enable = true;
nvimCodeActionMenu.enable = true;
trouble.enable = false;
nvim-docs-view.enable = true;
};
};
}

View file

@ -0,0 +1,9 @@
{
programs.neovim-flake.settings.vim = {
minimap = {
# cool for vanity but practically useless on small screens
minimap-vim.enable = false;
codewindow.enable = false;
};
};
}

View file

@ -0,0 +1,9 @@
{
programs.neovim-flake.settings.vim = {
notes = {
todo-comments.enable = true;
mind-nvim.enable = false;
obsidian.enable = false;
};
};
}

View file

@ -0,0 +1,7 @@
{
programs.neovim-flake.settings.vim = {
notify = {
nvim-notify.enable = true;
};
};
}

View file

@ -0,0 +1,5 @@
{
programs.neovim-flake.settings.vim = {
presence.neocord.enable = false;
};
}

View file

@ -0,0 +1,22 @@
{
programs.neovim-flake.settings.vim = {
projects = {
project-nvim = {
enable = true;
setupOpts = {
manualMode = false;
detectionMethods = ["lsp" "pattern"];
patterns = [
".git"
".hg"
"Makefile"
"package.json"
"index.*"
".anchor"
"flake.nix"
];
};
};
};
};
}

View file

@ -0,0 +1,8 @@
{
programs.neovim-flake.settings.vim = {
session.nvim-session-manager = {
enable = false;
setupOpts.autoload_mode = "Disabled"; # misbehaves with dashboard
};
};
}

View file

@ -0,0 +1,10 @@
{
programs.neovim-flake.settings.vim = {
statusline = {
lualine = {
enable = true;
theme = "catppuccin";
};
};
};
}

View file

@ -0,0 +1,7 @@
{
programs.neovim-flake.settings.vim = {
tabline = {
nvimBufferline.enable = true;
};
};
}

View file

@ -0,0 +1,5 @@
{
programs.neovim-flake.settings.vim = {
telescope.enable = true;
};
}

View file

@ -0,0 +1,4 @@
{
programs.neovim-flake.settings.vim = {
};
}

View file

@ -0,0 +1,18 @@
{
programs.neovim-flake.settings.vim = {
terminal = {
toggleterm = {
enable = true;
mappings.open = "<C-t>";
setupOpts = {
direction = "tab";
lazygit = {
enable = true;
direction = "tab";
};
};
};
};
};
}

View file

@ -0,0 +1,10 @@
{
programs.neovim-flake.settings.vim = {
theme = {
enable = true;
name = "catppuccin";
style = "mocha";
transparent = true;
};
};
}

View file

@ -0,0 +1,14 @@
{pkgs, ...}: {
programs.neovim-flake.settings.vim = {
treesitter = {
fold = true;
context.enable = false; # FIXME: currently broken, I do not know why.
# extra grammars that will be installed by Nix
grammars = with pkgs.vimPlugins.nvim-treesitter.builtGrammars; [
regex # for regexplainer
kdl # zellij configurations are in KDL, I want syntax highlighting
];
};
};
}

View file

@ -0,0 +1,34 @@
{
programs.neovim-flake.settings.vim = {
ui = {
noice.enable = true;
colorizer.enable = true;
modes-nvim.enable = false;
illuminate.enable = true;
breadcrumbs = {
enable = true;
source = "nvim-navic";
navbuddy.enable = false;
};
smartcolumn = {
enable = true;
setupOpts = {
columnAt.languages = {
markdown = [80];
nix = [150];
ruby = 110;
java = 120;
go = [130];
};
};
};
borders = {
enable = true;
globalStyle = "rounded";
};
};
};
}

View file

@ -0,0 +1,24 @@
{pkgs, ...}: {
programs.neovim-flake.settings.vim = {
utility = {
ccc.enable = true;
icon-picker.enable = true;
diffview-nvim.enable = true;
vim-wakatime = {
enable = true;
cli-package = pkgs.wakatime-cli;
};
motion = {
hop.enable = true;
leap.enable = false;
};
preview = {
glow.enable = true;
markdownPreview.enable = true;
};
};
};
}

View file

@ -0,0 +1,34 @@
{
programs.neovim-flake.settings.vim = {
visuals = {
enable = true;
nvimWebDevicons.enable = true;
scrollBar.enable = true;
smoothScroll.enable = false;
cellularAutomaton.enable = false;
highlight-undo.enable = true;
indentBlankline = {
enable = true;
fillChar = null;
eolChar = null;
scope.enabled = true;
};
cursorline = {
enable = true;
lineTimeout = 0;
};
fidget-nvim = {
enable = true;
setupOpts = {
notification.window = {
winblend = 0;
border = "none";
};
};
};
};
};
}

View file

@ -0,0 +1,87 @@
{
self,
pkgs,
...
}: let
inherit (self) pins;
inherit (pkgs) fetchFromGitHub;
inherit (pkgs.vimUtils) buildVimPlugin;
sources = {
hmts = buildVimPlugin {
name = "hmts.nvim";
src = pins."hmts.nvim";
};
smart-splits = buildVimPlugin {
name = "smart-splits";
src = pins."smart-splits.nvim";
};
slides-nvim = buildVimPlugin {
name = "slides.nvim";
src = pins."slides.nvim";
};
regexplainer = buildVimPlugin {
name = "nvim-regexplainer";
src = fetchFromGitHub {
owner = "bennypowers";
repo = "nvim-regexplainer";
rev = "4250c8f3c1307876384e70eeedde5149249e154f";
hash = "sha256-15DLbKtOgUPq4DcF71jFYu31faDn52k3P1x47GL3+b0=";
};
};
specs-nvim = buildVimPlugin {
name = "specs.nvim";
src = fetchFromGitHub {
owner = "notashelf";
repo = "specs.nvim";
rev = "0792aaebf8cbac0c8545c43ad648b98deb83af42";
hash = "sha256-doHE/3bRuC8lyYxMk927JmwLfiy7aR22+i+BNefEGJ4=";
};
};
deferred-clipboard = buildVimPlugin {
name = "deferred-clipboard";
src = fetchFromGitHub {
owner = "EtiamNullam";
repo = "deferred-clipboard.nvim";
rev = "810a29d166eaa41afc220cc7cd85eeaa3c43b37f";
hash = "sha256-nanNQEtpjv0YKEkkrPmq/5FPxq+Yj/19cs0Gf7YgKjU=";
};
};
data-viewer-nvim = buildVimPlugin {
name = "data-viewer.nvim";
src = fetchFromGitHub {
owner = "VidocqH";
repo = "data-viewer.nvim";
rev = "40ddf37bb7ab6c04ff9e820812d1539afe691668";
hash = "sha256-D5hvLhsYski11H9qiDDL2zlZMtYmbpHgpewiWR6C7rE=";
};
};
vim-nftables = buildVimPlugin {
name = "vim-nftables";
src = fetchFromGitHub {
owner = "awisse";
repo = "vim-nftables";
rev = "bc29309080b4c7e1888ffb1a830846be16e5b8e7";
hash = "sha256-L1x3Hv95t/DBBrLtPBKrqaTbIPor/NhVuEHVIYo/OaA=";
};
};
neotab-nvim = buildVimPlugin {
name = "neotab.nvim";
src = fetchFromGitHub {
owner = "kawre";
repo = "neotab.nvim";
rev = "6c6107dddaa051504e433608f59eca606138269b";
hash = "sha256-bSFKbjj8fJHdfBzYoQ9l3NU0GAYfdfCbESKbwdbLNSw=";
};
};
};
in
sources

View file

@ -0,0 +1,100 @@
# Credity to raf aka Notashelf, link to his repo is in the README.md
{
inputs,
config,
pkgs,
lib,
...
}: let
inherit (builtins) filter map toString path isPath throw;
inherit (lib.filesystem) listFilesRecursive;
inherit (lib.strings) hasSuffix fileContents;
inherit (lib.attrsets) genAttrs;
inherit (config.modues.other.system) username;
nvf = inputs.neovim-flake;
inherit (inputs) neovim-nightly-overlay;
inherit (nvf.lib.nvim.dag) entryBefore entryAnywhere;
mkRuntimeDir = name: let
finalPath = ./runtime + /${name};
in
path {
name = "nvim-runtime-${name}";
path = toString finalPath;
};
in {
home-manager.users.${username} = {
programs.neovim-flake = {
enable = true;
defaultEditor = true;
enableManpages = true;
settings = {
vim = {
# use neovim-unwrapped from nixpkgs
# alternatively, neovim-nightly from the neovim-nightly overlay
# via inputs.neovim-nightly.packages.${pkgs.stdenv.system}.neovim
# package = pkgs.neovim-unwrapped;
package = neovim-nightly-overlay;
viAlias = true;
vimAlias = true;
withNodeJs = false;
withPython3 = false;
withRuby = false;
preventJunkFiles = true;
useSystemClipboard = true;
spellcheck = {
enable = true;
languages = ["en" "de" ];
};
enableLuaLoader = true;
enableEditorconfig = true;
debugMode = {
enable = false;
logFile = "/tmp/nvim.log";
};
additionalRuntimePaths = [
(mkRuntimeDir "after")
(mkRuntimeDir "spell")
];
# while I should be doing this in luaConfigRC below
# I have come to realise that spellfile contents are
# actually **not** loaded when luaConfigRC is used.
# as spellfile is a vim thing, this should be fine
configRC.spellfile = entryAnywhere ''
set spellfile=${toString ./spell/runtime/en.utf-8.add} " toString sanitizes the path
'';
# additional lua configuration that I can append
# or, to be more precise, randomly inject into
# the lua configuration of my Neovim configuration
# wrapper. this is recursively read from the lua
# directory, so we do not need to use require
luaConfigRC = let
# get the name of each lua file in the lua directory, where setting files reside
# and import tham recursively
configPaths = filter (hasSuffix ".lua") (map toString (listFilesRecursive ./lua));
# generates a key-value pair that looks roughly as follows:
# `<filePath> = entryAnywhere ''<contents of filePath>''`
# which is expected by neovim-flake's modified DAG library
luaConfig = genAttrs configPaths (file:
entryBefore ["luaScript"] ''
${fileContents "${file}"}
'');
in
luaConfig;
};
};
};
};
}