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

@ -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 = '' },
},
},
},
})