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
|
||||
vim.g.have_nerd_font = false
|
||||
vim.g.have_nerd_font = true
|
||||
|
||||
-- [[ Setting options ]]
|
||||
-- See `:help vim.opt`
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
-- [plugins/editing.lua]
|
||||
-- [plugins/editor.lua]
|
||||
|
||||
return {
|
||||
|
||||
|
||||
|
||||
{ -- Autoformat
|
||||
-- -- Autoformat: `conform.nvim`
|
||||
-- This plugin provides a non-LSP based way to format your code.
|
||||
{
|
||||
'stevearc/conform.nvim',
|
||||
-- Only load this plugin right before a buffer is written.
|
||||
event = { 'BufWritePre' },
|
||||
-- Add the `ConformInfo` command for debugging.
|
||||
cmd = { 'ConformInfo' },
|
||||
-- Set up keybinds for manual formatting.
|
||||
keys = {
|
||||
{
|
||||
-- The leader key followed by 'f' to format the current buffer.
|
||||
'<leader>f',
|
||||
function()
|
||||
require('conform').format { async = true, lsp_format = 'fallback' }
|
||||
|
@ -19,18 +23,115 @@ return {
|
|||
},
|
||||
},
|
||||
opts = {
|
||||
-- Disable notifications on formatting errors to avoid pop-ups.
|
||||
notify_on_error = false,
|
||||
-- This function runs before saving a file to check if it should be formatted.
|
||||
format_on_save = function(bufnr)
|
||||
-- A list of filetypes where auto-formatting on save is disabled.
|
||||
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 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
|
||||
|
||||
return {
|
||||
timeout_ms = 500,
|
||||
lsp_format = lsp_format_opt,
|
||||
}
|
||||
end,
|
||||
-- Map filetypes to specific formatters.
|
||||
formatters_by_ft = {
|
||||
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 { timeout_ms = 500, lsp_format = 'fallback' }
|
||||
end,
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
},
|
||||
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
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
--[plugins/git.lua]
|
||||
|
||||
-- [plugins/git.lua]
|
||||
return {
|
||||
{ -- Adds git related signs to the gutter, as well as utilities for managing changes
|
||||
'lewis6991/gitsigns.nvim',
|
||||
{ -- Adds git related signs + keymaps
|
||||
"lewis6991/gitsigns.nvim",
|
||||
event = "BufReadPre", -- load only when a file is opened
|
||||
opts = {
|
||||
-- Basic options for the signs in the gutter
|
||||
signs = {
|
||||
add = { text = '+' },
|
||||
change = { text = '~' },
|
||||
delete = { text = '_' },
|
||||
topdelete = { text = '‾' },
|
||||
changedelete = { text = '~' },
|
||||
add = { text = "+" },
|
||||
change = { text = "~" },
|
||||
delete = { text = "_" },
|
||||
topdelete = { 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)
|
||||
local gs = package.loaded.gitsigns
|
||||
local function map(mode, l, r, desc)
|
||||
|
@ -20,42 +28,39 @@ return {
|
|||
end
|
||||
|
||||
-- Navigation
|
||||
map('n', ']c', gs.next_hunk, 'Next Hunk')
|
||||
map('n', '[c', gs.prev_hunk, 'Prev Hunk')
|
||||
map("n", "]c", gs.next_hunk, "Next Hunk")
|
||||
map("n", "[c", gs.prev_hunk, "Prev Hunk")
|
||||
|
||||
-- Actions
|
||||
map({ 'n', 'v' }, '<leader>hs', gs.stage_hunk, 'Stage Hunk')
|
||||
map({ 'n', 'v' }, '<leader>hr', gs.reset_hunk, 'Reset Hunk')
|
||||
map('n', '<leader>hS', gs.stage_buffer, 'Stage Buffer')
|
||||
map('n', '<leader>hu', gs.undo_stage_hunk, 'Undo Stage Hunk')
|
||||
map('n', '<leader>hR', gs.reset_buffer, 'Reset Buffer')
|
||||
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>tb', gs.toggle_current_line_blame, 'Toggle Blame Line')
|
||||
map('n', '<leader>hd', gs.diffthis, 'Diff This')
|
||||
map('n', '<leader>hD', function() gs.diffthis '~' end, 'Diff This ~')
|
||||
map('n', '<leader>td', gs.toggle_deleted, 'Toggle Deleted')
|
||||
map({ "n", "v" }, "<leader>hs", gs.stage_hunk, "Stage Hunk")
|
||||
map({ "n", "v" }, "<leader>hr", gs.reset_hunk, "Reset Hunk")
|
||||
map("n", "<leader>hS", gs.stage_buffer, "Stage Buffer")
|
||||
map("n", "<leader>hu", gs.undo_stage_hunk, "Undo Stage Hunk")
|
||||
map("n", "<leader>hR", gs.reset_buffer, "Reset Buffer")
|
||||
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>tb", gs.toggle_current_line_blame, "Toggle Blame Line")
|
||||
map("n", "<leader>hd", gs.diffthis, "Diff This")
|
||||
map("n", "<leader>hD", function() gs.diffthis("~") end, "Diff This ~")
|
||||
map("n", "<leader>td", gs.toggle_deleted, "Toggle Deleted")
|
||||
|
||||
-- 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,
|
||||
},
|
||||
},
|
||||
|
||||
{ -- Git wrapper
|
||||
'tpope/vim-fugitive',
|
||||
cmd = { "Git", "G" }, -- lazy load on :Git
|
||||
"tpope/vim-fugitive",
|
||||
cmd = { "Git", "G" }, -- lazy load only on :Git commands
|
||||
},
|
||||
|
||||
require('gitsigns').setup {
|
||||
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,
|
||||
{ -- Lazygit UI (optional)
|
||||
"kdheepak/lazygit.nvim",
|
||||
cmd = "LazyGit",
|
||||
dependencies = { "nvim-lua/plenary.nvim" },
|
||||
keys = {
|
||||
{ "<leader>lg", "<cmd>LazyGit<CR>", desc = "Open LazyGit" },
|
||||
},
|
||||
current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
|
|
@ -162,99 +162,4 @@ return {
|
|||
}
|
||||
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
|
||||
'stevearc/oil.nvim',
|
||||
opts = {},
|
||||
|
@ -97,17 +148,23 @@ return {
|
|||
},
|
||||
|
||||
{ -- Snacks.nvim: utilities (scratch, terminal, etc.)
|
||||
'folke/snacks.nvim',
|
||||
config = function()
|
||||
require("snacks").setup({
|
||||
"folke/snacks.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {
|
||||
terminal = { win = { style = "float" } },
|
||||
scratch = true,
|
||||
})
|
||||
vim.keymap.set("n", "<leader>tt", function() require("snacks.terminal").toggle() end, { desc = "Toggle terminal" })
|
||||
vim.keymap.set("n", "<leader>ss", function() require("snacks.scratch").open() end, { desc = "Open scratch buffer" })
|
||||
scratch = { enabled = true }, -- ✅ must be a table
|
||||
},
|
||||
config = function(_, opts)
|
||||
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,
|
||||
},
|
||||
|
||||
|
||||
{ -- Debugging (DAP)
|
||||
'mfussenegger/nvim-dap',
|
||||
dependencies = {
|
||||
|
|
Loading…
Reference in New Issue