diff --git a/vim/lua/config/formatting.lua b/vim/lua/config/formatting.lua index 6bda44f..5910f5e 100644 --- a/vim/lua/config/formatting.lua +++ b/vim/lua/config/formatting.lua @@ -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 diff --git a/vim/lua/config/general.lua b/vim/lua/config/general.lua index 5573312..34f20b5 100644 --- a/vim/lua/config/general.lua +++ b/vim/lua/config/general.lua @@ -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 diff --git a/vim/lua/config/lazy.lua b/vim/lua/config/lazy.lua index 0efd9a0..a4d2201 100644 --- a/vim/lua/config/lazy.lua +++ b/vim/lua/config/lazy.lua @@ -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 + }, }) diff --git a/vim/lua/config/visual.lua b/vim/lua/config/visual.lua index 4be32dc..f640b29 100644 --- a/vim/lua/config/visual.lua +++ b/vim/lua/config/visual.lua @@ -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 @@ -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 @@ -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, }) diff --git a/vim/lua/plugins/bullets.lua b/vim/lua/plugins/bullets.lua index 8599902..d432376 100644 --- a/vim/lua/plugins/bullets.lua +++ b/vim/lua/plugins/bullets.lua @@ -1,3 +1,3 @@ return { - { "bullets-vim/bullets.vim" }, + { "bullets-vim/bullets.vim" }, } diff --git a/vim/lua/plugins/csv.lua b/vim/lua/plugins/csv.lua index f318ded..995aa3f 100644 --- a/vim/lua/plugins/csv.lua +++ b/vim/lua/plugins/csv.lua @@ -1,3 +1,3 @@ return { - { "chrisbra/csv.vim" }, + { "chrisbra/csv.vim" }, } diff --git a/vim/lua/plugins/easy-align.lua b/vim/lua/plugins/easy-align.lua index 78d6456..1925cde 100644 --- a/vim/lua/plugins/easy-align.lua +++ b/vim/lua/plugins/easy-align.lua @@ -1,11 +1,11 @@ return { - { - "junegunn/vim-easy-align", - keys = { - -- Start interactive EasyAlign in visual mode (e.g. vipga) - { "ga", "(EasyAlign)", mode = "x" }, - -- Start interactive EasyAlign for a motion/text object (e.g. gaip) - { "ga", "(EasyAlign)" }, - }, - }, + { + "junegunn/vim-easy-align", + keys = { + -- Start interactive EasyAlign in visual mode (e.g. vipga) + { "ga", "(EasyAlign)", mode = "x" }, + -- Start interactive EasyAlign for a motion/text object (e.g. gaip) + { "ga", "(EasyAlign)" }, + }, + }, } diff --git a/vim/lua/plugins/fugitive.lua b/vim/lua/plugins/fugitive.lua index c0c159d..540c951 100644 --- a/vim/lua/plugins/fugitive.lua +++ b/vim/lua/plugins/fugitive.lua @@ -1,3 +1,3 @@ return { - { "tpope/vim-fugitive" }, + { "tpope/vim-fugitive" }, } diff --git a/vim/lua/plugins/gitsigns.lua b/vim/lua/plugins/gitsigns.lua index 3ac3b63..25908f9 100644 --- a/vim/lua/plugins/gitsigns.lua +++ b/vim/lua/plugins/gitsigns.lua @@ -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", "hs", gitsigns.stage_hunk) - map("n", "hr", gitsigns.reset_hunk) - map("v", "hs", function() - gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) - end) - map("v", "hr", function() - gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) - end) - map("n", "hS", gitsigns.stage_buffer) - map("n", "hu", gitsigns.undo_stage_hunk) - map("n", "hR", gitsigns.reset_buffer) - map("n", "hp", gitsigns.preview_hunk) - map("n", "hb", function() - gitsigns.blame_line({ full = true }) - end) - map("n", "tb", gitsigns.toggle_current_line_blame) - map("n", "hd", gitsigns.diffthis) - map("n", "hD", function() - gitsigns.diffthis("~") - end) - map("n", "td", gitsigns.toggle_deleted) + -- Actions + map("n", "hs", gitsigns.stage_hunk) + map("n", "hr", gitsigns.reset_hunk) + map("v", "hs", function() + gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end) + map("v", "hr", function() + gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end) + map("n", "hS", gitsigns.stage_buffer) + map("n", "hu", gitsigns.undo_stage_hunk) + map("n", "hR", gitsigns.reset_buffer) + map("n", "hp", gitsigns.preview_hunk) + map("n", "hb", function() + gitsigns.blame_line({ full = true }) + end) + map("n", "tb", gitsigns.toggle_current_line_blame) + map("n", "hd", gitsigns.diffthis) + map("n", "hD", function() + gitsigns.diffthis("~") + end) + map("n", "td", gitsigns.toggle_deleted) - -- Text object - map({ "o", "x" }, "ih", ":Gitsigns select_hunk") - end, - }) - end, - }, + -- Text object + map({ "o", "x" }, "ih", ":Gitsigns select_hunk") + end, + }) + end, + }, } diff --git a/vim/lua/plugins/gutentags.lua b/vim/lua/plugins/gutentags.lua index 64ddf65..ca95053 100644 --- a/vim/lua/plugins/gutentags.lua +++ b/vim/lua/plugins/gutentags.lua @@ -1,3 +1,3 @@ return { - { "ludovicchabant/vim-gutentags" }, + { "ludovicchabant/vim-gutentags" }, } diff --git a/vim/lua/plugins/highlight-colors.lua b/vim/lua/plugins/highlight-colors.lua index 2f2cdad..8b968e3 100644 --- a/vim/lua/plugins/highlight-colors.lua +++ b/vim/lua/plugins/highlight-colors.lua @@ -1,12 +1,12 @@ return { - { - "brenoprata10/nvim-highlight-colors", - lazy = false, - config = function() - require("nvim-highlight-colors").setup({ - render = "virtual", - enable_named_colors = false, - }) - end, - }, + { + "brenoprata10/nvim-highlight-colors", + lazy = false, + config = function() + require("nvim-highlight-colors").setup({ + render = "virtual", + enable_named_colors = false, + }) + end, + }, } diff --git a/vim/lua/plugins/lastplace.lua b/vim/lua/plugins/lastplace.lua index 05ab7a0..3f0c567 100644 --- a/vim/lua/plugins/lastplace.lua +++ b/vim/lua/plugins/lastplace.lua @@ -1,3 +1,3 @@ return { - { "farmergreg/vim-lastplace" }, + { "farmergreg/vim-lastplace" }, } diff --git a/vim/lua/plugins/nvim-solarized-lua.lua b/vim/lua/plugins/nvim-solarized-lua.lua index a97dbcd..a1088e8 100644 --- a/vim/lua/plugins/nvim-solarized-lua.lua +++ b/vim/lua/plugins/nvim-solarized-lua.lua @@ -1,10 +1,10 @@ return { - { - "ishan9299/nvim-solarized-lua", - lazy = false, - priority = 1000, - config = function() - vim.cmd([[ colorscheme solarized ]]) - end, - }, + { + "ishan9299/nvim-solarized-lua", + lazy = false, + priority = 1000, + config = function() + vim.cmd([[ colorscheme solarized ]]) + end, + }, } diff --git a/vim/lua/plugins/obsession.lua b/vim/lua/plugins/obsession.lua index 6e0c11f..1c98d58 100644 --- a/vim/lua/plugins/obsession.lua +++ b/vim/lua/plugins/obsession.lua @@ -1,3 +1,3 @@ return { - { "tpope/vim-obsession" }, + { "tpope/vim-obsession" }, } diff --git a/vim/lua/plugins/repeat.lua b/vim/lua/plugins/repeat.lua index da5d511..85763bc 100644 --- a/vim/lua/plugins/repeat.lua +++ b/vim/lua/plugins/repeat.lua @@ -1,3 +1,3 @@ return { - { "tpope/vim-repeat" }, + { "tpope/vim-repeat" }, } diff --git a/vim/lua/plugins/rhubarb.lua b/vim/lua/plugins/rhubarb.lua index a3d2674..ee0fc5b 100644 --- a/vim/lua/plugins/rhubarb.lua +++ b/vim/lua/plugins/rhubarb.lua @@ -1,3 +1,3 @@ return { - { "tpope/vim-rhubarb" }, + { "tpope/vim-rhubarb" }, } diff --git a/vim/lua/plugins/sleuth.lua b/vim/lua/plugins/sleuth.lua index 6c112dd..24a2dba 100644 --- a/vim/lua/plugins/sleuth.lua +++ b/vim/lua/plugins/sleuth.lua @@ -1,3 +1,3 @@ return { - { "tpope/vim-sleuth" }, + { "tpope/vim-sleuth" }, } diff --git a/vim/lua/plugins/surround.lua b/vim/lua/plugins/surround.lua index 0a05df2..06e53f0 100644 --- a/vim/lua/plugins/surround.lua +++ b/vim/lua/plugins/surround.lua @@ -1,3 +1,3 @@ return { - { "tpope/vim-surround" }, + { "tpope/vim-surround" }, } diff --git a/vim/lua/plugins/tcomment.lua b/vim/lua/plugins/tcomment.lua index d8bc85c..0efdd61 100644 --- a/vim/lua/plugins/tcomment.lua +++ b/vim/lua/plugins/tcomment.lua @@ -1,3 +1,3 @@ return { - { "tomtom/tcomment_vim" }, + { "tomtom/tcomment_vim" }, } diff --git a/vim/lua/plugins/text-objects.lua b/vim/lua/plugins/text-objects.lua index a3c93e2..6d03239 100644 --- a/vim/lua/plugins/text-objects.lua +++ b/vim/lua/plugins/text-objects.lua @@ -1,11 +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" }, + { + "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" }, } diff --git a/vim/lua/plugins/wordmotion.lua b/vim/lua/plugins/wordmotion.lua index 9419fda..48749cf 100644 --- a/vim/lua/plugins/wordmotion.lua +++ b/vim/lua/plugins/wordmotion.lua @@ -1,8 +1,8 @@ return { - { - "chaoren/vim-wordmotion", - init = function() - vim.g.wordmotion_prefix = "" - end, - }, + { + "chaoren/vim-wordmotion", + init = function() + vim.g.wordmotion_prefix = "" + end, + }, }