From c3c96328c9c758cf9d57579344d3c20b6d29ece6 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Tue, 25 Feb 2025 11:00:15 +0100 Subject: [PATCH] update simple nvim --- config.json | 2 +- config/shared/nvim | 79 +++++++++++++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/config.json b/config.json index 9b9a83c..f0a1793 100644 --- a/config.json +++ b/config.json @@ -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'" }, "nvim": { - "link": { "from": "shared/nvim", "to": "~/.config/nvim" } + "link": { "from": "shared/nvim", "to": "~/.config/nvim/init.lua" } }, "zsh": { "link": { "from": "shared/zsh", "to": "~/.zshrc" } diff --git a/config/shared/nvim b/config/shared/nvim index e3c38c7..863b000 100644 --- a/config/shared/nvim +++ b/config/shared/nvim @@ -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 vim.g.mapleader = " " vim.g.maplocalleader = " " @@ -87,52 +110,50 @@ vim.api.nvim_create_autocmd("TextYankPost", { -- Keymaps -local remap = require("utils.remap") +nmap("q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" }) -remap.nmap("q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" }) - -remap.imap("jk", "", { desc = "Exit insert mode with jk" }) -remap.nmap("", "nohlsearch", { desc = "Clear highlights" }) +imap("jk", "", { desc = "Exit insert mode with jk" }) +nmap("", "nohlsearch", { desc = "Clear highlights" }) -- Prevent "x" from overriding the register -remap.nmap("x", '"_x') +nmap("x", '"_x') -- Window Navigation -remap.nmap("", "h", { desc = "Move focus to the left window" }) -remap.nmap("", "l", { desc = "Move focus to the right window" }) -remap.nmap("", "j", { desc = "Move focus to the lower window" }) -remap.nmap("", "k", { desc = "Move focus to the upper window" }) +nmap("", "h", { desc = "Move focus to the left window" }) +nmap("", "l", { desc = "Move focus to the right window" }) +nmap("", "j", { desc = "Move focus to the lower window" }) +nmap("", "k", { desc = "Move focus to the upper window" }) -- Tab management -remap.nmap("tn", ":tabnew", { desc = "[T]ab [N]ew" }) -remap.nmap("tc", ":tabclose", { desc = "[T]ab [C]lose" }) -remap.nmap("to", ":tabonly", { desc = "[T]ab [O]nly" }) -remap.nmap("tl", ":tabnext", { desc = "[T]ab Next" }) -remap.nmap("th", ":tabprevious", { desc = "[T]ab Previous" }) -remap.nmap("tm.", ":tabmove +1", { desc = "[T]ab [M]ove Right" }) -remap.nmap("tm,", ":tabmove -1", { desc = "[T]ab [M]ove Left" }) +nmap("tn", ":tabnew", { desc = "[T]ab [N]ew" }) +nmap("tc", ":tabclose", { desc = "[T]ab [C]lose" }) +nmap("to", ":tabonly", { desc = "[T]ab [O]nly" }) +nmap("tl", ":tabnext", { desc = "[T]ab Next" }) +nmap("th", ":tabprevious", { desc = "[T]ab Previous" }) +nmap("tm.", ":tabmove +1", { desc = "[T]ab [M]ove Right" }) +nmap("tm,", ":tabmove -1", { desc = "[T]ab [M]ove Left" }) for i = 1, 9 do - remap.nmap(string.format("%d", i), string.format("%dgt", i), { desc = string.format("[T]ab %d", i) }) + nmap(string.format("%d", i), string.format("%dgt", i), { desc = string.format("[T]ab %d", i) }) end -- Buffer Management -remap.nmap("bl", ":ls", { desc = "[B]uffer [L]ist" }) -remap.nmap("bd", ":bdelete", { desc = "[B]uffer [D]elete" }) -remap.nmap("]b", ":bnext", { desc = "[B]uffer [N]ext" }) -remap.nmap("[b", ":bprevious", { desc = "[B]uffer [P]revious" }) -remap.nmap("bb", ":b", { desc = "[B]uffer Select" }) -remap.nmap("bo", ":bufdo bd|1bd", { desc = "[B]uffer Delete Others" }) +nmap("bl", ":ls", { desc = "[B]uffer [L]ist" }) +nmap("bd", ":bdelete", { desc = "[B]uffer [D]elete" }) +nmap("]b", ":bnext", { desc = "[B]uffer [N]ext" }) +nmap("[b", ":bprevious", { desc = "[B]uffer [P]revious" }) +nmap("bb", ":b", { desc = "[B]uffer Select" }) +nmap("bo", ":bufdo bd|1bd", { desc = "[B]uffer Delete Others" }) -- Terminal -remap.nmap("tet", function() +nmap("tet", function() vim.cmd("terminal") vim.cmd("startinsert") end, { desc = "[T]erminal" }) -remap.nmap("ter", function() +nmap("ter", function() local buf_dir = vim.fn.expand("%:p:h") vim.cmd("edit term://" .. buf_dir .. "//zsh") vim.cmd("startinsert") end, { desc = "[T]erminal [R]elative" }) -remap.tmap("", "", { desc = "Terminal Normal Mode" }) -remap.tmap("jk", "", { desc = "Terminal Normal Mode" }) -remap.tmap("", "", { desc = "Terminal Window Command" }) +tmap("", "", { desc = "Terminal Normal Mode" }) +tmap("jk", "", { desc = "Terminal Normal Mode" }) +tmap("", "", { desc = "Terminal Window Command" })