feat: add which-key to manage keybindings

This commit is contained in:
Nydragon 2024-05-03 15:26:56 +09:00
parent 3c46257653
commit 4f8db4d933
5 changed files with 103 additions and 36 deletions

View file

@ -13,3 +13,7 @@ Toggles the comment state of the selected line(s) individually | [count]<leader>
## cheatsheet @custom: ## cheatsheet @custom:
Shows a searchable list of all keybindings | <leader>? Shows a searchable list of all keybindings | <leader>?
## Term @custom
Opens a normal interactive terminal | <c-c>
Opens lazygit | <leader>g

View file

@ -71,4 +71,5 @@ autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false })
-- Enable filetype plugins -- Enable filetype plugins
vim.cmd("filetype plugin on") vim.cmd("filetype plugin on")
vim.g.mapleader = ","
require("plugins") require("plugins")

View file

@ -37,14 +37,24 @@ require("lazy").setup({
require("barbar-config") require("barbar-config")
end, end,
}, },
"nvim-treesitter/nvim-treesitter", { "nvim-treesitter/nvim-treesitter", enabled = false },
{ {
"neovim/nvim-lspconfig", -- Configurations for Nvim LSP "neovim/nvim-lspconfig", -- Configurations for Nvim LSP
init = function() init = function()
require("nvim-lsp-config") require("nvim-lsp-config")
end, end,
}, },
{
"simrat39/rust-tools.nvim", "simrat39/rust-tools.nvim",
opts = {
on_attach = function(_, bufnr)
-- Hover actions
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
-- Code action groups
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
end,
},
},
"preservim/nerdcommenter", -- (batch)commenting tool "preservim/nerdcommenter", -- (batch)commenting tool
{ {
"m4xshen/autoclose.nvim", "m4xshen/autoclose.nvim",
@ -53,9 +63,6 @@ require("lazy").setup({
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",
{ {
"EdenEast/nightfox.nvim", -- themeing "EdenEast/nightfox.nvim", -- themeing
init = function()
vim.cmd("colorscheme carbonfox")
end,
opts = { opts = {
options = { options = {
styles = { styles = {
@ -66,21 +73,14 @@ require("lazy").setup({
}, },
}, },
}, },
{
"catppuccin/nvim",
name = "catppuccin",
priority = 1000,
},
"lukas-reineke/virt-column.nvim", -- thin bar indicating an arbitray character limit "lukas-reineke/virt-column.nvim", -- thin bar indicating an arbitray character limit
{ {
"nvim-telescope/telescope.nvim", -- fuzzy file finder "nvim-telescope/telescope.nvim", -- fuzzy file finder
opts = {
pickers = {
find_files = {
-- `hidden = true` will still show the inside of `.git/` as it's not `.gitignore`d.
-- find_command = { "rg", "--files", "--hidden", "--no-ignore", "--glob", "!**/.git/*" },
-- find_command = { "fd" },
},
},
},
init = function()
require("telescope-config")
end,
}, },
{ {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
@ -100,8 +100,10 @@ require("lazy").setup({
}, },
{ {
"mhartington/formatter.nvim", "mhartington/formatter.nvim",
--opts = require("formatter-config").build(),
config = function() config = function()
opts = require("formatter-config").build() opts = require("formatter-config").build()
require("formatter").setup(opts) require("formatter").setup(opts)
end, end,
}, },
@ -113,6 +115,40 @@ require("lazy").setup({
"nvim-lua/plenary.nvim", "nvim-lua/plenary.nvim",
}, },
}, },
{
"akinsho/toggleterm.nvim",
version = "*",
opts = {
direction = "float",
},
config = function(_, opts)
local Terminal = require("toggleterm.terminal").Terminal
local lazygit = Terminal:new({ cmd = "lazygit", hidden = true, direction = "float" })
function _lazygit_toggle()
lazygit:toggle()
end
require("toggleterm").setup(opts)
end,
},
{
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 300
end,
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
config = function(_, opts)
require("which-key-config")
require("which-key").setup(opts)
end,
},
}) })
local augroup = vim.api.nvim_create_augroup local augroup = vim.api.nvim_create_augroup
@ -123,19 +159,6 @@ autocmd("BufWritePost", {
command = ":FormatWrite", command = ":FormatWrite",
}) })
local rt = require("rust-tools")
rt.setup({
server = {
on_attach = function(_, bufnr)
-- Hover actions
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
-- Code action groups
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
end,
},
})
-- LSP Diagnostics Options Setup -- LSP Diagnostics Options Setup
local sign = function(opts) local sign = function(opts)
vim.fn.sign_define(opts.name, { vim.fn.sign_define(opts.name, {
@ -163,3 +186,11 @@ vim.cmd([[
set signcolumn=yes set signcolumn=yes
autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false })
]]) ]])
vim.cmd("colorscheme catppuccin")
--vim.api.nvim_create_autocmd({ "VimLeave" }, {
--callback = function()
--vim.cmd("close")
--end,
--})

View file

@ -1,6 +0,0 @@
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set("n", "<leader>fh", builtin.help_tags, {})

View file

@ -0,0 +1,37 @@
local wk = require("which-key")
wk.register({
f = {
"Telescope - Finder",
f = {
"<cmd>Telescope find_files<cr>",
"Find File",
},
g = {
"<cmd>Telescope live_grep<cr>",
"Live Grep",
},
b = {
"<cmd>Telescope buffers<cr>",
"Find Open Buffers",
},
h = {
"<cmd>Telescope help_tags<cr>",
"Find Help",
},
},
n = {
"Terminal",
b = {
"<cmd>lua _lazygit_toggle()<CR>",
"Open Lazygit",
},
j = {
"<cmd>ToggleTerm<cr>",
"Open Terminal",
},
},
c = {
"NerdCommenter",
},
}, { prefix = "<leader>" })