removed dupication and refactored my keymaps
This commit is contained in:
parent
116c91c155
commit
c5d1b0ac8f
|
@ -1,5 +1,5 @@
|
||||||
-- Set to true if you have a Nerd Font installed and selected in the terminal
|
-- Set to true if you have a Nerd Font installed and selected in the terminal
|
||||||
vim.g.have_nerd_font = false
|
vim.g.have_nerd_font = true
|
||||||
|
|
||||||
-- [[ Setting options ]]
|
-- [[ Setting options ]]
|
||||||
-- See `:help vim.opt`
|
-- See `:help vim.opt`
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
-- [plugins/editing.lua]
|
-- [plugins/editor.lua]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
|
-- -- Autoformat: `conform.nvim`
|
||||||
|
-- This plugin provides a non-LSP based way to format your code.
|
||||||
{ -- Autoformat
|
{
|
||||||
'stevearc/conform.nvim',
|
'stevearc/conform.nvim',
|
||||||
|
-- Only load this plugin right before a buffer is written.
|
||||||
event = { 'BufWritePre' },
|
event = { 'BufWritePre' },
|
||||||
|
-- Add the `ConformInfo` command for debugging.
|
||||||
cmd = { 'ConformInfo' },
|
cmd = { 'ConformInfo' },
|
||||||
|
-- Set up keybinds for manual formatting.
|
||||||
keys = {
|
keys = {
|
||||||
{
|
{
|
||||||
|
-- The leader key followed by 'f' to format the current buffer.
|
||||||
'<leader>f',
|
'<leader>f',
|
||||||
function()
|
function()
|
||||||
require('conform').format { async = true, lsp_format = 'fallback' }
|
require('conform').format { async = true, lsp_format = 'fallback' }
|
||||||
|
@ -19,20 +23,117 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts = {
|
opts = {
|
||||||
|
-- Disable notifications on formatting errors to avoid pop-ups.
|
||||||
notify_on_error = false,
|
notify_on_error = false,
|
||||||
|
-- This function runs before saving a file to check if it should be formatted.
|
||||||
format_on_save = function(bufnr)
|
format_on_save = function(bufnr)
|
||||||
|
-- A list of filetypes where auto-formatting on save is disabled.
|
||||||
local disable_filetypes = { c = true, cpp = true }
|
local disable_filetypes = { c = true, cpp = true }
|
||||||
|
|
||||||
|
-- Determine if LSP formatting should be used.
|
||||||
|
local lsp_format_opt
|
||||||
if disable_filetypes[vim.bo[bufnr].filetype] then
|
if disable_filetypes[vim.bo[bufnr].filetype] then
|
||||||
return
|
-- If the filetype is in the disabled list, don't use LSP formatting.
|
||||||
|
lsp_format_opt = 'never'
|
||||||
|
else
|
||||||
|
-- Otherwise, use LSP formatting as a fallback.
|
||||||
|
lsp_format_opt = 'fallback'
|
||||||
end
|
end
|
||||||
return { timeout_ms = 500, lsp_format = 'fallback' }
|
|
||||||
|
return {
|
||||||
|
timeout_ms = 500,
|
||||||
|
lsp_format = lsp_format_opt,
|
||||||
|
}
|
||||||
end,
|
end,
|
||||||
|
-- Map filetypes to specific formatters.
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
lua = { 'stylua' },
|
lua = { 'stylua' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- -- Autocompletion: `nvim-cmp` and its dependencies
|
||||||
|
-- This is the core of the autocompletion system.
|
||||||
|
{
|
||||||
|
'hrsh7th/nvim-cmp',
|
||||||
|
-- Only load this plugin when entering insert mode.
|
||||||
|
event = 'InsertEnter',
|
||||||
|
dependencies = {
|
||||||
|
-- `LuaSnip` is the snippet engine.
|
||||||
|
{
|
||||||
|
'L3MON4D3/LuaSnip',
|
||||||
|
-- This build command ensures the `jsregexp` dependency is installed if needed.
|
||||||
|
build = (function()
|
||||||
|
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return 'make install_jsregexp'
|
||||||
|
end)(),
|
||||||
|
},
|
||||||
|
-- `cmp_luasnip` connects the snippet engine to the autocompletion.
|
||||||
|
'saadparwaiz1/cmp_luasnip',
|
||||||
|
-- `cmp-nvim-lsp` provides completion items from the language server.
|
||||||
|
'hrsh7th/cmp-nvim-lsp',
|
||||||
|
-- `cmp-path` provides completion for file paths.
|
||||||
|
'hrsh7th/cmp-path',
|
||||||
|
-- `lazydev` is used for runtime completion of `lazy.nvim` plugin names.
|
||||||
|
'folke/lazydev.nvim',
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
-- Get local references to the required modules.
|
||||||
|
local cmp = require 'cmp'
|
||||||
|
local luasnip = require 'luasnip'
|
||||||
|
luasnip.config.setup {}
|
||||||
|
|
||||||
|
-- Set up the `nvim-cmp` plugin.
|
||||||
|
cmp.setup {
|
||||||
|
-- Define how snippets are expanded.
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
-- Configure the completion menu.
|
||||||
|
completion = { completeopt = 'menu,menuone,noinsert' },
|
||||||
|
-- Set up key mappings for various completion actions.
|
||||||
|
mapping = cmp.mapping.preset.insert {
|
||||||
|
-- Navigate the completion menu.
|
||||||
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||||
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||||
|
-- Scroll documentation.
|
||||||
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||||
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||||
|
-- Confirm the selected completion item.
|
||||||
|
['<C-y>'] = cmp.mapping.confirm { select = true },
|
||||||
|
-- Manually trigger completion.
|
||||||
|
['<C-Space>'] = cmp.mapping.complete {},
|
||||||
|
-- Jump to the next part of a snippet.
|
||||||
|
['<C-l>'] = cmp.mapping(function()
|
||||||
|
if luasnip.expand_or_locally_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
-- Jump to the previous part of a snippet.
|
||||||
|
['<C-h>'] = cmp.mapping(function()
|
||||||
|
if luasnip.locally_jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
},
|
||||||
|
-- Define the sources for completion items and their priority.
|
||||||
|
sources = {
|
||||||
|
{
|
||||||
|
name = 'lazydev',
|
||||||
|
group_index = 0,
|
||||||
|
},
|
||||||
|
{ name = 'nvim_lsp' },
|
||||||
|
{ name = 'luasnip' },
|
||||||
|
{ name = 'path' },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
{ -- Linting
|
{ -- Linting
|
||||||
'mfussenegger/nvim-lint',
|
'mfussenegger/nvim-lint',
|
||||||
event = { 'BufReadPre', 'BufNewFile' },
|
event = { 'BufReadPre', 'BufNewFile' },
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
-- [plugins/git.lua]
|
-- [plugins/git.lua]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{ -- Adds git related signs to the gutter, as well as utilities for managing changes
|
{ -- Adds git related signs + keymaps
|
||||||
'lewis6991/gitsigns.nvim',
|
"lewis6991/gitsigns.nvim",
|
||||||
|
event = "BufReadPre", -- load only when a file is opened
|
||||||
opts = {
|
opts = {
|
||||||
-- Basic options for the signs in the gutter
|
|
||||||
signs = {
|
signs = {
|
||||||
add = { text = '+' },
|
add = { text = "+" },
|
||||||
change = { text = '~' },
|
change = { text = "~" },
|
||||||
delete = { text = '_' },
|
delete = { text = "_" },
|
||||||
topdelete = { text = '‾' },
|
topdelete = { text = "‾" },
|
||||||
changedelete = { text = '~' },
|
changedelete = { text = "~" },
|
||||||
},
|
},
|
||||||
-- All keymaps are now defined in the on_attach function
|
current_line_blame = true, -- shows git blame at end of line
|
||||||
|
current_line_blame_opts = {
|
||||||
|
virt_text = true,
|
||||||
|
virt_text_pos = "eol", -- "eol" | "overlay" | "right_align"
|
||||||
|
delay = 500,
|
||||||
|
ignore_whitespace = false,
|
||||||
|
},
|
||||||
|
current_line_blame_formatter = "<author>, <author_time:%Y-%m-%d> - <summary>",
|
||||||
|
|
||||||
|
-- Keymaps on attach
|
||||||
on_attach = function(bufnr)
|
on_attach = function(bufnr)
|
||||||
local gs = package.loaded.gitsigns
|
local gs = package.loaded.gitsigns
|
||||||
local function map(mode, l, r, desc)
|
local function map(mode, l, r, desc)
|
||||||
|
@ -20,42 +28,39 @@ return {
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Navigation
|
-- Navigation
|
||||||
map('n', ']c', gs.next_hunk, 'Next Hunk')
|
map("n", "]c", gs.next_hunk, "Next Hunk")
|
||||||
map('n', '[c', gs.prev_hunk, 'Prev Hunk')
|
map("n", "[c", gs.prev_hunk, "Prev Hunk")
|
||||||
|
|
||||||
-- Actions
|
-- Actions
|
||||||
map({ 'n', 'v' }, '<leader>hs', gs.stage_hunk, 'Stage Hunk')
|
map({ "n", "v" }, "<leader>hs", gs.stage_hunk, "Stage Hunk")
|
||||||
map({ 'n', 'v' }, '<leader>hr', gs.reset_hunk, 'Reset Hunk')
|
map({ "n", "v" }, "<leader>hr", gs.reset_hunk, "Reset Hunk")
|
||||||
map('n', '<leader>hS', gs.stage_buffer, 'Stage Buffer')
|
map("n", "<leader>hS", gs.stage_buffer, "Stage Buffer")
|
||||||
map('n', '<leader>hu', gs.undo_stage_hunk, 'Undo Stage Hunk')
|
map("n", "<leader>hu", gs.undo_stage_hunk, "Undo Stage Hunk")
|
||||||
map('n', '<leader>hR', gs.reset_buffer, 'Reset Buffer')
|
map("n", "<leader>hR", gs.reset_buffer, "Reset Buffer")
|
||||||
map('n', '<leader>hp', gs.preview_hunk, 'Preview Hunk')
|
map("n", "<leader>hp", gs.preview_hunk, "Preview Hunk")
|
||||||
map('n', '<leader>hb', function() gs.blame_line { full = true } end, 'Blame Line')
|
map("n", "<leader>hb", function() gs.blame_line { full = true } end, "Blame Line")
|
||||||
map('n', '<leader>tb', gs.toggle_current_line_blame, 'Toggle Blame Line')
|
map("n", "<leader>tb", gs.toggle_current_line_blame, "Toggle Blame Line")
|
||||||
map('n', '<leader>hd', gs.diffthis, 'Diff This')
|
map("n", "<leader>hd", gs.diffthis, "Diff This")
|
||||||
map('n', '<leader>hD', function() gs.diffthis '~' end, 'Diff This ~')
|
map("n", "<leader>hD", function() gs.diffthis("~") end, "Diff This ~")
|
||||||
map('n', '<leader>td', gs.toggle_deleted, 'Toggle Deleted')
|
map("n", "<leader>td", gs.toggle_deleted, "Toggle Deleted")
|
||||||
|
|
||||||
-- Text object
|
-- Text object
|
||||||
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', 'Select Hunk')
|
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "Select Hunk")
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{ -- Git wrapper
|
{ -- Git wrapper
|
||||||
'tpope/vim-fugitive',
|
"tpope/vim-fugitive",
|
||||||
cmd = { "Git", "G" }, -- lazy load on :Git
|
cmd = { "Git", "G" }, -- lazy load only on :Git commands
|
||||||
},
|
},
|
||||||
|
|
||||||
require('gitsigns').setup {
|
{ -- Lazygit UI (optional)
|
||||||
current_line_blame = true, -- shows git blame at end of line
|
"kdheepak/lazygit.nvim",
|
||||||
current_line_blame_opts = {
|
cmd = "LazyGit",
|
||||||
virt_text = true,
|
dependencies = { "nvim-lua/plenary.nvim" },
|
||||||
virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
|
keys = {
|
||||||
delay = 500,
|
{ "<leader>lg", "<cmd>LazyGit<CR>", desc = "Open LazyGit" },
|
||||||
ignore_whitespace = false,
|
},
|
||||||
},
|
},
|
||||||
current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,99 +162,4 @@ return {
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ -- Autoformat
|
|
||||||
'stevearc/conform.nvim',
|
|
||||||
event = { 'BufWritePre' },
|
|
||||||
cmd = { 'ConformInfo' },
|
|
||||||
keys = {
|
|
||||||
{
|
|
||||||
'<leader>f',
|
|
||||||
function()
|
|
||||||
require('conform').format { async = true, lsp_format = 'fallback' }
|
|
||||||
end,
|
|
||||||
mode = '',
|
|
||||||
desc = '[F]ormat buffer',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
opts = {
|
|
||||||
notify_on_error = false,
|
|
||||||
format_on_save = function(bufnr)
|
|
||||||
local disable_filetypes = { c = true, cpp = true }
|
|
||||||
local lsp_format_opt
|
|
||||||
if disable_filetypes[vim.bo[bufnr].filetype] then
|
|
||||||
lsp_format_opt = 'never'
|
|
||||||
else
|
|
||||||
lsp_format_opt = 'fallback'
|
|
||||||
end
|
|
||||||
return {
|
|
||||||
timeout_ms = 500,
|
|
||||||
lsp_format = lsp_format_opt,
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
formatters_by_ft = {
|
|
||||||
lua = { 'stylua' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{ -- Autocompletion
|
|
||||||
'hrsh7th/nvim-cmp',
|
|
||||||
event = 'InsertEnter',
|
|
||||||
dependencies = {
|
|
||||||
{
|
|
||||||
'L3MON4D3/LuaSnip',
|
|
||||||
build = (function()
|
|
||||||
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
return 'make install_jsregexp'
|
|
||||||
end)(),
|
|
||||||
},
|
|
||||||
'saadparwaiz1/cmp_luasnip',
|
|
||||||
'hrsh7th/cmp-nvim-lsp',
|
|
||||||
'hrsh7th/cmp-path',
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
local cmp = require 'cmp'
|
|
||||||
local luasnip = require 'luasnip'
|
|
||||||
luasnip.config.setup {}
|
|
||||||
|
|
||||||
cmp.setup {
|
|
||||||
snippet = {
|
|
||||||
expand = function(args)
|
|
||||||
luasnip.lsp_expand(args.body)
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
completion = { completeopt = 'menu,menuone,noinsert' },
|
|
||||||
mapping = cmp.mapping.preset.insert {
|
|
||||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
||||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
||||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
|
||||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
||||||
['<C-y>'] = cmp.mapping.confirm { select = true },
|
|
||||||
['<C-Space>'] = cmp.mapping.complete {},
|
|
||||||
['<C-l>'] = cmp.mapping(function()
|
|
||||||
if luasnip.expand_or_locally_jumpable() then
|
|
||||||
luasnip.expand_or_jump()
|
|
||||||
end
|
|
||||||
end, { 'i', 's' }),
|
|
||||||
['<C-h>'] = cmp.mapping(function()
|
|
||||||
if luasnip.locally_jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
|
||||||
end
|
|
||||||
end, { 'i', 's' }),
|
|
||||||
},
|
|
||||||
sources = {
|
|
||||||
{
|
|
||||||
name = 'lazydev',
|
|
||||||
group_index = 0,
|
|
||||||
},
|
|
||||||
{ name = 'nvim_lsp' },
|
|
||||||
{ name = 'luasnip' },
|
|
||||||
{ name = 'path' },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,57 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- neo-tree.lua
|
||||||
|
'nvim-neo-tree/neo-tree.nvim',
|
||||||
|
branch = 'v3.x',
|
||||||
|
dependencies = {
|
||||||
|
'nvim-lua/plenary.nvim',
|
||||||
|
'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended
|
||||||
|
'MunifTanjim/nui.nvim',
|
||||||
|
},
|
||||||
|
cmd = 'Neotree',
|
||||||
|
keys = {
|
||||||
|
{
|
||||||
|
'<leader>e',
|
||||||
|
function()
|
||||||
|
require('neo-tree.command').execute { toggle = true, dir = vim.loop.cwd() }
|
||||||
|
end,
|
||||||
|
desc = 'Explorer NeoTree (Current Dir)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'<leader>E',
|
||||||
|
function()
|
||||||
|
require('neo-tree.command').execute { toggle = true, dir = vim.fn.stdpath 'config' }
|
||||||
|
end,
|
||||||
|
desc = 'Explorer NeoTree (Config Dir)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts = {
|
||||||
|
close_if_last_window = true, -- Close Neo-tree if it is the last window left
|
||||||
|
popup_border_style = 'rounded',
|
||||||
|
filesystem = {
|
||||||
|
filtered_items = {
|
||||||
|
visible = true,
|
||||||
|
hide_dotfiles = false,
|
||||||
|
hide_gitignored = true,
|
||||||
|
},
|
||||||
|
follow_current_file = {
|
||||||
|
enabled = true, -- This will find and focus the file in the tree when you open a buffer.
|
||||||
|
},
|
||||||
|
hijack_netrw_behavior = 'open_current', -- Or 'disabled' if you prefer to keep netrw for directories.
|
||||||
|
},
|
||||||
|
window = {
|
||||||
|
mappings = {
|
||||||
|
['<space>'] = 'none', -- Disable space for opening folders, allowing for custom mappings
|
||||||
|
['l'] = 'open',
|
||||||
|
['h'] = 'close_node',
|
||||||
|
['S'] = 'open_split',
|
||||||
|
['s'] = 'open_vsplit',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
{ -- Oil.nvim: directory navigation as buffers
|
{ -- Oil.nvim: directory navigation as buffers
|
||||||
'stevearc/oil.nvim',
|
'stevearc/oil.nvim',
|
||||||
opts = {},
|
opts = {},
|
||||||
|
@ -97,17 +148,23 @@ return {
|
||||||
},
|
},
|
||||||
|
|
||||||
{ -- Snacks.nvim: utilities (scratch, terminal, etc.)
|
{ -- Snacks.nvim: utilities (scratch, terminal, etc.)
|
||||||
'folke/snacks.nvim',
|
"folke/snacks.nvim",
|
||||||
config = function()
|
event = "VeryLazy",
|
||||||
require("snacks").setup({
|
opts = {
|
||||||
terminal = { win = { style = "float" } },
|
terminal = { win = { style = "float" } },
|
||||||
scratch = true,
|
scratch = { enabled = true }, -- ✅ must be a table
|
||||||
})
|
},
|
||||||
vim.keymap.set("n", "<leader>tt", function() require("snacks.terminal").toggle() end, { desc = "Toggle terminal" })
|
config = function(_, opts)
|
||||||
vim.keymap.set("n", "<leader>ss", function() require("snacks.scratch").open() end, { desc = "Open scratch buffer" })
|
local snacks = require("snacks")
|
||||||
|
snacks.setup(opts)
|
||||||
|
|
||||||
|
-- Keymaps
|
||||||
|
vim.keymap.set("n", "<leader>tt", function() snacks.terminal.toggle() end, { desc = "Toggle terminal" })
|
||||||
|
vim.keymap.set("n", "<leader>sc", function() snacks.scratch.open() end, { desc = "Open [s]cratch buffer" })
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
{ -- Debugging (DAP)
|
{ -- Debugging (DAP)
|
||||||
'mfussenegger/nvim-dap',
|
'mfussenegger/nvim-dap',
|
||||||
dependencies = {
|
dependencies = {
|
||||||
|
|
Loading…
Reference in New Issue