summaryrefslogtreecommitdiff
path: root/files/nvim
diff options
context:
space:
mode:
Diffstat (limited to 'files/nvim')
-rw-r--r--files/nvim/init.vim226
-rw-r--r--files/nvim/mini_starter_picture.diff46
2 files changed, 144 insertions, 128 deletions
diff --git a/files/nvim/init.vim b/files/nvim/init.vim
index e679f4d..f7c4d54 100644
--- a/files/nvim/init.vim
+++ b/files/nvim/init.vim
@@ -5,6 +5,8 @@ set signcolumn=yes
set updatetime=250
set scrolloff=5
+" https://github.com/SmiteshP/nvim-navic
+
" Change directory based on current file.
if !empty($NIX_SHELL)
" Attempt to conflict less with plugins.
@@ -33,7 +35,9 @@ set autoindent
" C syntax preference.
let g:c_syntax_for_h=1
-set cinoptions=:0,=4,l1,g2,h2,(4,u4,+4,m1
+let g:c_no_curly_error=1
+let g:c_function_pointers=1
+set cinoptions=:0,=4,l1,g2,h2,(4,u4,+4,m1,j1,J1
set cindent
" Set different format for mail and text files.
@@ -126,17 +130,6 @@ function! StatuslineGit()
return strlen(l:branchname) > 0 ? ' '.l:branchname.' ' : ' '
endfunction
-lua << EOF
-function get_lsp_name()
- local active_clients = vim.lsp.get_active_clients({bufnr = vim.api.nvim_get_current_buf()})
- if next(active_clients) == nil then
- return ''
- else
- return '+'..active_clients[1].name
- end
-end
-EOF
-
function! StatuslineLsp() abort
return luaeval('get_lsp_name()')
endfunction
@@ -159,7 +152,97 @@ function! Statusline() abort
endfunction
set statusline=%!Statusline()
+" Make shift + nav keys no-ops.
+nmap H <nop>
+nmap J <nop>
+nmap K <nop>
+nmap L <nop>
+" Normal mode tab no-op.
+nmap <Tab> <nop>
+" ctrl + c no-op.
+nmap <C-c> <nop>
+" Disable F1 for help.
+nmap <F1> <nop>
+" Disable q: for histroy.
+nmap q: <nop>
+" Simplify split movement.
+nmap <silent> <C-h> :wincmd h<CR>
+nmap <silent> <C-j> :wincmd j<CR>
+nmap <silent> <C-k> :wincmd k<CR>
+nmap <silent> <C-l> :wincmd l<CR>
+nmap <silent> <C-o> :vsplit<CR>
+" Make ctrl + '.' and ',' map to previous buffer.
+nmap <C-,> <C-^>
+nmap <C-.> <C-^>
+" Swap ctrl + f and b.
+nnoremap <C-b> <C-f>
+nnoremap <C-f> <C-b>
+" Toggle colorcolumn.
+nmap <silent> C :execute 'set colorcolumn=' . (&colorcolumn == '' ? '101' : '')<CR>
+" Personally intuitive pop-up menu binds.
+inoremap <expr> <CR> pumvisible() ? '<C-y><CR>' : '<CR>'
+inoremap <expr> <Up> pumvisible() ? '<C-p>' : '<Up>'
+inoremap <expr> <Down> pumvisible() ? '<C-n>' : '<Down>'
+" Lsp Binds.
+nmap <C-d> <C-]>
+" Fzf binds.
+nmap <silent> \ :Buffers<CR>
+nmap <silent> <C-i> :GGrep<CR>
+nmap <silent> <C-\> :GFiles<CR>
+" Only Neogit bind, handle all further operations from this menu.
+nmap <silent> Y :Neogit<CR>
+" Undotree
+nmap <silent> U :UndotreeToggle<CR>
+
+command Tabify set noexpandtab | %retab! | set expandtab
+command Untabify set expandtab | %retab!
+
+" https://stackoverflow.com/a/37040415
+function! SyntaxGroup()
+ let l:s = synID(line('.'), col('.'), 1)
+ echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
+endfun
+
+" https://github.com/junegunn/fzf.vim?tab=readme-ov-file#example-git-grep-wrapper
+command! -bang -nargs=* GGrep
+ \ call fzf#vim#grep(
+ \ 'git grep --line-number -- '.fzf#shellescape(<q-args>),
+ \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), <bang>0)
+
+" https://vim.fandom.com/wiki/Replace_a_builtin_command_using_cabbrev
+function! CommandCabbr(abbreviation, expansion)
+ execute 'cabbr ' . a:abbreviation . ' <C-R>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
+endfunction
+command! -nargs=+ CommandCabbr call CommandCabbr(<f-args>)
+CommandCabbr no nohlsearch
+
+call Juliana#Init() " Custom insert mode tab behavior inherited from Emacs.
+inoremap <silent><Tab> <C-R>=Juliana#CompleteTab('START')<CR>
+ \<C-R>=Juliana#CompleteTab('TAB')<CR>
+ \<C-R>=Juliana#CompleteTab('ALIGN')<CR>
+ \<C-R>=Juliana#CompleteTab('NEXT')<CR>
+inoremap <silent><S-Tab> <C-R>=Juliana#CompleteSTab('PREV')<CR>
+
lua << EOF
+function get_lsp_name()
+ local active_clients = vim.lsp.get_active_clients({bufnr = vim.api.nvim_get_current_buf()})
+ if next(active_clients) == nil then
+ return ''
+ else
+ return '+'..active_clients[1].name
+ end
+end
+
+buf_is_big = function(bufnr)
+ local max_filesize = 100 * 1024 -- 100 KB
+ local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(bufnr))
+ if ok and stats and stats.size > max_filesize then
+ return true
+ else
+ return false
+ end
+end
+
-- LSP configs.
if os.getenv('NIX_SHELL') ~= nil then
local lsp = require('lspconfig')
@@ -185,21 +268,25 @@ if os.getenv('NIX_SHELL') ~= nil then
}
})
lsp.ruff.setup({})
+ -- https://github.com/neovim/nvim-lspconfig/issues/2626#issuecomment-2117022664
+ -- https://github.com/neovim/nvim-lspconfig/issues/2508
+ vim.api.nvim_create_autocmd('BufReadPre', {
+ callback = function(t)
+ if buf_is_big(t.buf) then
+ vim.o.eventignore = "FileType"
+ vim.schedule(function()
+ vim.o.eventignore = ""
+ print("Dropped FileType events because the buffer is too big")
+ end)
+ end
+ end
+ })
require('inc_rename').setup({})
+ vim.keymap.set('n', '<C-n>', function()
+ return ':IncRename ' .. vim.fn.expand('<cword>')
+ end, { expr = true })
end
--- Try to make treesitter suck less.
-require('nvim-treesitter.configs').setup({
- highlight = {
- enable = true,
- additional_vim_regex_highlighting = false
- },
- indent = {
- enable = true,
- disable = { 'c', 'cpp' }
- }
-})
-
-- Set sessions folder and autowrite.
require('mini.sessions').setup({
autoread = false,
@@ -210,12 +297,6 @@ require('mini.sessions').setup({
-- Completion.
require('mini.completion').setup({})
--- Disable icons in diffview.
-require('diffview').setup({
- diff_binaries = false,
- use_icons = false
-})
-
-- Don't use tabs in Neogit.
require('neogit').setup({
disable_hint = true,
@@ -230,91 +311,12 @@ require('neogit').setup({
refs_view = { kind = 'split' },
-- Allow basic movement in Neogit without mapping conflicts.
mappings = {
- popup = { ['l'] = false, ['L'] = 'LogPopup' },
+ popup = { ['l'] = false, ['L'] = 'LogPopup', ['d'] = false },
status = { ['$'] = false, ['#'] = 'CommandHistory' }
- }
+ },
+ integrations = {}
})
-- Preview colors in #<hex> format.
require('ccc').setup({ highlighter = { auto_enable = false, lsp = true } })
-
---require("perfanno").setup({
--- telescope = {
--- enabled = false,
--- },
---})
-
--- Make shift + nav keys no-ops.
-vim.keymap.set('n', 'H', '<nop>', { silent = true })
-vim.keymap.set('n', 'J', '<nop>', { silent = true })
-vim.keymap.set('n', 'K', '<nop>', { silent = true })
-vim.keymap.set('n', 'L', '<nop>', { silent = true })
--- Normal mode tab no-op.
-vim.keymap.set('n', '<Tab>', '<nop>', { silent = true })
--- ctrl + c no-op.
-vim.keymap.set('n', '<C-c>', '<nop>', { silent = true })
--- Disable F1 for help.
-vim.keymap.set('n', '<F1>', '<nop>', { silent = true })
--- Disable q: for histroy.
-vim.keymap.set('n', 'q:', '<nop>', { silent = true })
--- Simplify split movement.
-vim.keymap.set('n', '<C-h>', [[:wincmd h<CR>]], { silent = true })
-vim.keymap.set('n', '<C-j>', [[:wincmd j<CR>]], { silent = true })
-vim.keymap.set('n', '<C-k>', [[:wincmd k<CR>]], { silent = true })
-vim.keymap.set('n', '<C-l>', [[:wincmd l<CR>]], { silent = true })
-vim.keymap.set('n', '<C-o>', [[:vsplit<CR>]], { silent = true })
--- Make ctrl + '.' and ',' map to previous buffer.
-vim.keymap.set('n', '<C-,>', '<C-^>', {})
-vim.keymap.set('n', '<C-.>', '<C-^>', {})
--- Swap ctrl + f and b.
-vim.keymap.set('n', '<C-f>', '<C-b>', {})
-vim.keymap.set('n', '<C-b>', '<C-f>', {})
--- Undotree
-vim.keymap.set('n', 'U', vim.cmd.UndotreeToggle)
--- Toggle colorcolumn.
-vim.keymap.set('n', 'C', [[:execute 'set colorcolumn=' . (&colorcolumn == '' ? '101' : '')<CR>]], { silent = true })
--- Personally intuitive pop-up menu binds.
-vim.keymap.set('i', '<CR>', [[pumvisible() ? '<C-y><CR>' : '<CR>']], { expr = true })
-vim.keymap.set('i', '<Up>', [[pumvisible() ? '<C-p>' : '<Up>']], { expr = true })
-vim.keymap.set('i', '<Down>', [[pumvisible() ? '<C-n>' : '<Down>']], { expr = true })
--- Lsp Binds.
-vim.keymap.set('n', '<C-d>', '<C-]>', {})
-vim.keymap.set('n', '<C-n>', function()
- return ':IncRename ' .. vim.fn.expand('<cword>')
-end, { expr = true })
--- Fzf binds.
-vim.keymap.set('n', '\\', [[:Buffers<CR>]], { silent = true })
-vim.keymap.set('n', '<C-i>', [[:GGrep<CR>]], { silent = true })
-vim.keymap.set('n', '<C-\\>', [[:GFiles<CR>]], { silent = true })
--- Only Neogit bind, handle all further operations from this menu.
-vim.keymap.set('n', 'Y', [[:Neogit<CR>]], { silent = true })
EOF
-
-command Tabify set noexpandtab | %retab! | set expandtab
-command Untabify set expandtab | %retab!
-
-" https://stackoverflow.com/a/37040415
-function! SyntaxGroup()
- let l:s = synID(line('.'), col('.'), 1)
- echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
-endfun
-
-" https://github.com/junegunn/fzf.vim?tab=readme-ov-file#example-git-grep-wrapper
-command! -bang -nargs=* GGrep
- \ call fzf#vim#grep(
- \ 'git grep --line-number -- '.fzf#shellescape(<q-args>),
- \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), <bang>0)
-
-" https://vim.fandom.com/wiki/Replace_a_builtin_command_using_cabbrev
-function! CommandCabbr(abbreviation, expansion)
- execute 'cabbr ' . a:abbreviation . ' <C-R>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
-endfunction
-command! -nargs=+ CommandCabbr call CommandCabbr(<f-args>)
-CommandCabbr no nohlsearch
-
-call Juliana#Init() " Custom insert mode tab behavior inherited from Emacs.
-inoremap <silent><Tab> <C-R>=Juliana#CompleteTab('START')<CR>
- \<C-R>=Juliana#CompleteTab('TAB')<CR>
- \<C-R>=Juliana#CompleteTab('ALIGN')<CR>
- \<C-R>=Juliana#CompleteTab('NEXT')<CR>
-inoremap <silent><S-Tab> <C-R>=Juliana#CompleteSTab('PREV')<CR>
diff --git a/files/nvim/mini_starter_picture.diff b/files/nvim/mini_starter_picture.diff
index 555009a..7831ca1 100644
--- a/files/nvim/mini_starter_picture.diff
+++ b/files/nvim/mini_starter_picture.diff
@@ -1,5 +1,5 @@
diff --git a/lua/mini/starter.lua b/lua/mini/starter.lua
-index 64939dc..493486b 100644
+index 8520569e..939e16de 100644
--- a/lua/mini/starter.lua
+++ b/lua/mini/starter.lua
@@ -138,7 +138,7 @@
@@ -11,7 +11,17 @@ index 64939dc..493486b 100644
--- timer:stop()
--- return
--- end
-@@ -249,6 +249,12 @@ MiniStarter.config = {
+@@ -239,6 +239,9 @@ MiniStarter.config = {
+ -- If `nil` (default), default items will be used (see |mini.starter|).
+ items = nil,
+
++ -- Empty lines at the top of the content.
++ top_padding = 0,
++
+ -- Header to be displayed before items. Converted to single string via
+ -- `tostring` (use `\n` to display several lines). If function, it is
+ -- evaluated first. If `nil` (default), polite greeting will be used.
+@@ -249,6 +252,12 @@ MiniStarter.config = {
-- evaluated first. If `nil` (default), default usage help will be shown.
footer = nil,
@@ -24,7 +34,7 @@ index 64939dc..493486b 100644
-- Array of functions to be applied consecutively to initial content.
-- Each function should take and return content for Starter buffer (see
-- |mini.starter| and |MiniStarter.get_content()| for more details).
-@@ -372,7 +378,7 @@ MiniStarter.refresh = function(buf_id)
+@@ -372,7 +381,7 @@ MiniStarter.refresh = function(buf_id)
data.footer = H.normalize_header_footer(config.footer or H.default_footer)
-- Evaluate content
@@ -33,7 +43,7 @@ index 64939dc..493486b 100644
local hooks = config.content_hooks or H.default_content_hooks
for _, f in ipairs(hooks) do
content = f(content, buf_id)
-@@ -399,6 +405,12 @@ MiniStarter.refresh = function(buf_id)
+@@ -399,6 +408,12 @@ MiniStarter.refresh = function(buf_id)
-- Apply current query (clear command line afterwards)
H.make_query(buf_id)
@@ -46,7 +56,7 @@ index 64939dc..493486b 100644
end
--- Close Starter buffer
-@@ -730,18 +742,45 @@ MiniStarter.gen_hook.aligning = function(horizontal, vertical)
+@@ -730,18 +745,45 @@ MiniStarter.gen_hook.aligning = function(horizontal, vertical)
local win_id = vim.fn.bufwinid(buf_id)
if win_id < 0 then return end
@@ -88,13 +98,13 @@ index 64939dc..493486b 100644
+ H.picture_x = left_pad + picture_left_pad
+ end
+ if H.picture_x < 0.0 then H.picture_x = 0.0 end
-+ H.picture_y = top_pad + config.picture.padding.top
++ H.picture_y = top_pad + config.picture.padding.top + config.top_padding
+ end
+
return MiniStarter.gen_hook.padding(left_pad, top_pad)(content)
end
end
-@@ -1004,7 +1043,7 @@ H.default_footer = [[
+@@ -1004,7 +1046,7 @@ H.default_footer = [[
Type query to filter items
<BS> deletes latest character from query
<Esc> resets current query
@@ -103,7 +113,7 @@ index 64939dc..493486b 100644
<CR> executes action of current item
<C-c> closes this buffer]]
-@@ -1052,8 +1091,54 @@ end
+@@ -1048,8 +1090,54 @@ end
H.apply_config = function(config) MiniStarter.config = config end
@@ -159,7 +169,7 @@ index 64939dc..493486b 100644
if config.autoopen then
local on_vimenter = function()
-@@ -1065,7 +1150,7 @@ H.create_autocommands = function(config)
+@@ -1061,7 +1149,7 @@ H.create_autocommands = function(config)
vim.cmd('noautocmd lua MiniStarter.open()')
end
@@ -168,7 +178,7 @@ index 64939dc..493486b 100644
vim.api.nvim_create_autocmd('VimEnter', au_opts)
end
-@@ -1111,7 +1196,7 @@ H.normalize_header_footer = function(x)
+@@ -1107,9 +1195,11 @@ H.normalize_header_footer = function(x)
end
-- Work with buffer content ---------------------------------------------------
@@ -176,8 +186,12 @@ index 64939dc..493486b 100644
+H.make_initial_content = function(header, items, footer, config)
local content = {}
++ H.content_add_empty_lines(content, config.top_padding)
++
-- Add header lines
-@@ -1124,7 +1209,7 @@ H.make_initial_content = function(header, items, footer)
+ for _, l in ipairs(header) do
+ H.content_add_line(content, { H.content_unit(l, 'header', 'MiniStarterHeader') })
+@@ -1120,7 +1210,7 @@ H.make_initial_content = function(header, items, footer)
H.content_add_items(content, items)
-- Add footer lines
@@ -186,7 +200,7 @@ index 64939dc..493486b 100644
for _, l in ipairs(footer) do
H.content_add_line(content, { H.content_unit(l, 'footer', 'MiniStarterFooter') })
end
-@@ -1327,11 +1412,22 @@ H.make_buffer_autocmd = function(buf_id)
+@@ -1323,11 +1413,22 @@ H.make_buffer_autocmd = function(buf_id)
au('VimResized', function() MiniStarter.refresh(buf_id) end, 'Refresh')
au('CursorMoved', function() H.position_cursor_on_current_item(buf_id) end, 'Position cursor')
@@ -209,7 +223,7 @@ index 64939dc..493486b 100644
end
H.apply_buffer_options = function(buf_id)
-@@ -1345,17 +1441,11 @@ H.apply_buffer_options = function(buf_id)
+@@ -1341,17 +1442,11 @@ H.apply_buffer_options = function(buf_id)
-- Set unique buffer name. Prefer "Starter" prefix as more user friendly.
H.buffer_number = H.buffer_number + 1
@@ -229,7 +243,7 @@ index 64939dc..493486b 100644
local options = {
-- Taken from 'vim-startify'
-@@ -1401,12 +1491,8 @@ H.apply_buffer_mappings = function(buf_id)
+@@ -1398,12 +1493,8 @@ H.apply_buffer_mappings = function(buf_id)
buf_keymap('<CR>', 'MiniStarter.eval_current_item()')
@@ -244,7 +258,7 @@ index 64939dc..493486b 100644
-- Make all special symbols to update query
for _, key in ipairs(vim.split(H.get_config().query_updaters, '')) do
-@@ -1487,7 +1573,7 @@ H.echo = function(msg, is_important)
+@@ -1491,7 +1582,7 @@ H.echo = function(msg, is_important)
-- Construct message chunks
msg = type(msg) == 'string' and { { msg } } or msg
@@ -253,7 +267,7 @@ index 64939dc..493486b 100644
-- Avoid hit-enter-prompt
local max_width = vim.o.columns * math.max(vim.o.cmdheight - 1, 0) + vim.v.echospace
-@@ -1525,7 +1611,7 @@ H.eval_fun_or_string = function(x, string_as_cmd)
+@@ -1540,7 +1631,7 @@ H.eval_fun_or_string = function(x, string_as_cmd)
if type(x) == 'function' then return x() end
if type(x) == 'string' then
if string_as_cmd then