Skip to content

Commit

Permalink
Convert Neovim config to Lua (#21)
Browse files Browse the repository at this point in the history
## What

Convert Neovim configuration to Lua:
- migrate existing config (mostly) as-is
- re-evaluate each plugin:
  - `css-color` replaced with `highlight-colors`
  - `gitgutter` replaced with `gitsigns`
  - `systemcopy` removed
  • Loading branch information
vicnett authored Nov 8, 2024
1 parent 4e31b49 commit b597dac
Show file tree
Hide file tree
Showing 51 changed files with 331 additions and 268 deletions.
1 change: 0 additions & 1 deletion vim/after/ftplugin/sql.vim

This file was deleted.

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.

25 changes: 25 additions & 0 deletions vim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"bullets.vim": { "branch": "master", "commit": "2253f970e54320dbd76fd6bb4f5a0bf2436ce232" },
"csv.vim": { "branch": "master", "commit": "bddfcbadd788ab11eb3dbba4550a38a412fe3705" },
"gitsigns.nvim": { "branch": "main", "commit": "4daf7022f1481edf1e8fb9947df13bb07c18e89a" },
"lazy.nvim": { "branch": "main", "commit": "b1134ab82ee4279e31f7ddf7e34b2a99eb9b7bc9" },
"nvim-highlight-colors": { "branch": "main", "commit": "e967e2ba13fd4ca731b41d0e5cc1ac2edcd6e25e" },
"nvim-solarized-lua": { "branch": "master", "commit": "d69a263c97cbc765ca442d682b3283aefd61d4ac" },
"tcomment_vim": { "branch": "master", "commit": "48ab639a461d9b8344f7fee06cb69b4374863b13" },
"vim-easy-align": { "branch": "master", "commit": "9815a55dbcd817784458df7a18acacc6f82b1241" },
"vim-fugitive": { "branch": "master", "commit": "d4877e54cef67f5af4f950935b1ade19ed6b7370" },
"vim-gutentags": { "branch": "master", "commit": "aa47c5e29c37c52176c44e61c780032dfacef3dd" },
"vim-lastplace": { "branch": "master", "commit": "e58cb0df716d3c88605ae49db5c4741db8b48aa9" },
"vim-obsession": { "branch": "master", "commit": "ed9dfc7c2cc917ace8b24f4f9f80a91e05614b63" },
"vim-repeat": { "branch": "master", "commit": "65846025c15494983dafe5e3b46c8f88ab2e9635" },
"vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" },
"vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" },
"vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" },
"vim-textobj-codeblock": { "branch": "master", "commit": "7658826f1a13a2865fb65b64481c40968fd780c1" },
"vim-textobj-entire": { "branch": "master", "commit": "64a856c9dff3425ed8a863b9ec0a21dbaee6fb3a" },
"vim-textobj-indent": { "branch": "master", "commit": "deb76867c302f933c8f21753806cbf2d8461b548" },
"vim-textobj-line": { "branch": "master", "commit": "1a6780d29adcf7e464e8ddbcd0be0a9df1a37339" },
"vim-textobj-quotes": { "branch": "master", "commit": "cca9686acf7b21d930ced1801120ecf23fb2f995" },
"vim-textobj-user": { "branch": "master", "commit": "41a675ddbeefd6a93664a4dc52f302fe3086a933" },
"vim-wordmotion": { "branch": "master", "commit": "81d9bd298376ab0dc465c85d55afa4cb8d5f47a1" }
}
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
40 changes: 40 additions & 0 deletions vim/lua/config/lazy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- 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" },
},
-- colorscheme that will be used when installing plugins.
install = { colorscheme = { "solarized" } },
-- automatically check for plugin updates
checker = { enabled = true },
change_detection = {
-- automatically check for config file changes and reload the ui
enabled = true,
notify = false, -- don't get a notification when changes are found
},
})
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/bullets.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "bullets-vim/bullets.vim" },
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/csv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "chrisbra/csv.vim" },
}
11 changes: 11 additions & 0 deletions vim/lua/plugins/easy-align.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
return {
{
"junegunn/vim-easy-align",
keys = {
-- Start interactive EasyAlign in visual mode (e.g. vipga)
{ "ga", "<Plug>(EasyAlign)", mode = "x" },
-- Start interactive EasyAlign for a motion/text object (e.g. gaip)
{ "ga", "<Plug>(EasyAlign)" },
},
},
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/fugitive.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "tpope/vim-fugitive" },
}
62 changes: 62 additions & 0 deletions vim/lua/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
return {
{
"lewis6991/gitsigns.nvim",
lazy = false,
config = function()
require("gitsigns").setup({
on_attach = function(bufnr)
local gitsigns = require("gitsigns")

local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end

-- Navigation
map("n", "]c", function()
if vim.wo.diff then
vim.cmd.normal({ "]c", bang = true })
else
gitsigns.nav_hunk("next")
end
end)

map("n", "[c", function()
if vim.wo.diff then
vim.cmd.normal({ "[c", bang = true })
else
gitsigns.nav_hunk("prev")
end
end)

-- Actions
map("n", "<leader>hs", gitsigns.stage_hunk)
map("n", "<leader>hr", gitsigns.reset_hunk)
map("v", "<leader>hs", function()
gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
map("v", "<leader>hr", function()
gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
map("n", "<leader>hS", gitsigns.stage_buffer)
map("n", "<leader>hu", gitsigns.undo_stage_hunk)
map("n", "<leader>hR", gitsigns.reset_buffer)
map("n", "<leader>hp", gitsigns.preview_hunk)
map("n", "<leader>hb", function()
gitsigns.blame_line({ full = true })
end)
map("n", "<leader>tb", gitsigns.toggle_current_line_blame)
map("n", "<leader>hd", gitsigns.diffthis)
map("n", "<leader>hD", function()
gitsigns.diffthis("~")
end)
map("n", "<leader>td", gitsigns.toggle_deleted)

-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
})
end,
},
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/gutentags.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "ludovicchabant/vim-gutentags" },
}
12 changes: 12 additions & 0 deletions vim/lua/plugins/highlight-colors.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
return {
{
"brenoprata10/nvim-highlight-colors",
lazy = false,
config = function()
require("nvim-highlight-colors").setup({
render = "virtual",
enable_named_colors = false,
})
end,
},
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/lastplace.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "farmergreg/vim-lastplace" },
}
10 changes: 10 additions & 0 deletions vim/lua/plugins/nvim-solarized-lua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
return {
{
"ishan9299/nvim-solarized-lua",
lazy = false,
priority = 1000,
config = function()
vim.cmd([[ colorscheme solarized ]])
end,
},
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/obsession.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "tpope/vim-obsession" },
}
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" },
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/rhubarb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "tpope/vim-rhubarb" },
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/sleuth.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "tpope/vim-sleuth" },
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/surround.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "tpope/vim-surround" },
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/tcomment.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
{ "tomtom/tcomment_vim" },
}
11 changes: 11 additions & 0 deletions vim/lua/plugins/text-objects.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
return {
{
"kana/vim-textobj-user",
priority = 100,
},
{ "kana/vim-textobj-line" },
{ "kana/vim-textobj-indent" },
{ "kana/vim-textobj-entire" },
{ "beloglazov/vim-textobj-quotes" },
{ "christoomey/vim-textobj-codeblock" },
}
8 changes: 8 additions & 0 deletions vim/lua/plugins/wordmotion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
return {
{
"chaoren/vim-wordmotion",
init = function()
vim.g.wordmotion_prefix = "<leader>"
end,
},
}
7 changes: 0 additions & 7 deletions vim/rcfiles/abbreviations

This file was deleted.

Loading

0 comments on commit b597dac

Please sign in to comment.