Skip to content

Commit

Permalink
feat(keymaps): use lazy keys to manage plugins keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
liubang committed Jan 16, 2023
1 parent cd64fc6 commit c8879b5
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 187 deletions.
93 changes: 1 addition & 92 deletions lua/lb/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
--
-- =====================================================================

-- termcodes helper function {{{
local function termcodes(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
-- }}}

-- stylua: ignore start

-- clear default {{{
Expand All @@ -33,16 +27,11 @@ vim.keymap.set("n", "<S-k>", [[:<c-u>execute 'm -1-'. v:count1<cr>==]], { silent
vim.keymap.set("x", "<S-j>", [[:m '>+1<CR><CR>gv=gv]], { silent = true, desc = "move lines down" })
vim.keymap.set("x", "<S-k>", [[:m '<-2<CR><CR>gv=gv]], { silent = true, desc = "move lines up" })

-- vim.keymap.set("n", "G", "Gzz", { desc = "auto re-centre when moving around" })
-- vim.keymap.set("n", "g;", "m'g;zz", { desc = "auto re-centre when moving around" })
-- vim.keymap.set("n", "g,", "m'g,zz", { desc = "auto re-centre when moving around" })

vim.keymap.set("n", "<Esc><Esc>", ":noh<CR>", { silent = true, desc = "clear hlsearch" })
vim.keymap.set("x", "/", "<Esc>/\\%V", { desc = "Search in visually selected region" })

vim.keymap.set("x", "<", "<gv", { desc = "keep the visually selected area when indenting" })
vim.keymap.set("x", ">", ">gv", { desc = "keep the visually selected area when indenting" })
-- vim.keymap.set("n", "<Leader>hh", ":h <CR>", { desc = "show help for work under the cursor" })
-- }}}

-- Yank related {{{
Expand Down Expand Up @@ -79,90 +68,10 @@ vim.keymap.set('n', '<Leader>wk', '<C-W>k')
vim.keymap.set('n', '<Leader>w=', '<C-W>=')
vim.keymap.set('n', '<Leader>ws', '<C-W>s')
vim.keymap.set('n', '<Leader>wv', '<C-W>v')
vim.keymap.set('n', '<C-S-Up>', function() require('smart-splits').resize_up() end)
vim.keymap.set('n', '<C-S-Down>', function() require('smart-splits').resize_down() end)
vim.keymap.set('n', '<C-S-Left>', function() require('smart-splits').resize_left() end)
vim.keymap.set('n', '<C-S-Right>', function() require('smart-splits').resize_right() end)
-- }}}

-- terminal {{{
vim.keymap.set('t', '<Esc>', termcodes '<C-\\><C-N>')
-- }}}

-- buffer delete {{{
vim.keymap.set('n', '<Leader>bd', '<cmd>Bwipeout<CR>')
-- }}}

-- neotree {{{
-- vim.keymap.set(
-- 'n',
-- '<Leader>ft',
-- '<cmd>Neotree action=focus source=filesystem position=left toggle=true reveal=true<CR>'
-- )
-- }}}

-- undo tree {{{
vim.keymap.set("n", "<leader>u", "<cmd>UndotreeToggle<CR>")
-- }}}

-- nvim-tree {{{
vim.keymap.set('n', '<Leader>ft', ":NvimTreeToggle<CR>", { silent = true, desc = 'toggle tree view' })
-- }}}

-- floaterm {{{
vim.keymap.set('n', '<Leader>tw', '<cmd>FloatermNew<CR>')
vim.keymap.set('n', '<C-t>', '<cmd>FloatermToggle<CR>')
vim.keymap.set('t', '<C-n>', termcodes '<C-\\><C-N>:FloatermNew<CR>')
vim.keymap.set('t', '<C-k>', termcodes '<C-\\><C-N>:FloatermPrev<CR>')
vim.keymap.set('t', '<C-j>', termcodes '<C-\\><C-N>:FloatermNext<CR>')
vim.keymap.set('t', '<C-t>', termcodes '<C-\\><C-N>:FloatermToggle<CR>')
vim.keymap.set('t', '<C-d>', termcodes '<C-\\><C-N>:FloatermKill<CR>')
-- }}}

-- asynctask {{{
vim.keymap.set('n', '<C-b>', '<cmd>AsyncTask file-build<CR>')
vim.keymap.set('n', '<C-r>', '<cmd>AsyncTask file-run<CR>')
vim.keymap.set('n', '<C-x>', '<cmd>AsyncTask file-build-run<CR>')
-- }}}

-- aerial {{{
vim.keymap.set('n', '<Leader>tl', '<cmd>AerialToggle<CR>')
-- }}}

-- bufferline {{{
vim.keymap.set('n', '<Leader>1', '<cmd>BufferLineGoToBuffer 1<CR>')
vim.keymap.set('n', '<Leader>2', '<cmd>BufferLineGoToBuffer 2<CR>')
vim.keymap.set('n', '<Leader>3', '<cmd>BufferLineGoToBuffer 3<CR>')
vim.keymap.set('n', '<Leader>4', '<cmd>BufferLineGoToBuffer 4<CR>')
vim.keymap.set('n', '<Leader>5', '<cmd>BufferLineGoToBuffer 5<CR>')
vim.keymap.set('n', '<Leader>6', '<cmd>BufferLineGoToBuffer 6<CR>')
vim.keymap.set('n', '<Leader>7', '<cmd>BufferLineGoToBuffer 7<CR>')
vim.keymap.set('n', '<Leader>8', '<cmd>BufferLineGoToBuffer 8<CR>')
vim.keymap.set('n', '<Leader>9', '<cmd>BufferLineGoToBuffer 9<CR>')
-- }}}

-- git {{{
vim.keymap.set('n', '<Leader>hb', function() require('gitsigns').blame_line {full = true} end)
vim.keymap.set('n', '<Leader>hd', function() require('gitsigns').diffthis() end)
vim.keymap.set('n', '<Leader>hr', function() require('gitsigns').reset_hunk() end)
vim.keymap.set('n', '<Leader>hs', function() require('gitsigns').stage_hunk() end)
-- }}}

-- markdown {{{
vim.keymap.set('n', '<Leader>mp', '<cmd>MarkdownPreview<CR>')
-- }}}

-- telescope {{{
vim.keymap.set('n', '<Leader>ff', "<cmd>Telescope find_files<CR>")
vim.keymap.set('n', '<Leader>rf', "<cmd>Telescope oldfiles<CR>")
vim.keymap.set('n', '<Leader>ag', "<cmd>Telescope live_grep<CR>")
vim.keymap.set('n', '<Leader>Ag', "<cmd>Telescope grep_string<CR>")
vim.keymap.set('n', '<Leader>bb', "<cmd>Telescope buffers<CR>")
vim.keymap.set('n', '<Leader>fc', "<cmd>Telescope command<CR>")
vim.keymap.set('n', '<Leader>ts', "<cmd>Telescope tasks<CR>")
vim.keymap.set('n', '<Leader>br', "<cmd>Telescope bazel bazel_run<CR>")
vim.keymap.set('n', '<Leader>bt', "<cmd>Telescope bazel bazel_tests<CR>")
vim.keymap.set('n', '<Leader>ts', "<cmd>Telescope tasks<CR>")
vim.keymap.set('t', '<Esc>', vim.api.nvim_replace_termcodes('<C-\\><C-N>', true, true, true))
-- }}}

-- stylua: ignore end
Expand Down
1 change: 1 addition & 0 deletions lua/plugins/aerial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ return {
["O"] = "actions.tree_toggle",
},
},
keys = { { "<Leader>tl", "<CMD>AerialToggle<CR>", mode = { "n" } } },
}

-- vim: fdm=marker fdl=0
6 changes: 2 additions & 4 deletions lua/plugins/alpha.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
return {
"goolord/alpha-nvim",
lazy = false,
config = function()
local alpha = require "alpha"
opts = function()
local h = {
[[ ███▄ █ ▓█████ ▒█████ ██▒ █▓ ██▓ ███▄ ▄███▓]],
[[ ██ ▀█ █ ▓█ ▀ ▒██▒ ██▒▓██░ █▒▓██▒▓██▒▀█▀ ██▒]],
Expand Down Expand Up @@ -129,7 +128,6 @@ return {
margin = 5,
},
}

alpha.setup(opts)
return opts
end,
}
5 changes: 5 additions & 0 deletions lua/plugins/asynctasks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ return {
vim.g.asyncrun_rootmarks = { ".svn", ".git", ".root", "build.xml" }
vim.g.asynctasks_term_pos = "floaterm"
end, -- }}}
keys = {
{ "<C-b>", "<CMD>AsyncTask file-build<CR>", mode = { "n" } },
{ "<C-r>", "<CMD>AsyncTask file-run<CR>", mode = { "n" } },
{ "<C-x>", "<CMD>AsyncTask file-build-run<CR>", mode = { "n" } },
},
}

-- vim: fdm=marker fdl=0
11 changes: 11 additions & 0 deletions lua/plugins/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ return {
sort_by = "insert_at_end",
}, -- }}}
},
keys = {
{ "<Leader>1", "<CMD>BufferLineGoToBuffer 1<CR>", mode = { "n" } },
{ "<Leader>2", "<CMD>BufferLineGoToBuffer 2<CR>", mode = { "n" } },
{ "<Leader>3", "<CMD>BufferLineGoToBuffer 3<CR>", mode = { "n" } },
{ "<Leader>4", "<CMD>BufferLineGoToBuffer 4<CR>", mode = { "n" } },
{ "<Leader>5", "<CMD>BufferLineGoToBuffer 5<CR>", mode = { "n" } },
{ "<Leader>6", "<CMD>BufferLineGoToBuffer 6<CR>", mode = { "n" } },
{ "<Leader>7", "<CMD>BufferLineGoToBuffer 7<CR>", mode = { "n" } },
{ "<Leader>8", "<CMD>BufferLineGoToBuffer 8<CR>", mode = { "n" } },
{ "<Leader>9", "<CMD>BufferLineGoToBuffer 9<CR>", mode = { "n" } },
},
}

-- vim: fdm=marker fdl=0
6 changes: 6 additions & 0 deletions lua/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ return {
enable = false,
},
},
keys = {
{ '<Leader>hb', function() require('gitsigns').blame_line { full = true } end, mode = { 'n' } },
{ '<Leader>hd', function() require('gitsigns').diffthis() end, mode = { 'n' } },
{ '<Leader>hr', function() require('gitsigns').reset_hunk() end, mode = { 'n' } },
{ '<Leader>hs', function() require('gitsigns').stage_hunk() end, mode = { 'n' } },
}
}

-- stylua: ignore end
Expand Down
8 changes: 7 additions & 1 deletion lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ return {
"onsails/lspkind.nvim",
"nvim-tree/nvim-web-devicons",
"williamboman/mason-lspconfig.nvim",
{ "famiu/bufdelete.nvim", event = "BufAdd" },
{
"famiu/bufdelete.nvim",
cmd = { "Bdelete", "Bwipeout" },
keys = {
{ "<Leader>bd", "<CMD>Bwipeout<CR>", mode = { "n" } },
},
},
{ "dstein64/vim-startuptime", cmd = "StartupTime" },
}

Expand Down
3 changes: 3 additions & 0 deletions lua/plugins/markdown-preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ return {
init = function()
vim.g.mkdp_filetypes = { "markdown" }
end,
keys = {
{ "<Leader>mp", "<CMD>MarkdownPreview<CR>", mode = { "n" } },
},
}

-- vim: fdm=marker fdl=0
Loading

0 comments on commit c8879b5

Please sign in to comment.