update simple nvim

This commit is contained in:
Tomas Mirchev 2025-02-25 11:00:15 +01:00
parent 4e2a91fbe6
commit c3c96328c9
2 changed files with 51 additions and 30 deletions

View File

@ -11,7 +11,7 @@
"-post-link": "curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim && vim -es -u ~/.vimrc -i NONE -c 'PlugInstall' -c 'qa'" "-post-link": "curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim && vim -es -u ~/.vimrc -i NONE -c 'PlugInstall' -c 'qa'"
}, },
"nvim": { "nvim": {
"link": { "from": "shared/nvim", "to": "~/.config/nvim" } "link": { "from": "shared/nvim", "to": "~/.config/nvim/init.lua" }
}, },
"zsh": { "zsh": {
"link": { "from": "shared/zsh", "to": "~/.zshrc" } "link": { "from": "shared/zsh", "to": "~/.zshrc" }

View File

@ -1,3 +1,26 @@
-- Helper function for key mappings
local function map(mode, lhs, rhs, opts)
local options = { silent = true, noremap = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
if type(mode) == "table" then
for _, m in ipairs(mode) do
vim.keymap.set(m, lhs, rhs, options)
end
else
vim.keymap.set(mode, lhs, rhs, options)
end
end
-- Mode-specific mapping functions
local function nmap(lhs, rhs, opts) map("n", lhs, rhs, opts) end
local function imap(lhs, rhs, opts) map("i", lhs, rhs, opts) end
local function vmap(lhs, rhs, opts) map("v", lhs, rhs, opts) end
local function tmap(lhs, rhs, opts) map("t", lhs, rhs, opts) end
-- Map Leader -- Map Leader
vim.g.mapleader = " " vim.g.mapleader = " "
vim.g.maplocalleader = " " vim.g.maplocalleader = " "
@ -87,52 +110,50 @@ vim.api.nvim_create_autocmd("TextYankPost", {
-- Keymaps -- Keymaps
local remap = require("utils.remap") nmap("<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" })
remap.nmap("<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" }) imap("jk", "<Esc>", { desc = "Exit insert mode with jk" })
nmap("<Esc>", "<cmd>nohlsearch<CR>", { desc = "Clear highlights" })
remap.imap("jk", "<Esc>", { desc = "Exit insert mode with jk" })
remap.nmap("<Esc>", "<cmd>nohlsearch<CR>", { desc = "Clear highlights" })
-- Prevent "x" from overriding the register -- Prevent "x" from overriding the register
remap.nmap("x", '"_x') nmap("x", '"_x')
-- Window Navigation -- Window Navigation
remap.nmap("<C-h>", "<C-w>h", { desc = "Move focus to the left window" }) nmap("<C-h>", "<C-w>h", { desc = "Move focus to the left window" })
remap.nmap("<C-l>", "<C-w>l", { desc = "Move focus to the right window" }) nmap("<C-l>", "<C-w>l", { desc = "Move focus to the right window" })
remap.nmap("<C-j>", "<C-w>j", { desc = "Move focus to the lower window" }) nmap("<C-j>", "<C-w>j", { desc = "Move focus to the lower window" })
remap.nmap("<C-k>", "<C-w>k", { desc = "Move focus to the upper window" }) nmap("<C-k>", "<C-w>k", { desc = "Move focus to the upper window" })
-- Tab management -- Tab management
remap.nmap("<Leader>tn", ":tabnew<CR>", { desc = "[T]ab [N]ew" }) nmap("<Leader>tn", ":tabnew<CR>", { desc = "[T]ab [N]ew" })
remap.nmap("<Leader>tc", ":tabclose<CR>", { desc = "[T]ab [C]lose" }) nmap("<Leader>tc", ":tabclose<CR>", { desc = "[T]ab [C]lose" })
remap.nmap("<Leader>to", ":tabonly<CR>", { desc = "[T]ab [O]nly" }) nmap("<Leader>to", ":tabonly<CR>", { desc = "[T]ab [O]nly" })
remap.nmap("<Leader>tl", ":tabnext<CR>", { desc = "[T]ab Next" }) nmap("<Leader>tl", ":tabnext<CR>", { desc = "[T]ab Next" })
remap.nmap("<Leader>th", ":tabprevious<CR>", { desc = "[T]ab Previous" }) nmap("<Leader>th", ":tabprevious<CR>", { desc = "[T]ab Previous" })
remap.nmap("<Leader>tm.", ":tabmove +1<CR>", { desc = "[T]ab [M]ove Right" }) nmap("<Leader>tm.", ":tabmove +1<CR>", { desc = "[T]ab [M]ove Right" })
remap.nmap("<Leader>tm,", ":tabmove -1<CR>", { desc = "[T]ab [M]ove Left" }) nmap("<Leader>tm,", ":tabmove -1<CR>", { desc = "[T]ab [M]ove Left" })
for i = 1, 9 do for i = 1, 9 do
remap.nmap(string.format("<Leader>%d", i), string.format("%dgt", i), { desc = string.format("[T]ab %d", i) }) nmap(string.format("<Leader>%d", i), string.format("%dgt", i), { desc = string.format("[T]ab %d", i) })
end end
-- Buffer Management -- Buffer Management
remap.nmap("<Leader>bl", ":ls<CR>", { desc = "[B]uffer [L]ist" }) nmap("<Leader>bl", ":ls<CR>", { desc = "[B]uffer [L]ist" })
remap.nmap("<Leader>bd", ":bdelete<CR>", { desc = "[B]uffer [D]elete" }) nmap("<Leader>bd", ":bdelete<CR>", { desc = "[B]uffer [D]elete" })
remap.nmap("]b", ":bnext<CR>", { desc = "[B]uffer [N]ext" }) nmap("]b", ":bnext<CR>", { desc = "[B]uffer [N]ext" })
remap.nmap("[b", ":bprevious<CR>", { desc = "[B]uffer [P]revious" }) nmap("[b", ":bprevious<CR>", { desc = "[B]uffer [P]revious" })
remap.nmap("<Leader>bb", ":b<Space>", { desc = "[B]uffer Select" }) nmap("<Leader>bb", ":b<Space>", { desc = "[B]uffer Select" })
remap.nmap("<Leader>bo", ":bufdo bd|1bd<CR>", { desc = "[B]uffer Delete Others" }) nmap("<Leader>bo", ":bufdo bd|1bd<CR>", { desc = "[B]uffer Delete Others" })
-- Terminal -- Terminal
remap.nmap("<Leader>tet", function() nmap("<Leader>tet", function()
vim.cmd("terminal") vim.cmd("terminal")
vim.cmd("startinsert") vim.cmd("startinsert")
end, { desc = "[T]erminal" }) end, { desc = "[T]erminal" })
remap.nmap("<leader>ter", function() nmap("<leader>ter", function()
local buf_dir = vim.fn.expand("%:p:h") local buf_dir = vim.fn.expand("%:p:h")
vim.cmd("edit term://" .. buf_dir .. "//zsh") vim.cmd("edit term://" .. buf_dir .. "//zsh")
vim.cmd("startinsert") vim.cmd("startinsert")
end, { desc = "[T]erminal [R]elative" }) end, { desc = "[T]erminal [R]elative" })
remap.tmap("<Esc>", "<C-\\><C-n>", { desc = "Terminal Normal Mode" }) tmap("<Esc>", "<C-\\><C-n>", { desc = "Terminal Normal Mode" })
remap.tmap("jk", "<C-\\><C-n>", { desc = "Terminal Normal Mode" }) tmap("jk", "<C-\\><C-n>", { desc = "Terminal Normal Mode" })
remap.tmap("<C-w>", "<C-\\><C-n><C-w>", { desc = "Terminal Window Command" }) tmap("<C-w>", "<C-\\><C-n><C-w>", { desc = "Terminal Window Command" })