From b9c469014cd701d67cb2b1045cef2d97944f2ce0 Mon Sep 17 00:00:00 2001 From: Vincent Capelle Date: Wed, 6 Nov 2024 23:19:30 -0500 Subject: [PATCH] Refactor Neovim config using Lua and lazy.nvim --- vim/init.lua | 12 ++++++++ vim/init.vim | 33 -------------------- vim/lazy-lock.json | 6 ++++ vim/lua/config/abbreviations.lua | 5 +++ vim/lua/config/formatting.lua | 22 +++++++++++++ vim/lua/config/general.lua | 18 +++++++++++ vim/lua/config/lazy.lua | 29 +++++++++++++++++ vim/lua/config/remaps.lua | 9 ++++++ vim/lua/config/visual.lua | 53 ++++++++++++++++++++++++++++++++ vim/lua/plugins/gitgutter.lua | 3 ++ vim/lua/plugins/neosolarized.lua | 10 ++++++ vim/lua/plugins/repeat.lua | 3 ++ vim/rcfiles/abbreviations | 7 ----- vim/rcfiles/formatting | 18 ----------- vim/rcfiles/general | 39 ----------------------- vim/rcfiles/remaps | 12 -------- vim/rcfiles/visual | 41 ------------------------ 17 files changed, 170 insertions(+), 150 deletions(-) create mode 100644 vim/init.lua delete mode 100644 vim/init.vim create mode 100644 vim/lazy-lock.json create mode 100644 vim/lua/config/abbreviations.lua create mode 100644 vim/lua/config/formatting.lua create mode 100644 vim/lua/config/general.lua create mode 100644 vim/lua/config/lazy.lua create mode 100644 vim/lua/config/remaps.lua create mode 100644 vim/lua/config/visual.lua create mode 100644 vim/lua/plugins/gitgutter.lua create mode 100644 vim/lua/plugins/neosolarized.lua create mode 100644 vim/lua/plugins/repeat.lua delete mode 100644 vim/rcfiles/abbreviations delete mode 100644 vim/rcfiles/formatting delete mode 100644 vim/rcfiles/general delete mode 100644 vim/rcfiles/remaps delete mode 100644 vim/rcfiles/visual diff --git a/vim/init.lua b/vim/init.lua new file mode 100644 index 0000000..c6a778d --- /dev/null +++ b/vim/init.lua @@ -0,0 +1,12 @@ +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +-- Config files +require("config.general") +require("config.abbreviations") +require("config.formatting") +require("config.remaps") +require("config.visual") + +-- Plugin manager +require("config.lazy") diff --git a/vim/init.vim b/vim/init.vim deleted file mode 100644 index 057b20e..0000000 --- a/vim/init.vim +++ /dev/null @@ -1,33 +0,0 @@ -" Vimrc -" -" This file contains the minimal settings to set the foundation, with the -" majority of the configuration and settings living in files spread between -" vim/rcfiles and vim/rcplugins - -set nocompatible - -" Need to set the leader before defining any leader mappings -let mapleader = "\" - -function! s:SourceConfigFilesIn(directory) - let directory_splat = a:directory . '/*' - for config_file in split(glob(directory_splat), '\n') - if filereadable(config_file) - execute 'source' config_file - endif - endfor -endfunction - -let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' -if empty(glob(data_dir . '/autoload/plug.vim')) - silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' - autocmd VimEnter * PlugInstall --sync | source $MYVIMRC -endif - -call plug#begin('~/.vim/bundle') -call s:SourceConfigFilesIn('~/.dotfiles/vim/rcplugins') -call s:SourceConfigFilesIn('~/.vimrc.d/rcplugins') -call plug#end() - -call s:SourceConfigFilesIn('~/.dotfiles/vim/rcfiles') -call s:SourceConfigFilesIn('~/.vimrc.d/rcfiles') diff --git a/vim/lazy-lock.json b/vim/lazy-lock.json new file mode 100644 index 0000000..ccdfa9a --- /dev/null +++ b/vim/lazy-lock.json @@ -0,0 +1,6 @@ +{ + "NeoSolarized.nvim": { "branch": "master", "commit": "bdfcdd056c4c73b10fc6f42f0c2d0df839ff49ae" }, + "lazy.nvim": { "branch": "main", "commit": "b1134ab82ee4279e31f7ddf7e34b2a99eb9b7bc9" }, + "vim-gitgutter": { "branch": "main", "commit": "7b0b5098e3e57be86bb96cfbf2b8902381eef57c" }, + "vim-repeat": { "branch": "master", "commit": "65846025c15494983dafe5e3b46c8f88ab2e9635" } +} diff --git a/vim/lua/config/abbreviations.lua b/vim/lua/config/abbreviations.lua new file mode 100644 index 0000000..b2120c5 --- /dev/null +++ b/vim/lua/config/abbreviations.lua @@ -0,0 +1,5 @@ +-- Vertical split find +vim.keymap.set('ca', 'vsfind', 'vert sfind') + +-- Vertical split existing buffer +vim.keymap.set('ca', 'vsb', 'vert sbuffer') diff --git a/vim/lua/config/formatting.lua b/vim/lua/config/formatting.lua new file mode 100644 index 0000000..6bda44f --- /dev/null +++ b/vim/lua/config/formatting.lua @@ -0,0 +1,22 @@ +-- Formatting settings +---------------------- + +-- Set maximum line length +vim.opt.textwidth = 80 + +-- Formatting options: +-- j Remove comment leaders when joining lines (where it makes sense) +-- tc Auto-wrap in both text and comments +-- r Continue comment on new line when hitting in insert mode +-- o Continue comment on new line when hitting "o" or "O" +-- q Allow formatting comments with "gq" +-- l Don't automatically break the line if it was already longer than +-- 'textwidth' when the insert command started +-- 1 Don't break a line after a one-letter word; break it before it if possible +vim.opt.formatoptions = jtcroql1 + +-- 2 space indentation +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.shiftround = true +vim.opt.expandtab = true diff --git a/vim/lua/config/general.lua b/vim/lua/config/general.lua new file mode 100644 index 0000000..8b2d63a --- /dev/null +++ b/vim/lua/config/general.lua @@ -0,0 +1,18 @@ +-- General Vim Settings +-- -------------------- + +-- vim.g.python_indent = {} +-- vim.g.python_indent.open_paren = 'shiftwidth()' +-- vim.g.python_indent.closed_paren_align_last_line = v:false + +vim.g.python_indent = { + open_paren = 'shiftwidth()', + closed_paren_align_last_line = false, +} + +-- Fuzzy file finding +vim.opt.path:append '**' + +-- Assume POSIX-compliant shell syntax for highlighting purposes, when other +-- detection methods fail +vim.g.is_posix = 1 diff --git a/vim/lua/config/lazy.lua b/vim/lua/config/lazy.lua new file mode 100644 index 0000000..132c75f --- /dev/null +++ b/vim/lua/config/lazy.lua @@ -0,0 +1,29 @@ +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + +-- Setup lazy.nvim +require("lazy").setup({ + spec = { + -- import your plugins + { import = "plugins" }, + }, + -- Configure any other settings here. See the documentation for more details. + -- colorscheme that will be used when installing plugins. + install = { colorscheme = { "habamax" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) diff --git a/vim/lua/config/remaps.lua b/vim/lua/config/remaps.lua new file mode 100644 index 0000000..e919d41 --- /dev/null +++ b/vim/lua/config/remaps.lua @@ -0,0 +1,9 @@ +-- Alt + j/k to move current line down/up in normal mode +vim.keymap.set("n", "", ":m .+1==") +vim.keymap.set("n", "", ":m .-2==") +-- in insert mode +vim.keymap.set("i", "", ":m .+1==gi") +vim.keymap.set("i", "", ":m .-2==gi") +-- and in visual mode +vim.keymap.set("v", "", ":m '>+1gv=gv") +vim.keymap.set("v", "", ":m '<-2gv=gv") diff --git a/vim/lua/config/visual.lua b/vim/lua/config/visual.lua new file mode 100644 index 0000000..7550e2f --- /dev/null +++ b/vim/lua/config/visual.lua @@ -0,0 +1,53 @@ +-- Visual settings +------------------ + +-- Make it obvious where the textwidth limit is +vim.opt.colorcolumn = '+1' + +-- Display extra whitespace +vim.opt.list = true +vim.opt.listchars:append { + tab = "▏ ", + leadmultispace = "▏ ", + trail = ·, + nbsp = ·, + multispace = ·, +} + +-- Display relative line numbers, with absolute line number for current line +vim.opt.number = true +vim.opt.numberwidth = 5 +vim.opt.relativenumber = true + +-- Automatically turn off relative line numbers when not in focus +-- ... But also don't turn them on and off for help buffers! +local numbertogglegroup = + vim.api.nvim_create_augroup('numbertoggle', { clear = true }) +vim.api.nvim_create_autocmd({ 'BufEnter', 'FocusGained', 'InsertLeave' }, { + callback = function() + if vim.bo.filetype ~= 'help' then + vim.opt.relativenumber = true + end + end, + group = numbertogglegroup, + pattern = '*', +}) +vim.api.nvim_create_autocmd({ 'BufLeave', 'FocusLost', 'InsertEnter' }, { + callback = function() + vim.opt.relativenumber = false + end, + group = numbertogglegroup, + pattern = '*', +}) + +-- Open new split panes to right and bottom +vim.opt.splitbelow = true +vim.opt.splitright = true + +-- Ignore whitespace only changes in diff, always use vertical diffs +vim.opt.diffopt:append { + iwhite, + vertical, + 'linematch:60', + algorithm = histogram, +} diff --git a/vim/lua/plugins/gitgutter.lua b/vim/lua/plugins/gitgutter.lua new file mode 100644 index 0000000..bf3d9ea --- /dev/null +++ b/vim/lua/plugins/gitgutter.lua @@ -0,0 +1,3 @@ +return { + { "airblade/vim-gitgutter", event = "VeryLazy" }, +} diff --git a/vim/lua/plugins/neosolarized.lua b/vim/lua/plugins/neosolarized.lua new file mode 100644 index 0000000..2e9f276 --- /dev/null +++ b/vim/lua/plugins/neosolarized.lua @@ -0,0 +1,10 @@ +return { + { + "Tsuzat/NeoSolarized.nvim", + lazy = false, -- make sure we load this during startup if it is your main colorscheme + priority = 1000, -- make sure to load this before all the other start plugins + config = function() + vim.cmd [[ colorscheme NeoSolarized ]] + end + } +} diff --git a/vim/lua/plugins/repeat.lua b/vim/lua/plugins/repeat.lua new file mode 100644 index 0000000..56c3855 --- /dev/null +++ b/vim/lua/plugins/repeat.lua @@ -0,0 +1,3 @@ +return { + { "tpope/vim-repeat", event = "VeryLazy" }, +} diff --git a/vim/rcfiles/abbreviations b/vim/rcfiles/abbreviations deleted file mode 100644 index 49ed4da..0000000 --- a/vim/rcfiles/abbreviations +++ /dev/null @@ -1,7 +0,0 @@ -" Vertical split find -cabbrev vsfind vert sfind - -" Vertical split existing buffer -cabbrev vsb vert sbuffer - -" vim:ft=vim diff --git a/vim/rcfiles/formatting b/vim/rcfiles/formatting deleted file mode 100644 index f55d154..0000000 --- a/vim/rcfiles/formatting +++ /dev/null @@ -1,18 +0,0 @@ -" Formatting settings -"-------------------- - -set textwidth=80 - -" only enforce line length in comments, plus other options (see :h fo-table) -set formatoptions=jcroql1 - -" Softtabs, 2 spaces -set tabstop=2 -set shiftwidth=2 -set shiftround -set expandtab - -" Use one space, not two, after punctuation. -set nojoinspaces - -" vim:ft=vim diff --git a/vim/rcfiles/general b/vim/rcfiles/general deleted file mode 100644 index c2e7769..0000000 --- a/vim/rcfiles/general +++ /dev/null @@ -1,39 +0,0 @@ -" General Vim Settings -" -------------------- - -filetype plugin indent on -let g:python_indent = {} -let g:python_indent.open_paren = 'shiftwidth()' -let g:python_indent.closed_paren_align_last_line = v:false - -set backspace=2 " Backspace deletes like most programs in insert mode -set nobackup -set nowritebackup -set noswapfile -set history=9999 -set ruler " show the cursor position all the time -set showcmd " display incomplete commands -set incsearch " do incremental searching -set laststatus=2 " Always display the status line -set autowrite " Automatically :write before running commands -set mouse=a " Mouse scrolling support - -" Fuzzy file finding -set path+=** -set wildmenu - -" When the type of shell script is /bin/sh, assume a POSIX-compatible -" shell for syntax highlighting purposes. -let g:is_posix = 1 - -" Set spellfile to location that is guaranteed to exist, can be symlinked to -" Dropbox or kept in Git and managed outside of thoughtbot/dotfiles using rcm. -set spellfile=$HOME/.vim-spell-en.utf-8.add - -" Autocomplete with dictionary words when spell check is on -set complete+=kspell - -" Don't require saving before closing a buffer -set hidden - -" vim:ft=vim diff --git a/vim/rcfiles/remaps b/vim/rcfiles/remaps deleted file mode 100644 index 1e21b92..0000000 --- a/vim/rcfiles/remaps +++ /dev/null @@ -1,12 +0,0 @@ -" Alt + j/k to move current line down/up in normal mode -nnoremap :m .+1== -nnoremap :m .-2== -" in insert mode -inoremap :m .+1==gi -inoremap :m .-2==gi -" and in visual mode -vnoremap :m '>+1gv=gv -vnoremap :m '<-2gv=gv - -" vim:ft=vim - diff --git a/vim/rcfiles/visual b/vim/rcfiles/visual deleted file mode 100644 index d51dd2d..0000000 --- a/vim/rcfiles/visual +++ /dev/null @@ -1,41 +0,0 @@ -" Visual settings -"---------------- - -" Make it obvious where the textwidth limit is -set colorcolumn=+1 - -" Display extra whitespace -set list listchars=tab:\┃\ ,trail:·,nbsp:·,extends:»,precedes:«,multispace:· - -" Display relative line numbers, with absolute line number for current line -set number -set numberwidth=5 -set relativenumber -" Automatically turn off relative line numbers when not in focus -:augroup numbertoggle -: autocmd! -: autocmd BufEnter,FocusGained,InsertLeave * set relativenumber -: autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber -:augroup END - -" automatically rebalance windows on vim resize -autocmd VimResized * GoldenRatioResize - -" zoom a vim pane, = to re-balance -nnoremap - :wincmd _:wincmd \| -nnoremap = :wincmd = - -" Open new split panes to right and bottom -set splitbelow -set splitright - -" Ignore whitespace only changes in diff, always use vertical diffs -set diffopt+=iwhite -set diffopt+=vertical - -" floating windows -highlight VertSplit guibg=NONE -highlight NormalFloat guifg=#999999 guibg=#222222 -hi Pmenu guibg=#222222 guifg=#999999 - -" vim:ft=vim