Skip to content

Commit

Permalink
nvim: move to more mini plugins, adjust lspp keybindings, docs summar…
Browse files Browse the repository at this point in the history
…ies, cleanups
  • Loading branch information
matu3ba committed Dec 6, 2024
1 parent 7c0a95e commit a68825a
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 169 deletions.
1 change: 0 additions & 1 deletion .config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ else
require 'my_lint' -- setup in my_lint.lua
require 'my_statusline' -- statusline
require 'my_over' -- runner
require 'my_surround' -- text_surround
require 'my_aerial' -- overview_window
require 'my_oil' -- file_explorer
require 'my_fmt' -- smart_formatter
Expand Down
17 changes: 16 additions & 1 deletion .config/nvim/lua/my_cmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
local has_plenary, plenary = pcall(require, 'plenary')
if not has_plenary then vim.print 'Please install plenary for all features.' end

-- run commands
-- :! {cmd}, !% {cmd}
-- dont use these: :terminal {cmd} io.popen(), uv.spawn()
-- use instead: vim.system() [sync and async], fn.termopen({cmd}) [async], api.nvim_open_term [async]
-- rarely useful: api.nvim_open_term
-- vim.system({'echo', 'hello'}, { text=true }, function(obj)
-- print(obj.code)
-- print(obj.stdout)
-- print(obj.stderr)
-- end)
-- local obj = vim.system({'echo', 'hello'}, { text=true }):wait()
-- { code = 0, signal = 0, stdout = '..', stderr = '' }

-- local obj = vim.system(exec curl)
-- local decoded = vim.json.decode(obj)

--TODO steal commands to run find into quickfix list from
--vim.fn.setloclist(winnr, {}, ' ', { items = items })
--vim.fn.setqflist({}, " ", {nr = "$", items = entries})
Expand All @@ -13,7 +29,6 @@ if not has_plenary then vim.print 'Please install plenary for all features.' end
--(c/l)ex[pr]! expr - create (q/l)l from expr + jump to first error
--cad[dbuffer]|laddb[uffer] add errors to (q/l)list
--(c/l)gete[xpr] expr - same as (c/l)ex[pr], but without jumping
-- TODO document :cdo etc

-- TODO make fn for :!mkdir -p %:h
-- TODO nvim +':w ++p' /path/to/file
Expand Down
39 changes: 14 additions & 25 deletions .config/nvim/lua/my_keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ map('n', '<C-s><C-s>', [[<cmd>w<CR>]], opts) -- fast saving of local file
-- to first/last 1.char of prev changed/yanked text, 2. selection, 3. jump,
-- 4.quote,5.insertion mode stop,6.last change,7.sentence,8.paragraph
-- 1.]'/2.]`/3.[' 1.count time to next line with lowercase mark below cursor
-- 2.count times to lowercase mark after cusor, 3.count times to prev line
-- 2.count times to lowercase mark after cursor, 3.count times to prev line
-- with lower case mark before cursor, [` count time to lowercase mark before
-- cursor
-- 1.:loc,2.:kee,3.:keepj {cmd} 1. execute cmd without adjusting marks,
Expand All @@ -120,11 +120,13 @@ map('n', '<C-s><C-s>', [[<cmd>w<CR>]], opts) -- fast saving of local file
-- [#/]#,[*|[/,]*,]/ go to [count] prev/next start of C comment

-- Search helpers
map('n', ',', [[viwP]], opts) -- keep pasting over the same thing for current word, simple instead of broken for EOL [["_diwP]]
-- map('n', ',', [[viwP]], opts) -- keep pasting over the same thing for current word, simple instead of broken for EOL [["_diwP]]
map('n', '*', [[m`:keepjumps normal! *``<CR>]], opts) -- word boundary search, no autojump
map('n', 'g*', [[m`:keepjumps normal! g*``<CR>]], opts) -- no word boundary search no autojump
--map('n', '/', [[:setl hls | let @/ = input('/')<CR>]], opts) -- no incsearch on typing
-- Note: * and # also work, but they autojump to next search result
-- TODO line search must also work for V selection, not only for 0vE//
-- TODO implement block search
map('v', '//', [[y/\V<C-R>=escape(@",'/\')<CR><CR>]], opts) -- search selected region on current line
-- 1. cgn to cut global next or something
-- 2. /pattern/e
Expand Down Expand Up @@ -457,18 +459,9 @@ map('n', '<F12>', [[<cmd>DapStepOut<CR>]], opts) -- s-f12 not used to prevent es
--nnoremap <leader>db :Telescope dap list_breakpoints<CR>

--==lspconfig
-- defaults
-- <C-s>: vim.lsp.buf.signature_help()
-- <gO>: vim.lsp.buf.document_symbol()
-- <grS>: vim.lsp.buf.workspace_symbol()
-- <gra>: vim.lsp.buf.code_action()
-- <gri>: vim.lsp.buf.implementation()
-- <grn>: vim.lsp.buf.rename()
-- <grr>: vim.lsp.buf.references()
-- <grs>: vim.lsp.buf.workspace_symbol()
--vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
--vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- see :CLsp lua/my_lsp.lua LspAttach
-- looks like deleting one default keybinding deletes all of them
vim.keymap.del('n', 'gO') -- '<leader>O'
-- see :CLsp .config/nvim/lua/my_lsp.lua LspAttach

-- see also echasnovski/mini.bracketed
-- • Mappings inspired by Tim Pope's vim-unimpaired:
Expand Down Expand Up @@ -504,19 +497,19 @@ map('n', '<leader>ta', '<cmd>execute "tag " .. expand("<cword>")<CR>', opts)
--map('n', '<LeftMouse>', '<LeftMouse><cmd>lua vim.lsp.buf.hover({border = "single"})<CR>', opts)
--map('n', '<RightMouse>', '<LeftMouse><cmd>lua vim.lsp.buf.definition()<CR>', opts)

--==telescope fuzzy_match 'extact_match ^prefix-exact suffix_exact$ !inverse_match, C-x split,C-v vsplit,C-t new tab
--==telescope fuzzy_match 'exact_match ^prefix-exact suffix_exact$ !inverse_match, C-x split,C-v vsplit,C-t new tab
-- vimgrep AA also sends into a quickfix
-- C-q (send to quickfixlist), :cdo %s/<search term>/<replace term>/gc, :cdo update (saving)
-- :norm {Vim} run command on every line
-- shift|shift+tab selects items
-- TODO overlap with gitsigns somehow
-- TODO: resolve https://github.com/nvim-telescope/telescope.nvim/issues/647
map('n', '<leader>tb', [[<cmd>lua require('telescope.builtin').buffers()<CR>]], opts) -- buffers
map('n', '<leader>ts', [[<cmd>lua require('telescope.builtin').lsp_document_symbols()<CR>]], opts) -- buffer: document symbols
map('n', '<leader>tls', [[<cmd>lua require('telescope.builtin').lsp_document_symbols()<CR>]], opts) -- buffer: document symbols
map('n', '<leader>tk', [[<cmd>lua require('telescope.builtin').keymaps()<CR>]], opts) -- keybindings
map('n', '<leader>tt', [[<cmd>lua require('telescope.builtin').tags()<CR>]], opts) -- keybindings
-- -- builtin.commands, nmap, vmap, imap
map('n', '<leader>tS', [[<cmd>lua require('telescope.builtin').lsp_dynamic_workspace_symbols()<CR>]], opts) -- workspace symbols (bigger)
map('n', '<leader>tlS', [[<cmd>lua require('telescope.builtin').lsp_dynamic_workspace_symbols()<CR>]], opts) -- workspace symbols (bigger)
map('n', '<leader>tf', [[<cmd>lua require('telescope.builtin').find_files()<CR>]], opts) -- find files
-- map('n', '<leader>gf', [[<cmd>lua require('telescope.builtin').git_files()<CR>]], opts) -- git files
map('n', '<leader>tg', [[<cmd>lua require('telescope.builtin').git_files()<CR>]], opts) -- git files
Expand All @@ -527,10 +520,10 @@ map('n', '<leader>ma', [[<cmd>lua require('material.functions').find_style()<CR>

-- stylua: ignore start
-- telescope leaks memory at cancellation points (unless the query can processes quickly)
map('n', '<leader>rg', [[<cmd>lua require('telescope.builtin').grep_string { search = vim.fn.expand("<cword>") }<CR>]], opts) -- ripgrep string search
map('n', '<leader>ss', [[<cmd>lua require("my_telesc").searchStringRecentReg()<CR>]], opts) -- search string
map('n', '<leader>fs', [[<cmd>GrepInDirectory<CR>]], opts) -- forwardIntoDir searchstring
map('n', '<leader>th', [[<cmd>lua require('telescope.builtin').help_tags()<CR>]], opts) -- helptags
map('n', '<leader>trg', [[<cmd>lua require('telescope.builtin').grep_string { search = vim.fn.expand("<cword>") }<CR>]], opts) -- ripgrep string search
map('n', '<leader>tss', [[<cmd>lua require("my_telesc").searchStringRecentReg()<CR>]], opts) -- search string
map('n', '<leader>tfs', [[<cmd>GrepInDirectory<CR>]], opts) -- forwardIntoDir searchstring
map('n', '<leader>the', [[<cmd>lua require('telescope.builtin').help_tags()<CR>]], opts) -- helptags
-- stylua: ignore end
-- <C-p> for projects ?
--map('n', '<leader>pr', [[<cmd>lua require'telescope'.extensions.project.project{display_type = 'full'}<CR>]], opts) -- project: d, r, c, s(in your project), w(change dir without open), f
Expand Down Expand Up @@ -617,10 +610,6 @@ end
-- `sendCommand(1, ':lua callfn(arg1, arg2,..)<CR>')`
-- or provide the cwd to use for the other neovim instance.

--====overseer
--build,close,clear,del,info,loadbu,open,quickact,runcmd,savebu,taskact,toggle,
map('n', ';t', [[<cmd>OverseerToggle<CR>]], opts)

--====harpoon
-- TODO copy last command into named/unnamed register
-- removing via quick menu is simpler
Expand Down
53 changes: 37 additions & 16 deletions .config/nvim/lua/my_lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,41 @@ vim.api.nvim_create_autocmd('LspAttach', {
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
-- vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
-- vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
-- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)

-- unclear if needed or not, works
--==defaults
-- see my_keymaps.lua for gO
-- vim.keymap.del('v', 'gra') -- '<leader>ra'
-- vim.keymap.del('n', 'gra') -- '<leader>rd'
-- vim.keymap.del('n', 'gri') -- '<leader>ri'
-- vim.keymap.del('n', 'grn') -- '<leader>rn'
-- vim.keymap.del('n', 'grr') -- '<leader>rr'

vim.keymap.set('n', '<leader>O', vim.lsp.buf.document_symbol, opts)
vim.keymap.set('n', '<leader>rD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', '<leader>ra', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', '<leader>rd', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<leader>ri', vim.lsp.buf.definition, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<leader>rr', vim.lsp.buf.references, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.signature_help, opts)

-- switch source header in same folder: map <F4> :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp,<CR>
vim.keymap.set('n', '<leader>sh', ':ClangdSwitchSourceHeader<CR>', opts) -- switch header_source
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
--==defaults
-- <grn>: vim.lsp.buf.rename()
-- <gra>: vim.lsp.buf.code_action()
-- <grr>: vim.lsp.buf.references()

-- TODO use different keybindings

--==provided with mini.bracketed
-- vim.keymap.set('n', '[e', function() vim.diagnostic.goto_prev() end, opts) -- next error
-- vim.keymap.set('n', ']e', function() vim.diagnostic.goto_next() end, opts) -- previous error

-- TODO: figure out how to solve this, because this is super annoying
-- local bufnr = vim.api.nvim_get_current_buf()
-- stylua: ignore start
vim.keymap.set('n', 'grf', function()
local params = vim.lsp.util.make_range_params()
vim.keymap.set('n', '<leader>rf', function()
local params = vim.lsp.util.make_range_params(0, "utf-8")
params.context = { only = { "source.fixAll" }, triggerKind = vim.lsp.protocol.CodeActionTriggerKind.Invoked, diagnostics = vim.lsp.diagnostic.get_line_diagnostics(), }
-- results is an array of lsp.CodeAction
local diags = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
Expand Down Expand Up @@ -232,13 +247,13 @@ vim.api.nvim_create_autocmd('LspAttach', {
end, opts)
-- stylua: ignore end

vim.keymap.set('n', 'grf', function()
vim.lsp.buf.code_action {
-- type annotation for missing field diagnostics is wrong, because its optional
context = { only = { 'source.fixAll' } },
apply = true,
}
end, opts)
-- vim.keymap.set('n', 'grf', function()
-- vim.lsp.buf.code_action {
-- -- type annotation for missing field diagnostics is wrong, because its optional
-- context = { only = { 'source.fixAll' } },
-- apply = true,
-- }
-- end, opts)

-- vim.keymap.set('n', '<leader>hi', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({})) end, opts)
-- defaults with neovim release 10.0
Expand Down Expand Up @@ -304,7 +319,13 @@ blink.setup {
use_nvim_cmp_as_default = true,
nerd_font_variant = 'mono',
},
keymap = { preset = 'default' },
keymap = {
preset = 'default',
-- ['<C-space>'] = { 'accept', 'fallback' },
-- ['<C-y>'] = { 'select_and_accept' },
-- ['<C-d>'] = { 'show', 'show_documentation', 'hide_documentation' },
-- ['<CR>'] = { 'accept', 'fallback' },
},
sources = {
completion = {
enabled_providers = { 'lsp', 'path', 'snippets', 'buffer', 'lazydev' },
Expand Down
9 changes: 7 additions & 2 deletions .config/nvim/lua/my_over.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ end
-- end
-- end

--====overseer
--build,close,clear,del,info,loadbu,open,quickact,runcmd,savebu,taskact,toggle,
vim.keymap.set('n', ';tt', [[<cmd>OverseerToggle<CR>]], { desc = string.format 'Toggle Overseer' })
-- vim.keymap.set('n', ';tt', overseer.setup, { desc = string.format 'Toggle Overseer' })

-- ;1..9 ;e1..9 ;o1..9 ;p1..9 ;t1..9
for i = 1, 9 do
vim.keymap.set('n', ';o' .. i, get_task_callback(i, 'open'), { desc = string.format('Open output here task #%d', i) })
Expand All @@ -128,11 +133,11 @@ end

vim.keymap.set('n', ';bs', function()
local bundle_name = vim.fs.basename(vim.fn.getcwd())
require('overseer').save_task_bundle(bundle_name, nil, { on_conflict = 'overwrite' })
overseer.save_task_bundle(bundle_name, nil, { on_conflict = 'overwrite' })
end)
vim.keymap.set('n', ';bl', function()
local bundle_name = vim.fs.basename(vim.fn.getcwd())
require('overseer').load_task_bundle(bundle_name)
overseer.load_task_bundle(bundle_name)
end)

-- local function validate_callback(task_id, exact)
Expand Down
Loading

0 comments on commit a68825a

Please sign in to comment.