Skip to content

Commit

Permalink
Refactor Neovim config using Lua and lazy.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
vicnett committed Nov 7, 2024
1 parent ef78551 commit b9c4690
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 150 deletions.
12 changes: 12 additions & 0 deletions vim/init.lua
Original file line number Diff line number Diff line change
@@ -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")
33 changes: 0 additions & 33 deletions vim/init.vim

This file was deleted.

6 changes: 6 additions & 0 deletions vim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -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" }
}
5 changes: 5 additions & 0 deletions vim/lua/config/abbreviations.lua
Original file line number Diff line number Diff line change
@@ -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')
22 changes: 22 additions & 0 deletions vim/lua/config/formatting.lua
Original file line number Diff line number Diff line change
@@ -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 <Enter> 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
18 changes: 18 additions & 0 deletions vim/lua/config/general.lua
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions vim/lua/config/lazy.lua
Original file line number Diff line number Diff line change
@@ -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 },
})
9 changes: 9 additions & 0 deletions vim/lua/config/remaps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Alt + j/k to move current line down/up in normal mode
vim.keymap.set("n", "<A-j>", ":m .+1<CR>==")
vim.keymap.set("n", "<A-k>", ":m .-2<CR>==")
-- in insert mode
vim.keymap.set("i", "<A-j>", "<Esc>:m .+1<CR>==gi")
vim.keymap.set("i", "<A-k>", "<Esc>:m .-2<CR>==gi")
-- and in visual mode
vim.keymap.set("v", "<A-j>", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "<A-k>", ":m '<-2<CR>gv=gv")
53 changes: 53 additions & 0 deletions vim/lua/config/visual.lua
Original file line number Diff line number Diff line change
@@ -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,
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/gitgutter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "airblade/vim-gitgutter", event = "VeryLazy" },
}
10 changes: 10 additions & 0 deletions vim/lua/plugins/neosolarized.lua
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/repeat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "tpope/vim-repeat", event = "VeryLazy" },
}
7 changes: 0 additions & 7 deletions vim/rcfiles/abbreviations

This file was deleted.

18 changes: 0 additions & 18 deletions vim/rcfiles/formatting

This file was deleted.

39 changes: 0 additions & 39 deletions vim/rcfiles/general

This file was deleted.

12 changes: 0 additions & 12 deletions vim/rcfiles/remaps

This file was deleted.

41 changes: 0 additions & 41 deletions vim/rcfiles/visual

This file was deleted.

0 comments on commit b9c4690

Please sign in to comment.