From e738954f467b0ea07b8806df54d30e075fd9be92 Mon Sep 17 00:00:00 2001 From: winston Date: Sun, 12 Mar 2023 01:04:48 +0100 Subject: [PATCH] refactor(nvim): split init & config --- home/apps/neovim/init.lua | 97 +------------------ home/apps/neovim/lazy-lock.json | 2 +- home/apps/neovim/lua/config/autocmds.lua | 27 ++++++ .../lua/{plugins.lua => config/init.lua} | 68 +------------ .../lua/{binds.lua => config/mappings.lua} | 0 home/apps/neovim/lua/config/options.lua | 63 ++++++++++++ home/apps/neovim/lua/config/plugins.lua | 71 ++++++++++++++ home/apps/neovim/lua/config/vscode.lua | 4 + 8 files changed, 174 insertions(+), 158 deletions(-) create mode 100644 home/apps/neovim/lua/config/autocmds.lua rename home/apps/neovim/lua/{plugins.lua => config/init.lua} (72%) rename home/apps/neovim/lua/{binds.lua => config/mappings.lua} (100%) create mode 100644 home/apps/neovim/lua/config/options.lua create mode 100644 home/apps/neovim/lua/config/plugins.lua create mode 100644 home/apps/neovim/lua/config/vscode.lua diff --git a/home/apps/neovim/init.lua b/home/apps/neovim/init.lua index 43f0402..4b7e1f9 100644 --- a/home/apps/neovim/init.lua +++ b/home/apps/neovim/init.lua @@ -1,94 +1,5 @@ -vim.g.mapleader = " " --- netrw is handled by nvim-tree -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 --- true colors -vim.o.termguicolors = true -vim.o.cmdheight = 0 --- line numbers -vim.o.mouse = "nv" -vim.o.number = true -vim.o.relativenumber = true --- scroll offsets -vim.o.scrolloff = 5 -vim.o.sidescrolloff = 15 --- always show status -vim.o.laststatus = 3 --- hide tab line -vim.o.showtabline = 0 -vim.g.termguicolors = false --- completion height -vim.o.pumheight = 15 --- split directions -vim.o.splitbelow = true -vim.o.splitright = true -vim.o.wrap = false --- redefine word boundaries - '_' is a word separator, this helps with snake_case -vim.opt.iskeyword:remove("_") --- indentations settings -vim.o.shiftwidth = 2 -vim.o.tabstop = 2 -vim.o.softtabstop = 0 -vim.o.expandtab = true -vim.o.signcolumn = "yes:1" -vim.opt.shortmess:append("sI") --- double box drawing characters for splits -vim.opt.fillchars:append({ - horiz = "═", - horizup = "╩", - horizdown = "╦", - vert = "║", - vertright = "╠", - vertleft = "╣", - verthoriz = "╬", -}) - -pcall(require, "plugins") -pcall(require, "binds") - -vim.api.nvim_create_autocmd("VimResized", { - pattern = "*", - command = "wincmd =", - desc = "Automatically resize windows when the host window size changes.", -}) - -vim.api.nvim_create_autocmd("TextYankPost", { - pattern = "*", - callback = function() - vim.highlight.on_yank({ higroup = "IncSearch", timeout = 200 }) - end, - desc = "Highlight yanked text", -}) - -local trnuGroup = vim.api.nvim_create_augroup("toggleRnu", {}) -vim.api.nvim_create_autocmd("InsertEnter,BufLeave,WinLeave,FocusLost", { - callback = function() - vim.opt_local.relativenumber = false - end, - group = trnuGroup, -}) -vim.api.nvim_create_autocmd("InsertLeave,BufEnter,WinEnter,FocusGained", { - callback = function() - vim.opt_local.relativenumber = true - end, - group = trnuGroup, -}) - -if vim.g.neovide then - vim.g.neovide_refresh_rate = 60 - vim.g.neovide_refresh_rate_idle = 5 - vim.g.neovide_cursor_vfx_mode = "ripple" - vim.g.neovide_scroll_animation_length = 0.3 - vim.g.neovide_input_macos_alt_is_meta = true - vim.g.neovide_hide_mouse_when_typing = true - vim.keymap.set( - "n", - "", - ":let g:neovide_fullscreen = !g:neovide_fullscreen", - { - noremap = true, - silent = true, - } - ) - vim.opt.guifont = { "BerkeleyMono Nerd Font", "h14", "#e-subpixelantialias" } +if vim.g.vscode then + pcall(require, "config.vscode") +else + require("config") end diff --git a/home/apps/neovim/lazy-lock.json b/home/apps/neovim/lazy-lock.json index 6a0df88..3cc620c 100644 --- a/home/apps/neovim/lazy-lock.json +++ b/home/apps/neovim/lazy-lock.json @@ -40,7 +40,7 @@ "nvim-navic": { "branch": "master", "commit": "cdd24539bcf114a499827e9b32869fe74836efe7" }, "nvim-surround": { "branch": "main", "commit": "177c95c12542cf20a422b19a87ba1ae80254445a" }, "nvim-tree.lua": { "branch": "master", "commit": "bbb6d4891009de7dab05ad8fc2d39f272d7a751c" }, - "nvim-treesitter": { "branch": "master", "commit": "11b2d430e6f501e29e6851aaf1bd6fa338072be6" }, + "nvim-treesitter": { "branch": "master", "commit": "079a50f66ea9f2d3b9827bdba82ba3b255155621" }, "nvim-ts-autotag": { "branch": "main", "commit": "fdefe46c6807441460f11f11a167a2baf8e4534b" }, "nvim-ts-rainbow2": { "branch": "master", "commit": "6bcb1472c321a15eef5a7a015b4fefa8758e6513" }, "nvim-web-devicons": { "branch": "master", "commit": "4af94fec29f508159ceab5413383e5dedd6c24e3" }, diff --git a/home/apps/neovim/lua/config/autocmds.lua b/home/apps/neovim/lua/config/autocmds.lua new file mode 100644 index 0000000..5aa3b12 --- /dev/null +++ b/home/apps/neovim/lua/config/autocmds.lua @@ -0,0 +1,27 @@ +vim.api.nvim_create_autocmd("VimResized", { + pattern = "*", + command = "wincmd =", + desc = "Automatically resize windows when the host window size changes.", +}) + +vim.api.nvim_create_autocmd("TextYankPost", { + pattern = "*", + callback = function() + vim.highlight.on_yank({ higroup = "IncSearch", timeout = 200 }) + end, + desc = "Highlight yanked text", +}) + +local trnuGroup = vim.api.nvim_create_augroup("toggleRnu", {}) +vim.api.nvim_create_autocmd("InsertEnter,BufLeave,WinLeave,FocusLost", { + callback = function() + vim.opt_local.relativenumber = false + end, + group = trnuGroup, +}) +vim.api.nvim_create_autocmd("InsertLeave,BufEnter,WinEnter,FocusGained", { + callback = function() + vim.opt_local.relativenumber = true + end, + group = trnuGroup, +}) diff --git a/home/apps/neovim/lua/plugins.lua b/home/apps/neovim/lua/config/init.lua similarity index 72% rename from home/apps/neovim/lua/plugins.lua rename to home/apps/neovim/lua/config/init.lua index f433549..cdb2a4d 100644 --- a/home/apps/neovim/lua/plugins.lua +++ b/home/apps/neovim/lua/config/init.lua @@ -1,15 +1,6 @@ -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "--single-branch", - "https://github.com/folke/lazy.nvim.git", - lazypath, - }) -end -vim.opt.runtimepath:prepend(lazypath) +require("config.autocmds") +require("config.mappings") +require("config.options") local plugins = { { "catppuccin/nvim", name = "catppuccin" }, @@ -157,55 +148,4 @@ local plugins = { { "nvim-neorg/neorg", build = ":Neorg sync-parsers" }, } -require("lazy").setup(plugins, { - install = { colorscheme = { "catppuccin" } }, - performance = { - rtp = { - disabled_plugins = { - "2html_plugin", - "bugreport", - "compiler", - "ftplugin", - "fzf", - "getscript", - "getscriptPlugin", - "gzip", - "logipat", - "matchit", - "netrw", - "netrwFileHandlers", - "netrwPlugin", - "netrwSettings", - "optwin", - "rplugin", - "rrhelper", - "spellfile_plugin", - "synmenu", - "syntax", - "tar", - "tarPlugin", - "tutor", - "vimball", - "vimballPlugin", - "zip", - "zipPlugin", - }, - }, - }, - ui = { - icons = { - cmd = " ", - config = "", - event = " ", - ft = " ", - init = " ", - keys = " ", - plugin = " ", - runtime = " ", - source = " ", - start = " ", - task = " ", - }, - border = "double", - }, -}) +require("config.plugins").setup(plugins) diff --git a/home/apps/neovim/lua/binds.lua b/home/apps/neovim/lua/config/mappings.lua similarity index 100% rename from home/apps/neovim/lua/binds.lua rename to home/apps/neovim/lua/config/mappings.lua diff --git a/home/apps/neovim/lua/config/options.lua b/home/apps/neovim/lua/config/options.lua new file mode 100644 index 0000000..7c1e168 --- /dev/null +++ b/home/apps/neovim/lua/config/options.lua @@ -0,0 +1,63 @@ +vim.g.mapleader = " " +-- netrw is handled by nvim-tree +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 +-- true colors +vim.o.termguicolors = true +vim.o.cmdheight = 0 +-- line numbers +vim.o.mouse = "nv" +vim.o.number = true +vim.o.relativenumber = true +-- scroll offsets +vim.o.scrolloff = 5 +vim.o.sidescrolloff = 15 +-- always show status +vim.o.laststatus = 3 +-- hide tab line +vim.o.showtabline = 0 +vim.g.termguicolors = false +-- completion height +vim.o.pumheight = 15 +-- split directions +vim.o.splitbelow = true +vim.o.splitright = true +vim.o.wrap = false +-- redefine word boundaries - '_' is a word separator, this helps with snake_case +vim.opt.iskeyword:remove("_") +-- indentations settings +vim.o.shiftwidth = 2 +vim.o.tabstop = 2 +vim.o.softtabstop = 0 +vim.o.expandtab = true +vim.o.signcolumn = "yes:1" +vim.opt.shortmess:append("sI") +-- double box drawing characters for splits +vim.opt.fillchars:append({ + horiz = "═", + horizup = "╩", + horizdown = "╦", + vert = "║", + vertright = "╠", + vertleft = "╣", + verthoriz = "╬", +}) + +if vim.g.neovide then + vim.g.neovide_refresh_rate = 60 + vim.g.neovide_refresh_rate_idle = 5 + vim.g.neovide_cursor_vfx_mode = "ripple" + vim.g.neovide_scroll_animation_length = 0.3 + vim.g.neovide_input_macos_alt_is_meta = true + vim.g.neovide_hide_mouse_when_typing = true + vim.keymap.set( + "n", + "", + ":let g:neovide_fullscreen = !g:neovide_fullscreen", + { + noremap = true, + silent = true, + } + ) + vim.opt.guifont = { "BerkeleyMono Nerd Font", "h14", "#e-subpixelantialias" } +end diff --git a/home/apps/neovim/lua/config/plugins.lua b/home/apps/neovim/lua/config/plugins.lua new file mode 100644 index 0000000..e7466cb --- /dev/null +++ b/home/apps/neovim/lua/config/plugins.lua @@ -0,0 +1,71 @@ +local M = {} + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not 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(vim.env.LAZY or lazypath) + +M.setup = function(plugins) + require("lazy").setup(plugins, { + install = { colorscheme = { "catppuccin" } }, + performance = { + rtp = { + disabled_plugins = { + "2html_plugin", + "bugreport", + "compiler", + "ftplugin", + "fzf", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "matchit", + "netrw", + "netrwFileHandlers", + "netrwPlugin", + "netrwSettings", + "optwin", + "rplugin", + "rrhelper", + "spellfile_plugin", + "synmenu", + "syntax", + "tar", + "tarPlugin", + "tutor", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + }, + }, + }, + ui = { + icons = { + cmd = " ", + config = "", + event = " ", + ft = " ", + init = " ", + keys = " ", + plugin = " ", + runtime = " ", + source = " ", + start = " ", + task = " ", + }, + border = "double", + }, + }) +end + +return M diff --git a/home/apps/neovim/lua/config/vscode.lua b/home/apps/neovim/lua/config/vscode.lua new file mode 100644 index 0000000..a1e4c66 --- /dev/null +++ b/home/apps/neovim/lua/config/vscode.lua @@ -0,0 +1,4 @@ +require("config.mappings") +require("config.options") + +require("config.plugins").setup()