nvim: mini.pick fixings
This commit is contained in:
parent
6cbd28148a
commit
e77885fdef
3 changed files with 110 additions and 84 deletions
|
@ -1,4 +1,4 @@
|
||||||
vim.g.mapleader = "<space>"
|
vim.g.mapleader = ' '
|
||||||
vim.g.maplocalleader = ","
|
vim.g.maplocalleader = ","
|
||||||
|
|
||||||
-- UI
|
-- UI
|
||||||
|
@ -14,13 +14,14 @@ vim.opt.termguicolors = true
|
||||||
-- Ruler
|
-- Ruler
|
||||||
function GetIndicators()
|
function GetIndicators()
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
local counts = vim.diagnostic.count(bufnr)
|
local counts = vim.diagnostic.count(bufnr)
|
||||||
local errors = counts[vim.diagnostic.severity.ERROR] or 0
|
local errors = counts[vim.diagnostic.severity.ERROR] or 0
|
||||||
local warnings = counts[vim.diagnostic.severity.WARN] or 0
|
local warnings = counts[vim.diagnostic.severity.WARN] or 0
|
||||||
local warn_string = warnings > 0 and "%#DiagnosticWarn# " .. warnings .. " " or " "
|
local warn_string = warnings > 0 and "%#DiagnosticWarn# " .. warnings .. " " or " "
|
||||||
local error_string = errors > 0 and "%#DiagnosticError# " .. errors .. " " or " "
|
local error_string = errors > 0 and "%#DiagnosticError# " .. errors .. " " or " "
|
||||||
return warn_string .. error_string
|
return warn_string .. error_string
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.opt.rulerformat = "%40(%=%{%v:lua.GetIndicators()%}%#Label#│ %t %)"
|
vim.opt.rulerformat = "%40(%=%{%v:lua.GetIndicators()%}%#Label#│ %t %)"
|
||||||
|
|
||||||
-- Search
|
-- Search
|
||||||
|
@ -95,8 +96,72 @@ vim.keymap.set({ "i", "s" }, "<Tab>", function()
|
||||||
end
|
end
|
||||||
end, { expr = true })
|
end, { expr = true })
|
||||||
|
|
||||||
vim.keymap.set({ "n" }, "<c-/>", "gcc", { remap = true })
|
|
||||||
vim.keymap.set({ "v" }, "<c-/>", "gc", { remap = true })
|
-- Keymap
|
||||||
vim.keymap.set({ "n" }, "<c-_>", "gcc", { remap = true })
|
local opts = function(label)
|
||||||
vim.keymap.set({ "v" }, "<c-_>", "gc", { remap = true })
|
return { noremap = true, silent = true, desc = label }
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Comments
|
||||||
|
vim.keymap.set("n", "<c-/>", "gcc", { remap = true })
|
||||||
|
vim.keymap.set("v", "<c-/>", "gc", { remap = true })
|
||||||
|
vim.keymap.set("n", "<c-_>", "gcc", { remap = true })
|
||||||
|
vim.keymap.set("v", "<c-_>", "gc", { remap = true })
|
||||||
|
|
||||||
|
vim.keymap.set({ "n", "v" }, "<Leader>a", vim.lsp.buf.code_action, { remap = true, desc = "Code action" })
|
||||||
|
vim.keymap.set("n", "<Leader>af", function()
|
||||||
|
vim.lsp.buf.format({ async = true })
|
||||||
|
end, opts("Format Buffer"))
|
||||||
|
vim.keymap.set('n', '<Leader>b', "<cmd>Pick buffers<cr>", opts("Open buffer picker"))
|
||||||
|
vim.keymap.set('n', '<Leader>/', "<cmd>Pick grep_live_root<cr>", opts("Search workspace files"))
|
||||||
|
vim.keymap.set('n', '<Leader>d', "<cmd>Pick diagnostic<cr>", opts("Open diagnostics picker"))
|
||||||
|
vim.keymap.set("n", "<Leader>D", vim.diagnostic.setloclist, { desc = "Diagnostics to location list" })
|
||||||
|
vim.keymap.set("n", "<Leader>r", vim.lsp.buf.rename, opts("Rename Symbol"))
|
||||||
|
vim.keymap.set('n', '<Leader>F', "<cmd>Pick files<cr>", opts("Open file picker CWD"))
|
||||||
|
vim.keymap.set('n', '<Leader>f', "<cmd>Pick files_root<cr>", opts("Open file picker"))
|
||||||
|
vim.keymap.set('n', '<Leader>g', "<cmd>Pick oldfiles<cr>", opts("Open file picker history"))
|
||||||
|
vim.keymap.set("n", '<Leader>k', vim.lsp.buf.hover, opts("Show docs for item under cursor"))
|
||||||
|
vim.keymap.set('n', '<Leader>q', require('mini.bufremove').delete, opts("Delete buffer"))
|
||||||
|
vim.keymap.set('n', '<Leader>s', "<cmd>Pick lsp scope='document_symbol'<cr>", opts("Open symbol picker"))
|
||||||
|
vim.keymap.set('n', '<Leader>S', "<cmd>Pick lsp scope='workspace_symbol'<cr>", opts("Open workspace symbol picker"))
|
||||||
|
vim.keymap.set('n', '<tab>', "<cmd>Pick buffers include_current=false<cr>", opts("Buffers"))
|
||||||
vim.keymap.set("n", "zz", "zt", { remap = true })
|
vim.keymap.set("n", "zz", "zt", { remap = true })
|
||||||
|
vim.keymap.set({ "n", "v" }, "<Leader>y", '"+y', opts("Yank to clipboard"))
|
||||||
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
|
||||||
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Declaration"))
|
||||||
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Definition"))
|
||||||
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Implementation"))
|
||||||
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Buffer References"))
|
||||||
|
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, opts("Type Definition"))
|
||||||
|
vim.keymap.set({"n", "i"}, "<M-k>", vim.lsp.buf.signature_help, opts("Signature Help"))
|
||||||
|
vim.keymap.set({ "n", "v" }, "<Leader>aa", vim.lsp.buf.code_action, opts("Code Action"))
|
||||||
|
vim.keymap.set("n", "<Leader>ws", "<C-w>s", opts("Horizontal split"))
|
||||||
|
vim.keymap.set("n", "<Leader>wv", "<C-w>v", opts("Vertical split"))
|
||||||
|
|
||||||
|
-- Completion
|
||||||
|
vim.keymap.set('i', '<Tab>', [[pumvisible() ? "\<C-n>" : "\<Tab>"]], { expr = true })
|
||||||
|
vim.keymap.set('i', '<S-Tab>', [[pumvisible() ? "\<C-p>" : "\<S-Tab>"]], { expr = true })
|
||||||
|
|
||||||
|
local keycode = vim.keycode or function(x)
|
||||||
|
return vim.api.nvim_replace_termcodes(x, true, true, true)
|
||||||
|
end
|
||||||
|
local keys = {
|
||||||
|
['cr'] = keycode('<CR>'),
|
||||||
|
['ctrl-y'] = keycode('<C-y>'),
|
||||||
|
['ctrl-y_cr'] = keycode('<C-y><CR>'),
|
||||||
|
}
|
||||||
|
|
||||||
|
_G.cr_action = function()
|
||||||
|
if vim.fn.pumvisible() ~= 0 then
|
||||||
|
-- If popup is visible, confirm selected item or add new line otherwise
|
||||||
|
local item_selected = vim.fn.complete_info()['selected'] ~= -1
|
||||||
|
return item_selected and keys['ctrl-y'] or keys['ctrl-y_cr']
|
||||||
|
else
|
||||||
|
-- If popup is not visible, use plain `<CR>`. You might want to customize
|
||||||
|
-- according to other plugins. For example, to use 'mini.pairs', replace
|
||||||
|
-- next line with `return require('mini.pairs').cr()`
|
||||||
|
return keys['cr']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('i', '<CR>', 'v:lua._G.cr_action()', { expr = true })
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
vim.keymap.set("n", "<space>d", vim.diagnostic.setloclist, { desc = "Add buffer diagnostics to the location list." })
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("LspAttach", {
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
|
@ -16,28 +14,6 @@ vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
if client.server_capabilities.codeLensProvider then
|
if client.server_capabilities.codeLensProvider then
|
||||||
vim.lsp.codelens.refresh({ bufnr = bufnr })
|
vim.lsp.codelens.refresh({ bufnr = bufnr })
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
|
|
||||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {})
|
|
||||||
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, {})
|
|
||||||
|
|
||||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Declaration"))
|
|
||||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Definition"))
|
|
||||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Implementation"))
|
|
||||||
vim.keymap.set("n", "<M-k>", vim.lsp.buf.signature_help, opts("Signature Help"))
|
|
||||||
vim.keymap.set("i", "<M-k>", vim.lsp.buf.signature_help, opts("Signature Help"))
|
|
||||||
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts("Add Workspace Folder"))
|
|
||||||
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts("Remove Workspace Folder"))
|
|
||||||
vim.keymap.set("n", "<space>wl", function()
|
|
||||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
||||||
end, opts("List Workspace Folders"))
|
|
||||||
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts("Type Definition"))
|
|
||||||
vim.keymap.set("n", "<space>r", vim.lsp.buf.rename, opts("Rename Symbol"))
|
|
||||||
vim.keymap.set({ "n", "v" }, "<space>a", vim.lsp.buf.code_action, opts("Code Action"))
|
|
||||||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Buffer References"))
|
|
||||||
vim.keymap.set("n", "<space>cf", function()
|
|
||||||
vim.lsp.buf.format({ async = true })
|
|
||||||
end, opts("Format Buffer"))
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
local opts = function(label)
|
|
||||||
return { noremap = true, silent = true, desc = label }
|
|
||||||
end
|
|
||||||
require('mini.ai').setup()
|
require('mini.ai').setup()
|
||||||
require('mini.align').setup()
|
require('mini.align').setup()
|
||||||
require('mini.bracketed').setup()
|
require('mini.bracketed').setup()
|
||||||
|
require('mini.bufremove').setup()
|
||||||
require('mini.comment').setup()
|
require('mini.comment').setup()
|
||||||
require('mini.diff').setup()
|
require('mini.diff').setup()
|
||||||
require('mini.extra').setup()
|
require('mini.extra').setup()
|
||||||
|
@ -13,50 +11,16 @@ require('mini.surround').setup()
|
||||||
require('mini.splitjoin').setup()
|
require('mini.splitjoin').setup()
|
||||||
require('mini.trailspace').setup()
|
require('mini.trailspace').setup()
|
||||||
|
|
||||||
local bufremove = require('mini.bufremove')
|
|
||||||
bufremove.setup()
|
|
||||||
vim.keymap.set('n', '<space>bd', bufremove.delete, opts("Delete"))
|
|
||||||
|
|
||||||
require('mini.cursorword').setup({
|
require('mini.cursorword').setup({
|
||||||
delay = 800
|
delay = 800
|
||||||
})
|
})
|
||||||
|
|
||||||
require('mini.completion').setup({
|
require('mini.completion').setup({
|
||||||
window = {
|
window = {
|
||||||
info = { height = 25, width = 80, border = 'rounded' },
|
info = { height = 25, width = 80, border = 'rounded' },
|
||||||
signature = { height = 25, width = 80, border = 'rounded' },
|
signature = { height = 25, width = 80, border = 'rounded' },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
local imap_expr = function(lhs, rhs)
|
|
||||||
vim.keymap.set('i', lhs, rhs, { expr = true })
|
|
||||||
end
|
|
||||||
imap_expr('<Tab>', [[pumvisible() ? "\<C-n>" : "\<Tab>"]])
|
|
||||||
imap_expr('<S-Tab>', [[pumvisible() ? "\<C-p>" : "\<S-Tab>"]])
|
|
||||||
|
|
||||||
local keycode = vim.keycode or function(x)
|
|
||||||
return vim.api.nvim_replace_termcodes(x, true, true, true)
|
|
||||||
end
|
|
||||||
local keys = {
|
|
||||||
['cr'] = keycode('<CR>'),
|
|
||||||
['ctrl-y'] = keycode('<C-y>'),
|
|
||||||
['ctrl-y_cr'] = keycode('<C-y><CR>'),
|
|
||||||
}
|
|
||||||
|
|
||||||
_G.cr_action = function()
|
|
||||||
if vim.fn.pumvisible() ~= 0 then
|
|
||||||
-- If popup is visible, confirm selected item or add new line otherwise
|
|
||||||
local item_selected = vim.fn.complete_info()['selected'] ~= -1
|
|
||||||
return item_selected and keys['ctrl-y'] or keys['ctrl-y_cr']
|
|
||||||
else
|
|
||||||
-- If popup is not visible, use plain `<CR>`. You might want to customize
|
|
||||||
-- according to other plugins. For example, to use 'mini.pairs', replace
|
|
||||||
-- next line with `return require('mini.pairs').cr()`
|
|
||||||
return keys['cr']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.keymap.set('i', '<CR>', 'v:lua._G.cr_action()', { expr = true })
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local hipatterns = require('mini.hipatterns')
|
local hipatterns = require('mini.hipatterns')
|
||||||
|
@ -84,9 +48,33 @@ require('mini.jump2d').setup({
|
||||||
mappings = { start_jumping = 'gw' }
|
mappings = { start_jumping = 'gw' }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local picker_win_config = function()
|
||||||
|
height = vim.o.lines - 8
|
||||||
|
width = 80
|
||||||
|
return {
|
||||||
|
border = 'rounded',
|
||||||
|
anchor = 'NW',
|
||||||
|
height = height,
|
||||||
|
width = width,
|
||||||
|
row = 2,
|
||||||
|
col = math.floor((vim.o.columns - width) / 2),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
require('mini.pick').setup({
|
require('mini.pick').setup({
|
||||||
mappings = { move_down = '<tab>' },
|
mappings = {
|
||||||
options = { use_cache = true }
|
move_down = '<tab>',
|
||||||
|
toggle_info = '<C-k>',
|
||||||
|
toggle_preview = '<C-p>',
|
||||||
|
},
|
||||||
|
options = { use_cache = true },
|
||||||
|
window = {
|
||||||
|
config = picker_win_config,
|
||||||
|
-- config = {
|
||||||
|
-- border = 'rounded',
|
||||||
|
-- width = 'auto',
|
||||||
|
-- },
|
||||||
|
},
|
||||||
})
|
})
|
||||||
MiniPick.registry.files_root = function(local_opts)
|
MiniPick.registry.files_root = function(local_opts)
|
||||||
local root_patterns = { ".jj", ".git" }
|
local root_patterns = { ".jj", ".git" }
|
||||||
|
@ -101,13 +89,6 @@ MiniPick.registry.grep_live_root = function(local_opts)
|
||||||
local_opts.cwd = root_dir
|
local_opts.cwd = root_dir
|
||||||
return MiniPick.builtin.grep_live(local_opts, { source = { cwd = root_dir } })
|
return MiniPick.builtin.grep_live(local_opts, { source = { cwd = root_dir } })
|
||||||
end
|
end
|
||||||
vim.keymap.set('n', '<space>/', "<cmd>Pick grep_live_root<cr>", opts("Live Grep"))
|
|
||||||
vim.keymap.set('n', '<space>fF', "<cmd>Pick files<cr>", opts("FindCWD"))
|
|
||||||
vim.keymap.set('n', '<space>ff', "<cmd>Pick files_root<cr>", opts("Find"))
|
|
||||||
vim.keymap.set('n', '<space>fr', "<cmd>Pick oldfiles<cr>", opts("Recent"))
|
|
||||||
vim.keymap.set('n', '<space>bb', "<cmd>Pick buffers<cr>", opts("Switch"))
|
|
||||||
vim.keymap.set('n', '<space>d', "<cmd>Pick diagnostics<cr>", opts("Diagnostics"))
|
|
||||||
vim.keymap.set('n', '<tab>', "<cmd>Pick buffers include_current=false<cr>", opts("Buffers"))
|
|
||||||
|
|
||||||
|
|
||||||
local miniclue = require('mini.clue')
|
local miniclue = require('mini.clue')
|
||||||
|
@ -157,7 +138,11 @@ miniclue.setup({ -- cute prompts about bindings
|
||||||
miniclue.gen_clues.z(),
|
miniclue.gen_clues.z(),
|
||||||
},
|
},
|
||||||
window = {
|
window = {
|
||||||
delay = 15,
|
delay = 0,
|
||||||
|
config = {
|
||||||
|
border = 'rounded',
|
||||||
|
width = 'auto',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -175,7 +160,7 @@ require('mini.notify').setup({
|
||||||
|
|
||||||
require('mini.starter').setup({
|
require('mini.starter').setup({
|
||||||
header =
|
header =
|
||||||
[[ ______ _
|
[[ ______ _
|
||||||
(_____ \ _ (_)
|
(_____ \ _ (_)
|
||||||
_____) )___| |_ ____ ____ _ ____
|
_____) )___| |_ ____ ____ _ ____
|
||||||
| ____/ _ | _)/ _ |/ _ | |/ _ |
|
| ____/ _ | _)/ _ |/ _ | |/ _ |
|
||||||
|
|
Loading…
Reference in a new issue