From dbbbb97b715f022251e2d1826967222b5865a949 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Mon, 8 Jul 2024 13:55:22 +0300 Subject: Neovim: refactored keymaps to , completions now have good keybindings and did some slight tweaks --- .config/nvim/TODO.md | 7 +--- .config/nvim/after/ftplugin/c.lua | 0 .config/nvim/after/ftplugin/go.lua | 0 .config/nvim/after/ftplugin/java.lua | 0 .config/nvim/after/ftplugin/lua.lua | 0 .config/nvim/after/ftplugin/rust.lua | 0 .config/nvim/init.lua | 21 ++++++++-- .config/nvim/lua/autocmds.lua | 18 -------- .config/nvim/lua/custom/completion.lua | 2 - .config/nvim/lua/custom/lsp.lua | 2 - .../nvim/lua/custom/plugins/TODO-completion.lua | 19 --------- .config/nvim/lua/custom/plugins/completion.lua | 16 +++++++ .config/nvim/lua/keymaps.lua | 46 -------------------- .config/nvim/lua/options.lua | 49 ---------------------- .config/nvim/lua/plugin-manager.lua | 15 ------- .config/nvim/plugin/autocmds.lua | 18 ++++++++ .config/nvim/plugin/keymaps.lua | 44 +++++++++++++++++++ .config/nvim/plugin/options.lua | 44 +++++++++++++++++++ .config/nvim/plugin/plugin-manager.lua | 0 19 files changed, 140 insertions(+), 161 deletions(-) create mode 100644 .config/nvim/after/ftplugin/c.lua create mode 100644 .config/nvim/after/ftplugin/go.lua create mode 100644 .config/nvim/after/ftplugin/java.lua create mode 100644 .config/nvim/after/ftplugin/lua.lua create mode 100644 .config/nvim/after/ftplugin/rust.lua delete mode 100644 .config/nvim/lua/autocmds.lua delete mode 100644 .config/nvim/lua/custom/plugins/TODO-completion.lua create mode 100644 .config/nvim/lua/custom/plugins/completion.lua delete mode 100644 .config/nvim/lua/keymaps.lua delete mode 100644 .config/nvim/lua/options.lua delete mode 100644 .config/nvim/lua/plugin-manager.lua create mode 100644 .config/nvim/plugin/autocmds.lua create mode 100644 .config/nvim/plugin/keymaps.lua create mode 100644 .config/nvim/plugin/options.lua create mode 100644 .config/nvim/plugin/plugin-manager.lua diff --git a/.config/nvim/TODO.md b/.config/nvim/TODO.md index da82204..c2c3e6f 100644 --- a/.config/nvim/TODO.md +++ b/.config/nvim/TODO.md @@ -1,15 +1,12 @@ # Plans for the future -- TODO: Refactor stuff to `plugin` folder (keymaps and options) and also `after` folder for filetype-specific things -p.s if some1 reads this and gets triggered by folders, GET REKT - - TODO: Look into bufferline.nvim for "tabs" - TODO: Look at configuring Noice.nvim and decide if u like it or not - TODO: Look at buffer-management plugins that automatically delete old buffers (and also ways to close buffers without exiting nvim, and be able to exit nvim with 1 keypress) - TODO: Replace obsidian with Neorg - TODO: Add refactoring keys like iv for introduce variable, extract method, introduce constant etc -- TODO: Decided which outline-plugin to use (lspsaga or aerial, or smthing else) +- TODO: Decide which outline-plugin to use (lspsaga or aerial, or smthing else) - TODO: Finish configuring lsp saga (I think it has supertypes and stuff which aren't in the doc) - TODO: learn what dot repeat is @@ -25,8 +22,6 @@ A lightbulb somewhere ONLY if the cursor (not line) has a code action and ONLY i ## TODO: Completions and snippets Make my own snippets per file type HAVE ACTUAL GOOD SORTING FOR SNIPPETS (hopefully this is possible) -*when there is an lsp active, it shouldn't show any other types like regex -it should just show lsp stuff # Look at in the future diff --git a/.config/nvim/after/ftplugin/c.lua b/.config/nvim/after/ftplugin/c.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/after/ftplugin/go.lua b/.config/nvim/after/ftplugin/go.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/after/ftplugin/java.lua b/.config/nvim/after/ftplugin/java.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/after/ftplugin/lua.lua b/.config/nvim/after/ftplugin/lua.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/after/ftplugin/rust.lua b/.config/nvim/after/ftplugin/rust.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index ad6df15..49c5efe 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,4 +1,17 @@ -require('options') -require('keymaps') -require('autocmds') -require('plugin-manager') +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not (vim.uv or vim.loop).fs_stat(lazypath) then + vim.fn.system({ + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) +require('lazy').setup({ import = 'custom/plugins' }, { + change_detection = { notify = false }, +}) diff --git a/.config/nvim/lua/autocmds.lua b/.config/nvim/lua/autocmds.lua deleted file mode 100644 index 5272029..0000000 --- a/.config/nvim/lua/autocmds.lua +++ /dev/null @@ -1,18 +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('FileType', { --- group = vim.api.nvim_create_augroup('disable-auto-comment', { clear = true }), --- pattern = '*', --- callback = function() --- -- c - autowrap using textwidth | r - enter in insert mode | o - o/O in normal mode --- -- vim.opt.formatoptions:remove({ 'c', 'r', 'o' }) --- vim.opt.formatoptions:remove('o') --- -- vim.cmd('set formatoptions-=o') --- end, --- }) diff --git a/.config/nvim/lua/custom/completion.lua b/.config/nvim/lua/custom/completion.lua index 80c9531..04ae172 100644 --- a/.config/nvim/lua/custom/completion.lua +++ b/.config/nvim/lua/custom/completion.lua @@ -67,5 +67,3 @@ cmp.setup({ [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), }), }) - -print('Sourced completion.lua') diff --git a/.config/nvim/lua/custom/lsp.lua b/.config/nvim/lua/custom/lsp.lua index d534e22..929014d 100644 --- a/.config/nvim/lua/custom/lsp.lua +++ b/.config/nvim/lua/custom/lsp.lua @@ -97,5 +97,3 @@ vim.api.nvim_create_autocmd('LspAttach', { -- -- require('lsp_lines').setup() -- vim.diagnostic.config({ virtual_text = false }) - -print('Sourced lsp.lua') diff --git a/.config/nvim/lua/custom/plugins/TODO-completion.lua b/.config/nvim/lua/custom/plugins/TODO-completion.lua deleted file mode 100644 index 3f0ba3e..0000000 --- a/.config/nvim/lua/custom/plugins/TODO-completion.lua +++ /dev/null @@ -1,19 +0,0 @@ -return { - { - 'hrsh7th/nvim-cmp', - lazy = false, - priority = 100, - dependencies = { - -- 'onsails/lspkind.nvim', - -- 'hrsh7th/cmp-path', - -- 'hrsh7th/cmp-buffer', - 'hrsh7th/cmp-nvim-lsp', -- lsp source for nvim-cmp - 'saadparwaiz1/cmp_luasnip', -- snippets source for nvim-cmp - { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp' }, -- snippets plugin - }, - -- TODO: Move to setup opts - config = function() - require('custom.completion') - end, - }, -} diff --git a/.config/nvim/lua/custom/plugins/completion.lua b/.config/nvim/lua/custom/plugins/completion.lua new file mode 100644 index 0000000..5e0f2ef --- /dev/null +++ b/.config/nvim/lua/custom/plugins/completion.lua @@ -0,0 +1,16 @@ +return { + 'hrsh7th/nvim-cmp', + lazy = false, + priority = 100, + dependencies = { + -- 'onsails/lspkind.nvim', + -- 'hrsh7th/cmp-path', + -- 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-nvim-lsp', -- lsp source for nvim-cmp + 'saadparwaiz1/cmp_luasnip', -- snippets source for nvim-cmp + { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp' }, -- snippets plugin + }, + config = function() + require('custom.completion') + end, +} diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua deleted file mode 100644 index a48679e..0000000 --- a/.config/nvim/lua/keymaps.lua +++ /dev/null @@ -1,46 +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 - --- Misc -set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) -set('n', '', 'nohlsearch', silent) -set({ 'i', 'c' }, '', function() - vim.fn.getreg('+') -end) -set('n', 'z', function() - vim.cmd('Neotree close') - vim.cmd('Trouble todo close') - vim.cmd('UndotreeHide') -end, { desc = '[Z]en Mode', silent = true }) -unbind({ 'i', 'n', 'v' }, '') - -set('n', 'U', 'redo') -set('i', '', 'undo') - --- Window Navigation -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' }) - -print('Sourced keymaps.lua') diff --git a/.config/nvim/lua/options.lua b/.config/nvim/lua/options.lua deleted file mode 100644 index 0ff65b9..0000000 --- a/.config/nvim/lua/options.lua +++ /dev/null @@ -1,49 +0,0 @@ -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - --- 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 - --- 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 - --- Searching -vim.opt.hlsearch = true -vim.opt.ignorecase = true -vim.opt.smartcase = true - --- Misc -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 -vim.opt.formatoptions:remove('o') -- don't have `o` add a comment - --- 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 - -print('Sourced options.lua') diff --git a/.config/nvim/lua/plugin-manager.lua b/.config/nvim/lua/plugin-manager.lua deleted file mode 100644 index 970847e..0000000 --- a/.config/nvim/lua/plugin-manager.lua +++ /dev/null @@ -1,15 +0,0 @@ -local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' -if not (vim.uv or vim.loop).fs_stat(lazypath) then - vim.fn.system({ - 'git', - 'clone', - '--filter=blob:none', - 'https://github.com/folke/lazy.nvim.git', - '--branch=stable', - lazypath, - }) -end -vim.opt.rtp:prepend(lazypath) -require('lazy').setup({ import = 'custom/plugins' }, { - change_detection = { notify = false }, -}) diff --git a/.config/nvim/plugin/autocmds.lua b/.config/nvim/plugin/autocmds.lua new file mode 100644 index 0000000..5272029 --- /dev/null +++ b/.config/nvim/plugin/autocmds.lua @@ -0,0 +1,18 @@ +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('FileType', { +-- group = vim.api.nvim_create_augroup('disable-auto-comment', { clear = true }), +-- pattern = '*', +-- callback = function() +-- -- c - autowrap using textwidth | r - enter in insert mode | o - o/O in normal mode +-- -- vim.opt.formatoptions:remove({ 'c', 'r', 'o' }) +-- vim.opt.formatoptions:remove('o') +-- -- vim.cmd('set formatoptions-=o') +-- end, +-- }) diff --git a/.config/nvim/plugin/keymaps.lua b/.config/nvim/plugin/keymaps.lua new file mode 100644 index 0000000..ee34aa2 --- /dev/null +++ b/.config/nvim/plugin/keymaps.lua @@ -0,0 +1,44 @@ +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 + +-- Misc +set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) +set('n', '', 'nohlsearch', silent) +set({ 'i', 'c' }, '', function() + vim.fn.getreg('+') +end) +set('n', 'z', function() + vim.cmd('Neotree close') + vim.cmd('Trouble todo close') + vim.cmd('UndotreeHide') +end, { desc = '[Z]en Mode', silent = true }) +unbind({ 'i', 'n', 'v' }, '') + +set('n', 'U', 'redo') +set('i', '', 'undo') + +-- Window Navigation +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' }) diff --git a/.config/nvim/plugin/options.lua b/.config/nvim/plugin/options.lua new file mode 100644 index 0000000..ec56b43 --- /dev/null +++ b/.config/nvim/plugin/options.lua @@ -0,0 +1,44 @@ +-- 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 + +-- 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 + +-- Searching +vim.opt.hlsearch = true +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Misc +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 +vim.opt.formatoptions:remove('o') -- don't have `o` add a comment + +-- 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/plugin-manager.lua b/.config/nvim/plugin/plugin-manager.lua new file mode 100644 index 0000000..e69de29 -- cgit v1.3.1