From 4e2a91fbe6d56aed7047a38f47dbee17584ecee3 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Tue, 25 Feb 2025 10:53:04 +0100 Subject: [PATCH] simplify shared nvim --- config/shared/nvim | 143 +++++++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 63 deletions(-) diff --git a/config/shared/nvim b/config/shared/nvim index 24bdf0c..e3c38c7 100644 --- a/config/shared/nvim +++ b/config/shared/nvim @@ -1,57 +1,15 @@ --- [[ Basic Keymaps ]] --- See `:help vim.keymap.set()` - --- Map 'jk' to escape in insert mode -vim.keymap.set('i', 'jk', '', { desc = 'Exit insert mode with jk' }) - --- Clear highlights on search when pressing in normal mode --- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') - --- Diagnostic keymaps -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) - --- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier --- for people to discover. Otherwise, you normally need to press , which --- is not what someone will guess without a bit more experience. -vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) - --- Keybinds to make split navigation easier. --- Use CTRL+ to switch between windows --- --- See `:help wincmd` for a list of all window commands -vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) - --- [[ Basic Autocommands ]] --- See `:help lua-guide-autocommands` - --- Highlight when yanking (copying) text --- Try it with `yap` in normal mode --- See `:help vim.highlight.on_yank()` -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) - --- --------------------------------------------------- --- --------------------------------------------------- - --- Set as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) +-- Map Leader vim.g.mapleader = " " vim.g.maplocalleader = " " --- [[ Setting options ]] --- See `:help vim.opt` --- NOTE: You can change these options as you wish! --- For more options, you can see `:help option-list` +-- Use Nerd Font +vim.g.have_nerd_font = true + +-- Add vertical line +-- vim.opt.colorcolumn = "100" + +-- Enable TrueColor +vim.opt.termguicolors = true -- Disable Neovim background vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) @@ -71,28 +29,24 @@ vim.opt.smartindent = true -- Do smart autoindenting when starting a new line -- Disable line wrapping vim.opt.wrap = false +-- Enable break indent +vim.opt.breakindent = true + -- Make line numbers default vim.opt.number = true vim.opt.relativenumber = true --- Enable mouse mode, can be useful for resizing splits for example! +-- Enable mouse mode, can be useful for resizing splits for example vim.opt.mouse = "a" --- Don't show the mode, since it's already in the status line -vim.opt.showmode = true +-- Full path on status line vim.opt.statusline = "%F%m%r%h%w%=%l,%c %P" --- Sync clipboard between OS and Neovim. --- Schedule the setting after `UiEnter` because it can increase startup-time. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` +-- Sync clipboard between OS and Neovim vim.schedule(function() vim.opt.clipboard = "unnamedplus" end) --- Enable break indent -vim.opt.breakindent = true - -- Save undo history vim.opt.undofile = true @@ -111,11 +65,74 @@ vim.opt.timeoutlen = 300 vim.opt.splitright = true vim.opt.splitbelow = true --- Preview substitutions live, as you type! +-- Sets how neovim will display certain whitespace characters in the editor. +vim.opt.list = true +vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" } + +-- Preview substitutions live, as you type vim.opt.inccommand = "split" -- Show which line your cursor is on vim.opt.cursorline = true --- Minimal number of screen lines to keep above and below the cursor. +-- Minimal number of screen lines to keep above and below the cursor vim.opt.scrolloff = 10 + +-- Highlight when yanking (copying) text +vim.api.nvim_create_autocmd("TextYankPost", { + callback = function() + vim.highlight.on_yank() + end, +}) + +-- Keymaps + +local remap = require("utils.remap") + +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" }) + +-- Prevent "x" from overriding the register +remap.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" }) + +-- 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" }) +for i = 1, 9 do + remap.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" }) + +-- Terminal +remap.nmap("tet", function() + vim.cmd("terminal") + vim.cmd("startinsert") +end, { desc = "[T]erminal" }) +remap.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" })