diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua index 3071edd..965b71b 100644 --- a/nvim/lua/mappings.lua +++ b/nvim/lua/mappings.lua @@ -15,7 +15,7 @@ vim.keymap.set("n", "tt", base46.toggle_transparency) -- Toggle wrap vim.keymap.set("n", "ww", function () - vim.wo.wrap = not vim.wo.wrap + vim.wo.wrap = not vim.wo.wrap end) -- Debbuger binds @@ -31,8 +31,8 @@ end) local dap = require "dap" vim.keymap.set("n", "", function() - vim.cmd('NvimTreeClose') - dap.continue() + vim.cmd('NvimTreeClose') + dap.continue() end) vim.keymap.set("n", "", dap.step_into, { desc = "Dap Step into" }) vim.keymap.set("n", "", dap.step_over, { desc = "Dap Step over" }) @@ -48,21 +48,44 @@ local function toggle_terminal() require("nvchad.term").toggle { pos = "sp", id = "htoggleTerm" } end -local function toggle_git_add() +-- Git add current file +local function git_add_current_file() local filepath = vim.fn.expand("%:p") -- Get the full path of the current file - local handle = io.popen("git ls-files --cached --error-unmatch " .. filepath .. " 2>/dev/null") -- Check if the file is staged - local result = handle:read("*a") - handle:close() + local command = "git add " .. vim.fn.shellescape(filepath) + local output = vim.fn.system(command) - if result ~= "" then - os.execute("git reset " .. filepath) -- Unstage the file if it's already staged - print("Unstaged: " .. filepath) + if vim.v.shell_error ~= 0 then + print("Error adding file: " .. output) else - os.execute("git add " .. filepath) -- Stage the file if it's not staged - print("Staged: " .. filepath) + print("Added: " .. filepath) end end +-- Git unstage (reset) current file +local function git_unstage_current_file() + local filepath = vim.fn.expand("%:p") -- Get the full path of the current file + local command = "git reset HEAD -- " .. vim.fn.shellescape(filepath) + local output = vim.fn.system(command) + + if vim.v.shell_error ~= 0 then + print("Error unstaging file: " .. output) + else + print("Unstaged: " .. filepath) + end +end + +-- Alternative unstage using restore (Git 2.23+) +local function git_unstage_current_file_restore() + local filepath = vim.fn.expand("%:p") -- Get the full path of the current file + local command = "git restore --staged " .. vim.fn.shellescape(filepath) + local output = vim.fn.system(command) + + if vim.v.shell_error ~= 0 then + print("Error unstaging file: " .. output) + else + print("Unstaged: " .. filepath) + end +end map({ "n", "t" }, "", toggle_terminal, { desc = "terminal toggleable horizontal term" }) map({ "n", "t" }, "", toggle_terminal, { desc = "terminal toggleable horizontal term" }) @@ -73,10 +96,10 @@ map("t", "", "", { desc = "terminal escape terminal mode" }) local hop = require('hop') local directions = require('hop.hint').HintDirection vim.keymap.set('', 'f', function() - hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = false }) + hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = false }) end, {remap=true}) vim.keymap.set('', 'F', function() - hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = false }) + hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = false }) end, {remap=true}) -- vim.keymap.set('', 't', function() -- hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = false, hint_offset = -1 }) @@ -103,20 +126,22 @@ vim.keymap.set("n", "ft", 'TodoTelescope', { desc = "Telescope vim.keymap.set("n", "tr", 'NvimTreeRefresh', { desc = "Nvimtree Refresh" }) -- toggle git add current file -vim.keymap.set("n", "ga", toggle_git_add, { desc = "Toggle git add for current file" }) +vim.keymap.set("n", "ga", git_add_current_file, { desc = "Git add file" }) +vim.keymap.set("n", "gd", git_unstage_current_file, { desc = "Git unstage file" }) +vim.keymap.set("n", "gr", git_unstage_current_file_restore, { desc = "Git unstage file (restore)" }) -- nvimtree open file without focusing vim.keymap.set("n", "T", - function(node) - local nt_api = require("nvim-tree.api") - nt_api.node.open.edit(node) - nt_api.tree.focus() - end, -{ desc = "Nvimtree Open without focusing" }) + function(node) + local nt_api = require("nvim-tree.api") + nt_api.node.open.edit(node) + nt_api.tree.focus() + end, + { desc = "Nvimtree Open without focusing" }) -- nvchad tabs vim.keymap.set("n", "tn", 'tabNext', { desc = "Tab Next" }) - vim.keymap.set("n", "tp", 'tabprevious', { desc = "Tab Previous" }) +vim.keymap.set("n", "tp", 'tabprevious', { desc = "Tab Previous" }) vim.keymap.set("n", "tm", 'tabnew', { desc = "Tab More!" }) vim.keymap.set("n", "tc", 'tabclose', { desc = "Tab Close" }) diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index 37abe90..27d337a 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -17,7 +17,27 @@ local enable_providers = { -- disable wrap vim.o.wrap = false +-- amount of tabs +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 + -- disable auto comment vim.opt_local.formatoptions:remove("r") vim.g.lua_snippets_path = "~/.config/nvim/lua/lua_snippets" + +-- enable blamer +vim.g.blamer_enabled = true + +-- Hyprlang LSP +vim.api.nvim_create_autocmd({'BufEnter', 'BufWinEnter'}, { + pattern = {"*.hl", "hypr*.conf"}, + callback = function() + vim.lsp.start { + name = "hyprlang", + cmd = {"hyprls"}, + root_dir = vim.fn.getcwd(), + } + end +}) diff --git a/nvim/lua/plugins/blamer.lua b/nvim/lua/plugins/blamer.lua index 587add1..3f2375f 100644 --- a/nvim/lua/plugins/blamer.lua +++ b/nvim/lua/plugins/blamer.lua @@ -1,5 +1,5 @@ return { - { - "APZelos/blamer.nvim" - } + { + "APZelos/blamer.nvim" + } }