Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indentation and tab/space indentation representation in Neovim #25

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions vim/lua/config/formatting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ vim.opt.textwidth = 80
-- 1 Don't break a line after a one-letter word; break it before it if possible
vim.opt.formatoptions = jtcroql1

-- 2 space indentation
-- Default to 2 space indentation
-- Note: vim-sleuth will dynamically adjust these based on context
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.shiftwidth = 0
vim.opt.softtabstop = -1
vim.opt.shiftround = true
vim.opt.expandtab = true
4 changes: 2 additions & 2 deletions vim/lua/config/general.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
-- vim.g.python_indent.closed_paren_align_last_line = v:false

vim.g.python_indent = {
open_paren = "shiftwidth()",
closed_paren_align_last_line = false,
open_paren = "shiftwidth()",
closed_paren_align_last_line = false,
}

-- Fuzzy file finding
Expand Down
62 changes: 31 additions & 31 deletions vim/lua/config/lazy.lua
Original file line number Diff line number Diff line change
@@ -1,40 +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
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
},
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
},
})
107 changes: 85 additions & 22 deletions vim/lua/config/visual.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,78 @@
vim.opt.colorcolumn = "+1"

-- Display extra whitespace
local vert_char = "▏"
vim.opt.list = true
vim.opt.listchars:append({
tab = "▏ ",
leadmultispace = "▏ ",
trail = "·",
nbsp = "·",
multispace = "·",
tab = vert_char .. "▏›",
trail = "·",
nbsp = "·",
multispace = "·",
})

-- Automatically adapt leadmultispace to current indentation settings, adapted
-- from:
-- https://github.com/gravndal/shiftwidth_leadmultispace.nvim/blob/master/plugin/shiftwidth_leadmultispace.lua
local char = "leadmultispace:" .. vert_char

local function lms(rep)
return char .. string.rep(" ", rep > 0 and rep - 1 or 0)
end

local function update(old, rep)
return old:gsub("leadmultispace:[^,]*", lms(rep))
end

local function update_curbuf()
for _, w in ipairs(vim.api.nvim_list_wins()) do
if vim.api.nvim_win_get_buf(w) == vim.api.nvim_get_current_buf() then
vim.wo[w].listchars = update(
vim.wo[w].listchars,
vim.bo.shiftwidth > 0 and vim.bo.shiftwidth or vim.bo.tabstop
)
end
end
end

local group = vim.api.nvim_create_augroup("ShiftwidthLeadmultispace", {})

-- Sync with 'shiftwidth'.
vim.api.nvim_create_autocmd("OptionSet", {
pattern = "shiftwidth,tabstop",
group = group,
callback = function()
if vim.v.option_type ~= "local" then
vim.go.listchars = update(
vim.go.listchars,
vim.go.shiftwidth > 0 and vim.go.shiftwidth or vim.go.tabstop
)
end
update_curbuf()
end,
})

-- Update 'listchars' when displaying buffer in a window.
vim.api.nvim_create_autocmd("BufWinEnter", {
group = group,
callback = function()
vim.wo.listchars = update(
vim.wo.listchars,
vim.bo.shiftwidth > 0 and vim.bo.shiftwidth or vim.bo.tabstop
)
end,
})

-- Handle cases where 'filetype' is set after BufWinEnter.
vim.api.nvim_create_autocmd("FileType", {
group = group,
callback = function()
update_curbuf()
end,
})

-- Set global default.
vim.opt_global.listchars:append(lms(vim.go.shiftwidth))

-- Display relative line numbers, with absolute line number for current line
vim.opt.number = true
vim.opt.numberwidth = 5
Expand All @@ -22,22 +85,22 @@ 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_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 = "*",
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 = "*",
callback = function()
vim.opt.relativenumber = false
end,
group = numbertogglegroup,
pattern = "*",
})

-- Open new split panes to right and bottom
Expand All @@ -46,8 +109,8 @@ vim.opt.splitright = true

-- Ignore whitespace only changes in diff, always use vertical diffs
vim.opt.diffopt:append({
iwhite,
vertical,
"linematch:60",
algorithm = histogram,
iwhite,
vertical,
"linematch:60",
algorithm = histogram,
})
2 changes: 1 addition & 1 deletion vim/lua/plugins/bullets.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return {
{ "bullets-vim/bullets.vim" },
{ "bullets-vim/bullets.vim" },
}
2 changes: 1 addition & 1 deletion vim/lua/plugins/csv.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return {
{ "chrisbra/csv.vim" },
{ "chrisbra/csv.vim" },
}
18 changes: 9 additions & 9 deletions vim/lua/plugins/easy-align.lua
Original file line number Diff line number Diff line change
@@ -1,11 +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)" },
},
},
{
"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)" },
},
},
}
2 changes: 1 addition & 1 deletion vim/lua/plugins/fugitive.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return {
{ "tpope/vim-fugitive" },
{ "tpope/vim-fugitive" },
}
110 changes: 55 additions & 55 deletions vim/lua/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
return {
{
"lewis6991/gitsigns.nvim",
lazy = false,
config = function()
require("gitsigns").setup({
on_attach = function(bufnr)
local gitsigns = require("gitsigns")
{
"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
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)
-- 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)
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)
-- 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,
},
-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
})
end,
},
}
2 changes: 1 addition & 1 deletion vim/lua/plugins/gutentags.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return {
{ "ludovicchabant/vim-gutentags" },
{ "ludovicchabant/vim-gutentags" },
}
Loading
Loading