From 3c4f03c439369bca263dcf410ff75049707ad55a Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Wed, 24 Jul 2024 14:45:21 +0300 Subject: refactor(neovim): moved plugin/ files to lua/custom/config --- .config/nvim/init.lua | 8 +++++ .config/nvim/lazy-lock.json | 1 - .config/nvim/lua/custom/config/autocmds.lua | 16 +++++++++ .config/nvim/lua/custom/config/keymaps.lua | 53 +++++++++++++++++++++++++++++ .config/nvim/lua/custom/config/options.lua | 46 +++++++++++++++++++++++++ .config/nvim/plugin/autocmds.lua | 16 --------- .config/nvim/plugin/keymaps.lua | 53 ----------------------------- .config/nvim/plugin/options.lua | 46 ------------------------- 8 files changed, 123 insertions(+), 116 deletions(-) create mode 100644 .config/nvim/lua/custom/config/autocmds.lua create mode 100644 .config/nvim/lua/custom/config/keymaps.lua create mode 100644 .config/nvim/lua/custom/config/options.lua delete mode 100644 .config/nvim/plugin/autocmds.lua delete mode 100644 .config/nvim/plugin/keymaps.lua delete mode 100644 .config/nvim/plugin/options.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index c752ac2..5107b3c 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,7 +2,15 @@ vim.loader.enable() vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' + +require('custom.config.options') +vim.schedule(function() + require('custom.config.keymaps') + require('custom.config.autocmds') +end) + local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +---@diagnostic disable-next-line: undefined-field if not (vim.uv or vim.loop).fs_stat(lazypath) then vim.fn.system({ 'git', diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 78b6832..490d974 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -4,7 +4,6 @@ "alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" }, "auto-save.nvim": { "branch": "main", "commit": "5fe9ab0c42f0457f2a973e814a6352b8eeb04730" }, "auto-session": { "branch": "main", "commit": "08c279882d4117a3e6ade1a014f7cf4af7c34fec" }, - "buffer-vacuum": { "branch": "main", "commit": "9c20a7f1db027d0f3411072546794f4d37ab5bdf" }, "buffer_manager.nvim": { "branch": "main", "commit": "fd36131b2b3e0f03fd6353ae2ffc88cf920b3bbb" }, "ccc.nvim": { "branch": "main", "commit": "4fb5abaef2f2e0540fe22d4d74a9841205fff9e4" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, diff --git a/.config/nvim/lua/custom/config/autocmds.lua b/.config/nvim/lua/custom/config/autocmds.lua new file mode 100644 index 0000000..a9a9dc0 --- /dev/null +++ b/.config/nvim/lua/custom/config/autocmds.lua @@ -0,0 +1,16 @@ +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking text', + group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, +}) + +vim.api.nvim_create_autocmd('BufEnter', { + desc = 'Disable newlines on commented lines from continuing the comment', + group = vim.api.nvim_create_augroup('disable-comments-continuation', { clear = true }), + callback = function() + -- vim.opt_local.formatoptions:remove('r') -- no comments on enter + vim.opt_local.formatoptions:remove('o') -- no comments on `o` or `O` + end, +}) diff --git a/.config/nvim/lua/custom/config/keymaps.lua b/.config/nvim/lua/custom/config/keymaps.lua new file mode 100644 index 0000000..bc5c73e --- /dev/null +++ b/.config/nvim/lua/custom/config/keymaps.lua @@ -0,0 +1,53 @@ +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 paste() + vim.fn.getreg('+') +end + +-- Misc +set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) +set('n', '', 'nohlsearch', silent) +set({ 'i', 'c' }, '', paste) -- FIXME: seems to not work +set('n', 'z', toggle_zen, { desc = '[Z]en Mode', silent = true }) +unbind({ 'i', 'n', 'v' }, '') + +set('n', 'U', 'redo') +set('i', '', 'undo') +set('i', '', 'undo') +set({ 'i', 'n', 'v' }, '', 'wqa') + +-- 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' }) diff --git a/.config/nvim/lua/custom/config/options.lua b/.config/nvim/lua/custom/config/options.lua new file mode 100644 index 0000000..9ee0fd0 --- /dev/null +++ b/.config/nvim/lua/custom/config/options.lua @@ -0,0 +1,46 @@ +-- System +vim.g.have_nerd_font = true +vim.opt.mouse = 'a' -- enable mouse +vim.opt.clipboard = 'unnamedplus' -- use system clipboard +vim.opt.undofile = true -- persist undo history by saving it to a file +vim.opt.exrc = true -- WARNING: runs .nvim.lua in cwd, which may execute arbitrary code + +-- Tab +vim.opt.expandtab = true -- convert tabs to spaces +vim.opt.tabstop = 4 -- number of visual spaces per TAB +vim.opt.softtabstop = 4 -- number of idfk tab when editing +vim.opt.shiftwidth = 4 -- number of spaces to insert on tab + +-- UI +vim.opt.signcolumn = 'auto:9' +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.cursorline = true -- highlight current line +vim.opt.splitright = true +vim.opt.splitbelow = true +vim.opt.showmode = false -- don't show mode, because lualine already does +vim.opt.list = true +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +vim.diagnostic.config({ signs = false }) -- disable signcolumn diagnostics +vim.opt.fillchars:append({ diff = '╱' }) -- nicer diff view for filled spaces + +-- Searching +vim.opt.hlsearch = true +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Misc +vim.opt_local.wrap = false +vim.opt.wrap = false +vim.opt.scrolloff = 8 +vim.opt.undofile = true +vim.opt.termguicolors = true +vim.opt.laststatus = 3 -- views can only be fully collapsed with the global statusline +vim.opt.splitkeep = 'screen' -- for edgy.nvim +vim.opt.inccommand = 'split' -- shows preview for commands like :%s/from/to + +-- Disable warnings for missing language providers +vim.g.loaded_node_provider = 0 +vim.g.loaded_perl_provider = 0 +vim.g.loaded_ruby_provider = 0 +vim.g.loaded_python3_provider = 0 diff --git a/.config/nvim/plugin/autocmds.lua b/.config/nvim/plugin/autocmds.lua deleted file mode 100644 index a9a9dc0..0000000 --- a/.config/nvim/plugin/autocmds.lua +++ /dev/null @@ -1,16 +0,0 @@ -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking text', - group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) - -vim.api.nvim_create_autocmd('BufEnter', { - desc = 'Disable newlines on commented lines from continuing the comment', - group = vim.api.nvim_create_augroup('disable-comments-continuation', { clear = true }), - callback = function() - -- vim.opt_local.formatoptions:remove('r') -- no comments on enter - vim.opt_local.formatoptions:remove('o') -- no comments on `o` or `O` - end, -}) diff --git a/.config/nvim/plugin/keymaps.lua b/.config/nvim/plugin/keymaps.lua deleted file mode 100644 index bc5c73e..0000000 --- a/.config/nvim/plugin/keymaps.lua +++ /dev/null @@ -1,53 +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 paste() - vim.fn.getreg('+') -end - --- Misc -set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) -set('n', '', 'nohlsearch', silent) -set({ 'i', 'c' }, '', paste) -- FIXME: seems to not work -set('n', 'z', toggle_zen, { desc = '[Z]en Mode', silent = true }) -unbind({ 'i', 'n', 'v' }, '') - -set('n', 'U', 'redo') -set('i', '', 'undo') -set('i', '', 'undo') -set({ 'i', 'n', 'v' }, '', 'wqa') - --- 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' }) diff --git a/.config/nvim/plugin/options.lua b/.config/nvim/plugin/options.lua deleted file mode 100644 index 9ee0fd0..0000000 --- a/.config/nvim/plugin/options.lua +++ /dev/null @@ -1,46 +0,0 @@ --- System -vim.g.have_nerd_font = true -vim.opt.mouse = 'a' -- enable mouse -vim.opt.clipboard = 'unnamedplus' -- use system clipboard -vim.opt.undofile = true -- persist undo history by saving it to a file -vim.opt.exrc = true -- WARNING: runs .nvim.lua in cwd, which may execute arbitrary code - --- Tab -vim.opt.expandtab = true -- convert tabs to spaces -vim.opt.tabstop = 4 -- number of visual spaces per TAB -vim.opt.softtabstop = 4 -- number of idfk tab when editing -vim.opt.shiftwidth = 4 -- number of spaces to insert on tab - --- UI -vim.opt.signcolumn = 'auto:9' -vim.opt.number = true -vim.opt.relativenumber = true -vim.opt.cursorline = true -- highlight current line -vim.opt.splitright = true -vim.opt.splitbelow = true -vim.opt.showmode = false -- don't show mode, because lualine already does -vim.opt.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -vim.diagnostic.config({ signs = false }) -- disable signcolumn diagnostics -vim.opt.fillchars:append({ diff = '╱' }) -- nicer diff view for filled spaces - --- Searching -vim.opt.hlsearch = true -vim.opt.ignorecase = true -vim.opt.smartcase = true - --- Misc -vim.opt_local.wrap = false -vim.opt.wrap = false -vim.opt.scrolloff = 8 -vim.opt.undofile = true -vim.opt.termguicolors = true -vim.opt.laststatus = 3 -- views can only be fully collapsed with the global statusline -vim.opt.splitkeep = 'screen' -- for edgy.nvim -vim.opt.inccommand = 'split' -- shows preview for commands like :%s/from/to - --- Disable warnings for missing language providers -vim.g.loaded_node_provider = 0 -vim.g.loaded_perl_provider = 0 -vim.g.loaded_ruby_provider = 0 -vim.g.loaded_python3_provider = 0 -- cgit v1.3.1