From 6bef8f32b19778fdfe52f0eb39719425508dcc7b Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Thu, 24 Apr 2025 11:36:39 +0300 Subject: Refactored nvim config to make it easier and less insanely nested --- .config/nvim/lua/custom/config/keymaps.lua | 99 ------------------------------ 1 file changed, 99 deletions(-) delete mode 100644 .config/nvim/lua/custom/config/keymaps.lua (limited to '.config/nvim/lua/custom/config/keymaps.lua') diff --git a/.config/nvim/lua/custom/config/keymaps.lua b/.config/nvim/lua/custom/config/keymaps.lua deleted file mode 100644 index 36134dd..0000000 --- a/.config/nvim/lua/custom/config/keymaps.lua +++ /dev/null @@ -1,99 +0,0 @@ -local set = vim.keymap.set -local silent = { silent = true } ----@param mode string|table ----@param keymap string -local function unbind(mode, keymap) - set(mode, keymap, function() end) -end - -local function toggle_zen() - vim.cmd('Neotree close') - vim.cmd('Trouble todo close') - vim.cmd('UndotreeHide') -end - -local function yank_filepath_to_clipboard(os) - return function() - local filepath = vim.fn.expand('%:p') - if os == 'linux' then - local home_dir = vim.fn.expand('~') - filepath = filepath:gsub(home_dir, '~') - elseif os == 'windows' then - local mnt = '/mnt/' - if filepath:sub(1, #mnt) == mnt then - filepath = filepath:sub(#mnt + 1, #mnt + 1) .. ':' .. filepath:sub(#mnt + 2) - else - filepath = '//wsl.localhost/openSUSE-Tumbleweed' .. filepath - end - filepath = filepath:gsub('/', '\\') - end - vim.fn.setreg('+', filepath) - end -end - -function RemoveClipboardCR() - local clipboard = vim.fn.getreg('+'):gsub('\r', '') - vim.fn.setreg('+', clipboard) -end - -local function paste() - RemoveClipboardCR() - local value = vim.fn.getreg('+') - if vim.fn.mode() == 'c' then - -- value = vim.split(value, '\n')[1] -- only use first line (default with normal pasting) - value = value:gsub('\n', ' ') -- replace newlines with spaces - vim.api.nvim_feedkeys(value, 'c', false) - else - vim.api.nvim_put(vim.split(value, '\n'), 'c', false, true) - end -end - --- "Greatest Keymap ever" - ThePrimeagen --- https://www.youtube.com/watch?v=qZO9A5F6BZs&list=PLm323Lc7iSW_wuxqmKx_xxNtJC_hJbQ7R&index=4 -set('x', 'p', 'lua RemoveClipboardCR()"_dP') - -set({ 'n', 'x' }, 'p', 'lua RemoveClipboardCR()p', { noremap = true }) -set({ 'n', 'x' }, 'P', 'lua RemoveClipboardCR()P', { noremap = true }) - --- Move lines around -set('n', '', ":m .+1", { noremap = true }) -set('n', '', ":m .-2", { noremap = true }) -set('v', '', ":m '>+1gv", { noremap = true }) -set('v', '', ":m '<-2gv", { noremap = true }) - --- Misc -set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) -set('i', '', '', { desc = 'Ctrl + Backspace to delete word' }) -set('n', '', 'nohlsearch', silent) -set({ 'i', 'c' }, '', paste) -set('n', 'z', toggle_zen, { desc = '[Z]en Mode', silent = true }) -unbind({ 'i', 'n', 'v' }, '') - -set('n', 'U', 'redo') -set('i', '', 'undo') -set({ 'i', 'n', 'v' }, '', 'wqa') -set('n', 'yp', yank_filepath_to_clipboard('linux'), { desc = '[Y]oink File [P]ath (linux)' }) -set('n', 'yP', yank_filepath_to_clipboard('windows'), { desc = '[Y]oink File [P]ath (windows)' }) - --- Window Navigation - NO NEED BECAUSE IT CONFLICTS WITH TMUX --- set('n', '', '', { desc = 'Move focus to the left window' }) --- set('n', '', '', { desc = 'Move focus to the down window' }) --- set('n', '', '', { desc = 'Move focus to the up window' }) --- set('n', '', '', { desc = 'Move focus to the right window' }) - --- Window resizing -local resize = 2 -set({ 'n', 't' }, '', string.format('vertical resize -%d', resize), { desc = 'Resize Left' }) -set({ 'n', 't' }, '', string.format('resize -%d', resize), { desc = 'Resize Up' }) -set({ 'n', 't' }, '', string.format('resize +%d', resize), { desc = 'Resize Down' }) -set({ 'n', 't' }, '', string.format('vertical resize +%d', resize), { desc = 'Resize Right' }) - --- Keep selection after < and > in visual mode -set('v', '<', '', '>gv') --- Execute lua file or line -set('n', 'x', '.lua', { desc = 'Execute the current line' }) -set('n', 'x', 'source %', { desc = 'Execute the current file' }) - --- Reformats file using lsp -set('n', '=', vim.lsp.buf.format, { desc = 'Format File' }) -- cgit v1.3.1