feat: add nvimdots

This commit is contained in:
2024-07-21 02:51:17 -04:00
parent f16942be42
commit e78c5ce3f5
149 changed files with 10623 additions and 43 deletions
+169
View File
@@ -0,0 +1,169 @@
---@class map_rhs
---@field cmd string
---@field options table
---@field options.noremap boolean
---@field options.silent boolean
---@field options.expr boolean
---@field options.nowait boolean
---@field options.callback function
---@field options.desc string
---@field buffer boolean|number
local rhs_options = {}
function rhs_options:new()
local instance = {
cmd = "",
options = {
noremap = false,
silent = false,
expr = false,
nowait = false,
callback = nil,
desc = "",
},
buffer = false,
}
setmetatable(instance, self)
self.__index = self
return instance
end
---@param cmd_string string
---@return map_rhs
function rhs_options:map_cmd(cmd_string)
self.cmd = cmd_string
return self
end
---@param cmd_string string
---@return map_rhs
function rhs_options:map_cr(cmd_string)
self.cmd = (":%s<CR>"):format(cmd_string)
return self
end
---@param cmd_string string
---@return map_rhs
function rhs_options:map_args(cmd_string)
self.cmd = (":%s<Space>"):format(cmd_string)
return self
end
---@param cmd_string string
---@return map_rhs
function rhs_options:map_cu(cmd_string)
-- <C-u> to eliminate the automatically inserted range in visual mode
self.cmd = (":<C-u>%s<CR>"):format(cmd_string)
return self
end
---@param callback fun():nil
--- Takes a callback that will be called when the key is pressed
---@return map_rhs
function rhs_options:map_callback(callback)
self.cmd = ""
self.options.callback = callback
return self
end
---@return map_rhs
function rhs_options:with_silent()
self.options.silent = true
return self
end
---@param description_string string
---@return map_rhs
function rhs_options:with_desc(description_string)
self.options.desc = description_string
return self
end
---@return map_rhs
function rhs_options:with_noremap()
self.options.noremap = true
return self
end
---@return map_rhs
function rhs_options:with_expr()
self.options.expr = true
return self
end
---@return map_rhs
function rhs_options:with_nowait()
self.options.nowait = true
return self
end
---@param num number
---@return map_rhs
function rhs_options:with_buffer(num)
self.buffer = num
return self
end
local bind = {}
---@param cmd_string string
---@return map_rhs
function bind.map_cr(cmd_string)
local ro = rhs_options:new()
return ro:map_cr(cmd_string)
end
---@param cmd_string string
---@return map_rhs
function bind.map_cmd(cmd_string)
local ro = rhs_options:new()
return ro:map_cmd(cmd_string)
end
---@param cmd_string string
---@return map_rhs
function bind.map_cu(cmd_string)
local ro = rhs_options:new()
return ro:map_cu(cmd_string)
end
---@param cmd_string string
---@return map_rhs
function bind.map_args(cmd_string)
local ro = rhs_options:new()
return ro:map_args(cmd_string)
end
---@param callback fun():nil
---@return map_rhs
function bind.map_callback(callback)
local ro = rhs_options:new()
return ro:map_callback(callback)
end
---@param cmd_string string
---@return string escaped_string
function bind.escape_termcode(cmd_string)
return vim.api.nvim_replace_termcodes(cmd_string, true, true, true)
end
---@param mapping table<string, map_rhs>
function bind.nvim_load_mapping(mapping)
for key, value in pairs(mapping) do
local modes, keymap = key:match("([^|]*)|?(.*)")
if type(value) == "table" then
for _, mode in ipairs(vim.split(modes, "")) do
local rhs = value.cmd
local options = value.options
local buf = value.buffer
if buf and type(buf) == "number" then
vim.api.nvim_buf_set_keymap(buf, mode, keymap, rhs, options)
else
vim.api.nvim_set_keymap(mode, keymap, rhs, options)
end
end
end
end
end
return bind
+74
View File
@@ -0,0 +1,74 @@
local bind = require("keymap.bind")
local map_cr = bind.map_cr
local map_cmd = bind.map_cmd
local map_callback = bind.map_callback
local plug_map = {
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("formatter: Toggle format on save"),
}
bind.nvim_load_mapping(plug_map)
local mapping = {}
function mapping.lsp(buf)
local map = {
-- LSP-related keymaps, ONLY effective in buffers with LSP(s) attached
["n|<leader>li"] = map_cr("LspInfo"):with_silent():with_buffer(buf):with_desc("lsp: Info"),
["n|<leader>lr"] = map_cr("LspRestart"):with_silent():with_buffer(buf):with_nowait():with_desc("lsp: Restart"),
["n|go"] = map_cr("AerialToggle!"):with_silent():with_buffer(buf):with_desc("lsp: Toggle outline"),
["n|gto"] = map_callback(function()
require("telescope").extensions.aerial.aerial()
end)
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Toggle outline in Telescope"),
["n|g["] = map_cr("Lspsaga diagnostic_jump_prev")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Prev diagnostic"),
["n|g]"] = map_cr("Lspsaga diagnostic_jump_next")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Next diagnostic"),
["n|<leader>lx"] = map_cr("Lspsaga show_line_diagnostics ++unfocus")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Line diagnostic"),
["n|gs"] = map_callback(function()
vim.lsp.buf.signature_help()
end):with_desc("lsp: Signature help"),
["n|gr"] = map_cr("Lspsaga rename"):with_silent():with_buffer(buf):with_desc("lsp: Rename in file range"),
["n|gR"] = map_cr("Lspsaga rename ++project")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Rename in project range"),
["n|K"] = map_cr("Lspsaga hover_doc"):with_silent():with_buffer(buf):with_desc("lsp: Show doc"),
["nv|ga"] = map_cr("Lspsaga code_action")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Code action for cursor"),
["n|gd"] = map_cr("Glance definitions"):with_silent():with_buffer(buf):with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_silent():with_buffer(buf):with_desc("lsp: Goto definition"),
["n|gh"] = map_cr("Glance references"):with_silent():with_buffer(buf):with_desc("lsp: Show reference"),
["n|gm"] = map_cr("Glance implementations")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show implementation"),
["n|gci"] = map_cr("Lspsaga incoming_calls")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show incoming calls"),
["n|gco"] = map_cr("Lspsaga outgoing_calls")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show outgoing calls"),
}
bind.nvim_load_mapping(map)
local ok, user_mappings = pcall(require, "user.keymap.completion")
if ok and type(user_mappings.lsp) == "function" then
require("modules.utils.keymap").replace(user_mappings.lsp(buf))
end
end
return mapping
+109
View File
@@ -0,0 +1,109 @@
local bind = require("keymap.bind")
local map_cr = bind.map_cr
local map_cu = bind.map_cu
local map_cmd = bind.map_cmd
local map_callback = bind.map_callback
local et = bind.escape_termcode
local plug_map = {
-- Plugin persisted.nvim
["n|<leader>ss"] = map_cu("SessionSave"):with_noremap():with_silent():with_desc("session: Save"),
["n|<leader>sl"] = map_cu("SessionLoad"):with_noremap():with_silent():with_desc("session: Load current"),
["n|<leader>sd"] = map_cu("SessionDelete"):with_noremap():with_silent():with_desc("session: Delete"),
-- Plugin: nvim-bufdel
["n|<A-q>"] = map_cr("BufDel"):with_noremap():with_silent():with_desc("buffer: Close current"),
-- Plugin: comment.nvim
["n|gcc"] = map_callback(function()
return vim.v.count == 0 and et("<Plug>(comment_toggle_linewise_current)")
or et("<Plug>(comment_toggle_linewise_count)")
end)
:with_silent()
:with_noremap()
:with_expr()
:with_desc("edit: Toggle comment for line"),
["n|gbc"] = map_callback(function()
return vim.v.count == 0 and et("<Plug>(comment_toggle_blockwise_current)")
or et("<Plug>(comment_toggle_blockwise_count)")
end)
:with_silent()
:with_noremap()
:with_expr()
:with_desc("edit: Toggle comment for block"),
["n|gc"] = map_cmd("<Plug>(comment_toggle_linewise)")
:with_silent()
:with_noremap()
:with_desc("edit: Toggle comment for line with operator"),
["n|gb"] = map_cmd("<Plug>(comment_toggle_blockwise)")
:with_silent()
:with_noremap()
:with_desc("edit: Toggle comment for block with operator"),
["x|gc"] = map_cmd("<Plug>(comment_toggle_linewise_visual)")
:with_silent()
:with_noremap()
:with_desc("edit: Toggle comment for line with selection"),
["x|gb"] = map_cmd("<Plug>(comment_toggle_blockwise_visual)")
:with_silent()
:with_noremap()
:with_desc("edit: Toggle comment for block with selection"),
-- Plugin: diffview.nvim
["n|<leader>gd"] = map_cr("DiffviewOpen"):with_silent():with_noremap():with_desc("git: Show diff"),
["n|<leader>gD"] = map_cr("DiffviewClose"):with_silent():with_noremap():with_desc("git: Close diff"),
-- Plugin: hop.nvim
["nv|<leader>w"] = map_cmd("<Cmd>HopWordMW<CR>"):with_noremap():with_desc("jump: Goto word"),
["nv|<leader>j"] = map_cmd("<Cmd>HopLineMW<CR>"):with_noremap():with_desc("jump: Goto line"),
["nv|<leader>k"] = map_cmd("<Cmd>HopLineMW<CR>"):with_noremap():with_desc("jump: Goto line"),
["nv|<leader>c"] = map_cmd("<Cmd>HopChar1MW<CR>"):with_noremap():with_desc("jump: Goto one char"),
["nv|<leader>C"] = map_cmd("<Cmd>HopChar2MW<CR>"):with_noremap():with_desc("jump: Goto two chars"),
-- Plugin: smart-splits.nvim
["n|<A-h>"] = map_cu("SmartResizeLeft"):with_silent():with_noremap():with_desc("window: Resize -3 horizontally"),
["n|<A-j>"] = map_cu("SmartResizeDown"):with_silent():with_noremap():with_desc("window: Resize -3 vertically"),
["n|<A-k>"] = map_cu("SmartResizeUp"):with_silent():with_noremap():with_desc("window: Resize +3 vertically"),
["n|<A-l>"] = map_cu("SmartResizeRight"):with_silent():with_noremap():with_desc("window: Resize +3 horizontally"),
["n|<C-h>"] = map_cu("SmartCursorMoveLeft"):with_silent():with_noremap():with_desc("window: Focus left"),
["n|<C-j>"] = map_cu("SmartCursorMoveDown"):with_silent():with_noremap():with_desc("window: Focus down"),
["n|<C-k>"] = map_cu("SmartCursorMoveUp"):with_silent():with_noremap():with_desc("window: Focus up"),
["n|<C-l>"] = map_cu("SmartCursorMoveRight"):with_silent():with_noremap():with_desc("window: Focus right"),
["n|<leader>Wh"] = map_cu("SmartSwapLeft"):with_silent():with_noremap():with_desc("window: Move window leftward"),
["n|<leader>Wj"] = map_cu("SmartSwapDown"):with_silent():with_noremap():with_desc("window: Move window downward"),
["n|<leader>Wk"] = map_cu("SmartSwapUp"):with_silent():with_noremap():with_desc("window: Move window upward"),
["n|<leader>Wl"] = map_cu("SmartSwapRight"):with_silent():with_noremap():with_desc("window: Move window rightward"),
-- Plugin: nvim-spectre
["n|<leader>Ss"] = map_callback(function()
require("spectre").toggle()
end)
:with_silent()
:with_noremap()
:with_desc("editn: Toggle search & replace panel"),
["n|<leader>Sp"] = map_callback(function()
require("spectre").open_visual({ select_word = true })
end)
:with_silent()
:with_noremap()
:with_desc("editn: search&replace current word (project)"),
["v|<leader>Sp"] = map_callback(function()
require("spectre").open_visual()
end)
:with_silent()
:with_noremap()
:with_desc("edit: search & replace current word (project)"),
["n|<leader>Sf"] = map_callback(function()
require("spectre").open_file_search({ select_word = true })
end)
:with_silent()
:with_noremap()
:with_desc("editn: search & replace current word (file)"),
-- Plugin: nvim-treehopper
["o|m"] = map_cu("lua require('tsht').nodes()"):with_silent():with_desc("jump: Operate across syntax tree"),
-- Plugin suda.vim
["n|<A-s>"] = map_cu("SudaWrite"):with_silent():with_noremap():with_desc("editn: Save file using sudo"),
}
bind.nvim_load_mapping(plug_map)
+67
View File
@@ -0,0 +1,67 @@
_G._command_panel = function()
require("telescope.builtin").keymaps({
lhs_filter = function(lhs)
return not string.find(lhs, "Þ")
end,
layout_config = {
width = 0.6,
height = 0.6,
prompt_position = "top",
},
})
end
_G._telescope_collections = function(picker_type)
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local conf = require("telescope.config").values
local finder = require("telescope.finders")
local pickers = require("telescope.pickers")
picker_type = picker_type or {}
local collections = vim.tbl_keys(require("search.tabs").collections)
pickers
.new(picker_type, {
prompt_title = "Telescope Collections",
finder = finder.new_table({ results = collections }),
sorter = conf.generic_sorter(picker_type),
attach_mappings = function(bufnr)
actions.select_default:replace(function()
actions.close(bufnr)
local selection = action_state.get_selected_entry()
require("search").open({ collection = selection[1] })
end)
return true
end,
})
:find()
end
_G._flash_esc_or_noh = function()
local flash_active, state = pcall(function()
return require("flash.plugins.char").state
end)
if flash_active and state then
state:hide()
else
pcall(vim.cmd.noh)
end
end
local _lazygit = nil
_G._toggle_lazygit = function()
if vim.fn.executable("lazygit") == 1 then
if not _lazygit then
_lazygit = require("toggleterm.terminal").Terminal:new({
cmd = "lazygit",
direction = "float",
close_on_exit = true,
hidden = true,
})
end
_lazygit:toggle()
else
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
end
end
+35
View File
@@ -0,0 +1,35 @@
require("keymap.helpers")
local bind = require("keymap.bind")
local map_cr = bind.map_cr
-- local map_cu = bind.map_cu
-- local map_cmd = bind.map_cmd
-- local map_callback = bind.map_callback
local plug_map = {
-- Package manager: lazy.nvim
["n|<leader>ph"] = map_cr("Lazy"):with_silent():with_noremap():with_nowait():with_desc("package: Show"),
["n|<leader>ps"] = map_cr("Lazy sync"):with_silent():with_noremap():with_nowait():with_desc("package: Sync"),
["n|<leader>pu"] = map_cr("Lazy update"):with_silent():with_noremap():with_nowait():with_desc("package: Update"),
["n|<leader>pi"] = map_cr("Lazy install"):with_silent():with_noremap():with_nowait():with_desc("package: Install"),
["n|<leader>pl"] = map_cr("Lazy log"):with_silent():with_noremap():with_nowait():with_desc("package: Log"),
["n|<leader>pc"] = map_cr("Lazy check"):with_silent():with_noremap():with_nowait():with_desc("package: Check"),
["n|<leader>pd"] = map_cr("Lazy debug"):with_silent():with_noremap():with_nowait():with_desc("package: Debug"),
["n|<leader>pp"] = map_cr("Lazy profile"):with_silent():with_noremap():with_nowait():with_desc("package: Profile"),
["n|<leader>pr"] = map_cr("Lazy restore"):with_silent():with_noremap():with_nowait():with_desc("package: Restore"),
["n|<leader>px"] = map_cr("Lazy clean"):with_silent():with_noremap():with_nowait():with_desc("package: Clean"),
}
bind.nvim_load_mapping(plug_map)
-- Plugin keymaps
require("keymap.completion")
require("keymap.editor")
require("keymap.lang")
require("keymap.tool")
require("keymap.ui")
-- User keymaps
local ok, mappings = pcall(require, "user.keymap.init")
if ok then
require("modules.utils.keymap").replace(mappings)
end
+12
View File
@@ -0,0 +1,12 @@
local bind = require("keymap.bind")
local map_cr = bind.map_cr
-- local map_cu = bind.map_cu
-- local map_cmd = bind.map_cmd
-- local map_callback = bind.map_callback
local plug_map = {
-- Plugin MarkdownPreview
["n|<F12>"] = map_cr("MarkdownPreviewToggle"):with_noremap():with_silent():with_desc("tool: Preview markdown"),
}
bind.nvim_load_mapping(plug_map)
+191
View File
@@ -0,0 +1,191 @@
local bind = require("keymap.bind")
local map_cr = bind.map_cr
local map_cu = bind.map_cu
local map_cmd = bind.map_cmd
local map_callback = bind.map_callback
require("keymap.helpers")
local plug_map = {
-- Plugin: vim-fugitive
["n|gps"] = map_cr("G push"):with_noremap():with_silent():with_desc("git: Push"),
["n|gpl"] = map_cr("G pull"):with_noremap():with_silent():with_desc("git: Pull"),
["n|<leader>gG"] = map_cu("Git"):with_noremap():with_silent():with_desc("git: Open git-fugitive"),
-- Plugin: nvim-tree
["n|<C-n>"] = map_cr("NvimTreeToggle"):with_noremap():with_silent():with_desc("filetree: Toggle"),
["n|<leader>nf"] = map_cr("NvimTreeFindFile"):with_noremap():with_silent():with_desc("filetree: Find file"),
["n|<leader>nr"] = map_cr("NvimTreeRefresh"):with_noremap():with_silent():with_desc("filetree: Refresh"),
-- Plugin: sniprun
["v|<leader>r"] = map_cr("SnipRun"):with_noremap():with_silent():with_desc("tool: Run code by range"),
["n|<leader>r"] = map_cu([[%SnipRun]]):with_noremap():with_silent():with_desc("tool: Run code by file"),
-- Plugin: toggleterm
["t|<Esc><Esc>"] = map_cmd([[<C-\><C-n>]]):with_noremap():with_silent(), -- switch to normal mode in terminal.
["n|<C-\\>"] = map_cr("ToggleTerm direction=horizontal")
:with_noremap()
:with_silent()
:with_desc("terminal: Toggle horizontal"),
["i|<C-\\>"] = map_cmd("<Esc><Cmd>ToggleTerm direction=horizontal<CR>")
:with_noremap()
:with_silent()
:with_desc("terminal: Toggle horizontal"),
["t|<C-\\>"] = map_cmd("<Cmd>ToggleTerm<CR>"):with_noremap():with_silent():with_desc("terminal: Toggle horizontal"),
["n|<A-\\>"] = map_cr("ToggleTerm direction=vertical")
:with_noremap()
:with_silent()
:with_desc("terminal: Toggle vertical"),
["i|<A-\\>"] = map_cmd("<Esc><Cmd>ToggleTerm direction=vertical<CR>")
:with_noremap()
:with_silent()
:with_desc("terminal: Toggle vertical"),
["t|<A-\\>"] = map_cmd("<Cmd>ToggleTerm<CR>"):with_noremap():with_silent():with_desc("terminal: Toggle vertical"),
["n|<F5>"] = map_cr("ToggleTerm direction=vertical")
:with_noremap()
:with_silent()
:with_desc("terminal: Toggle vertical"),
["i|<F5>"] = map_cmd("<Esc><Cmd>ToggleTerm direction=vertical<CR>")
:with_noremap()
:with_silent()
:with_desc("terminal: Toggle vertical"),
["t|<F5>"] = map_cmd("<Cmd>ToggleTerm<CR>"):with_noremap():with_silent():with_desc("terminal: Toggle vertical"),
["n|<A-d>"] = map_cr("ToggleTerm direction=float"):with_noremap():with_silent():with_desc("terminal: Toggle float"),
["i|<A-d>"] = map_cmd("<Esc><Cmd>ToggleTerm direction=float<CR>")
:with_noremap()
:with_silent()
:with_desc("terminal: Toggle float"),
["t|<A-d>"] = map_cmd("<Cmd>ToggleTerm<CR>"):with_noremap():with_silent():with_desc("terminal: Toggle float"),
["n|<leader>gg"] = map_callback(function()
_toggle_lazygit()
end)
:with_noremap()
:with_silent()
:with_desc("git: Toggle lazygit"),
-- Plugin: trouble
["n|gt"] = map_cr("Trouble diagnostics toggle"):with_noremap():with_silent():with_desc("lsp: Toggle trouble list"),
["n|<leader>lw"] = map_cr("Trouble diagnostics toggle")
:with_noremap()
:with_silent()
:with_desc("lsp: Show workspace diagnostics"),
["n|<leader>lp"] = map_cr("Trouble project_diagnostics toggle")
:with_noremap()
:with_silent()
:with_desc("lsp: Show project diagnostics"),
["n|<leader>ld"] = map_cr("Trouble diagnostics toggle filter.buf=0")
:with_noremap()
:with_silent()
:with_desc("lsp: Show document diagnostics"),
-- Plugin: telescope
["n|<C-p>"] = map_callback(function()
_command_panel()
end)
:with_noremap()
:with_silent()
:with_desc("tool: Toggle command panel"),
["n|<leader>fc"] = map_callback(function()
_telescope_collections(require("telescope.themes").get_dropdown())
end)
:with_noremap()
:with_silent()
:with_desc("tool: Open Telescope collections"),
["n|<leader>ff"] = map_callback(function()
require("search").open({ collection = "file" })
end)
:with_noremap()
:with_silent()
:with_desc("tool: Find files"),
["n|<leader>fp"] = map_callback(function()
require("search").open({ collection = "pattern" })
end)
:with_noremap()
:with_silent()
:with_desc("tool: Find patterns"),
["v|<leader>fs"] = map_cu("Telescope grep_string")
:with_noremap()
:with_silent()
:with_desc("tool: Find word under cursor"),
["n|<leader>fg"] = map_callback(function()
require("search").open({ collection = "git" })
end)
:with_noremap()
:with_silent()
:with_desc("tool: Locate Git objects"),
["n|<leader>fd"] = map_callback(function()
require("search").open({ collection = "dossier" })
end)
:with_noremap()
:with_silent()
:with_desc("tool: Retrieve dossiers"),
["n|<leader>fm"] = map_callback(function()
require("search").open({ collection = "misc" })
end)
:with_noremap()
:with_silent()
:with_desc("tool: Miscellaneous"),
-- Plugin: dap
["n|<F6>"] = map_callback(function()
require("dap").continue()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Run/Continue"),
["n|<F7>"] = map_callback(function()
require("dap").terminate()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Stop"),
["n|<F8>"] = map_callback(function()
require("dap").toggle_breakpoint()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Toggle breakpoint"),
["n|<F9>"] = map_callback(function()
require("dap").step_into()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Step into"),
["n|<F10>"] = map_callback(function()
require("dap").step_out()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Step out"),
["n|<F11>"] = map_callback(function()
require("dap").step_over()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Step over"),
["n|<leader>db"] = map_callback(function()
require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))
end)
:with_noremap()
:with_silent()
:with_desc("debug: Set breakpoint with condition"),
["n|<leader>dc"] = map_callback(function()
require("dap").run_to_cursor()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Run to cursor"),
["n|<leader>dl"] = map_callback(function()
require("dap").run_last()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Run last"),
["n|<leader>do"] = map_callback(function()
require("dap").repl.open()
end)
:with_noremap()
:with_silent()
:with_desc("debug: Open REPL"),
}
bind.nvim_load_mapping(plug_map)
+105
View File
@@ -0,0 +1,105 @@
local bind = require("keymap.bind")
local map_cr = bind.map_cr
-- local map_cu = bind.map_cu
-- local map_cmd = bind.map_cmd
-- local map_callback = bind.map_callback
local plug_map = {
-- Plugin: bufferline.nvim
["n|<A-i>"] = map_cr("BufferLineCycleNext"):with_noremap():with_silent():with_desc("buffer: Switch to next"),
["n|<A-o>"] = map_cr("BufferLineCyclePrev"):with_noremap():with_silent():with_desc("buffer: Switch to prev"),
["n|<A-S-i>"] = map_cr("BufferLineMoveNext"):with_noremap():with_silent():with_desc("buffer: Move current to next"),
["n|<A-S-o>"] = map_cr("BufferLineMovePrev"):with_noremap():with_silent():with_desc("buffer: Move current to prev"),
["n|<leader>be"] = map_cr("BufferLineSortByExtension"):with_noremap():with_desc("buffer: Sort by extension"),
["n|<leader>bd"] = map_cr("BufferLineSortByDirectory"):with_noremap():with_desc("buffer: Sort by directory"),
["n|<A-1>"] = map_cr("BufferLineGoToBuffer 1"):with_noremap():with_silent():with_desc("buffer: Goto buffer 1"),
["n|<A-2>"] = map_cr("BufferLineGoToBuffer 2"):with_noremap():with_silent():with_desc("buffer: Goto buffer 2"),
["n|<A-3>"] = map_cr("BufferLineGoToBuffer 3"):with_noremap():with_silent():with_desc("buffer: Goto buffer 3"),
["n|<A-4>"] = map_cr("BufferLineGoToBuffer 4"):with_noremap():with_silent():with_desc("buffer: Goto buffer 4"),
["n|<A-5>"] = map_cr("BufferLineGoToBuffer 5"):with_noremap():with_silent():with_desc("buffer: Goto buffer 5"),
["n|<A-6>"] = map_cr("BufferLineGoToBuffer 6"):with_noremap():with_silent():with_desc("buffer: Goto buffer 6"),
["n|<A-7>"] = map_cr("BufferLineGoToBuffer 7"):with_noremap():with_silent():with_desc("buffer: Goto buffer 7"),
["n|<A-8>"] = map_cr("BufferLineGoToBuffer 8"):with_noremap():with_silent():with_desc("buffer: Goto buffer 8"),
["n|<A-9>"] = map_cr("BufferLineGoToBuffer 9"):with_noremap():with_silent():with_desc("buffer: Goto buffer 9"),
}
bind.nvim_load_mapping(plug_map)
local mapping = {}
function mapping.gitsigns(buf)
local actions = require("gitsigns.actions")
local map = {
["n|]g"] = bind.map_callback(function()
if vim.wo.diff then
return "]g"
end
vim.schedule(function()
actions.next_hunk()
end)
return "<Ignore>"
end)
:with_buffer(buf)
:with_expr()
:with_desc("git: Goto next hunk"),
["n|[g"] = bind.map_callback(function()
if vim.wo.diff then
return "[g"
end
vim.schedule(function()
actions.prev_hunk()
end)
return "<Ignore>"
end)
:with_buffer(buf)
:with_expr()
:with_desc("git: Goto prev hunk"),
["n|<leader>gs"] = bind.map_callback(function()
actions.stage_hunk()
end)
:with_buffer(buf)
:with_desc("git: Stage hunk"),
["v|<leader>gs"] = bind.map_callback(function()
actions.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
:with_buffer(buf)
:with_desc("git: Stage hunk"),
["n|<leader>gu"] = bind.map_callback(function()
actions.undo_stage_hunk()
end)
:with_buffer(buf)
:with_desc("git: Undo stage hunk"),
["n|<leader>gr"] = bind.map_callback(function()
actions.reset_hunk()
end)
:with_buffer(buf)
:with_desc("git: Reset hunk"),
["v|<leader>gr"] = bind.map_callback(function()
actions.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
:with_buffer(buf)
:with_desc("git: Reset hunk"),
["n|<leader>gR"] = bind.map_callback(function()
actions.reset_buffer()
end)
:with_buffer(buf)
:with_desc("git: Reset buffer"),
["n|<leader>gp"] = bind.map_callback(function()
actions.preview_hunk()
end)
:with_buffer(buf)
:with_desc("git: Preview hunk"),
["n|<leader>gb"] = bind.map_callback(function()
actions.blame_line({ full = true })
end)
:with_buffer(buf)
:with_desc("git: Blame line"),
-- Text objects
["ox|ih"] = bind.map_callback(function()
actions.text_object()
end):with_buffer(buf),
}
bind.nvim_load_mapping(map)
end
return mapping