From 96e93d46ce8f3aa4f0ce6af7fbc135c59a21a2b2 Mon Sep 17 00:00:00 2001 From: FaultyBranches Date: Wed, 8 Jul 2026 14:05:40 -0500 Subject: [PATCH] feat: Adding in a custom statuscolumn formatting function and lua file --- nvim/lua/autocmds.lua | 53 ++++++++++++++++-------- nvim/lua/settings.lua | 84 +++++++++++++++++++-------------------- nvim/lua/statuscolumn.lua | 23 +++++++++++ 3 files changed, 102 insertions(+), 58 deletions(-) create mode 100644 nvim/lua/statuscolumn.lua diff --git a/nvim/lua/autocmds.lua b/nvim/lua/autocmds.lua index 30969e1..4ef67e9 100644 --- a/nvim/lua/autocmds.lua +++ b/nvim/lua/autocmds.lua @@ -1,22 +1,43 @@ +-- Autocommands for handling large files and switching between large file buffers and others +local largefile_group = vim.api.nvim_create_augroup('largefile', { clear = true }) +local max_filesize = 4 * (1024 * 1024) -- 4 MB + +local old_eventignore = false + -- Disables syntax, treesitter and folding on larger files vim.api.nvim_create_autocmd({ 'BufReadPre' }, { - pattern = '*', - group = vim.api.nvim_create_augroup('largefile', { clear = true }), - callback = function(args) - local max_filesize_MiB = 1 + group = largefile_group, + callback = function(ev) + if ev.file then + local status, size = pcall(function() return vim.loop.fs_stat(ev.file).size end) + if status and size > max_filesize then + old_eventignore = vim.o.eventignore + vim.o.eventignore = 'FileType' -- Reduce the calls for filetype specific plugins or syntax highlighting - local _, stats = pcall(function() - return vim.loop.fs_stat(vim.api.nvim_buf_get_name(args.buf)) - end) - - local file_size = math.floor(0.5 + (stats.size / (1024 * 1024))) - - if file_size > max_filesize_MiB then - print(string.format('File detected above %sMiB. Disabling syntax, treesitter, and folding.', max_filesize_MiB)) - vim.api.nvim_command('set foldmethod=manual') - vim.api.nvim_command('set noswapfile') - vim.api.nvim_command('set noundofile') - vim.api.nvim_command('set noloadplugins') + vim.b[ev.buf].is_large_file = true + vim.bo['bufhidden'] = 'unload' + vim.bo['buftype'] = 'nowrite' + vim.bo['swapfile'] = false + vim.bo['undofile'] = false + vim.bo['undolevels'] = -1 + end end end, }) + +vim.api.nvim_create_autocmd({ 'BufWinEnter' }, { + group = largefile_group, + callback = function(ev) + if old_eventignore ~= false then + vim.o.eventignore = old_eventignore -- Restore the old setting + old_eventignore = false + end + if vim.b[ev.buf].is_large_file then + vim.wo.wrap = false + else + vim.wo.wrap = vim.o.wrap -- Restore to default setting + end + end +}) + +-- End large file handling diff --git a/nvim/lua/settings.lua b/nvim/lua/settings.lua index 7a0e63c..96fc38f 100644 --- a/nvim/lua/settings.lua +++ b/nvim/lua/settings.lua @@ -1,47 +1,47 @@ -- Experimental -- vim.o.autocomplete = true -vim.opt.background = 'dark' -- Force a dark background for the colorscheme -vim.opt.clipboard = 'unnamed,unnamedplus' -- Use both the "*" and "+" registers for yanks and deletes (puts things in the system clipboard) -vim.opt.completeopt = 'fuzzy,menuone,noinsert,popup' -- Change how the completion menu is interacted with and displays -vim.opt.cursorcolumn = true -- Highlight the column the cursor is on -vim.opt.cursorline = true -- Highlight the line the cursor is on. -vim.opt.expandtab = true -- Expand tabs into spaces -vim.opt.fileformat = 'unix' -- Explicitly state that files should use the unix style EOL characters. -vim.opt.fillchars = 'fold: ' -- Sets the character that fills in a fold line (removes the dots) -vim.opt.foldcolumn = '0' -- Disables the foldcolumn -vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()' -- Uses Treesitter to determine where code folding should occur -vim.opt.foldlevel = 10 -- Sets the initial level at which folds will be closed -vim.opt.foldlevelstart = 4 -- Sets the initial fold level -vim.opt.foldmethod = 'expr' -- Attempt to use the syntax of a file to set folds. -vim.opt.foldnestmax = 4 -- Maximum level of fold nesting -vim.opt.formatoptions = 'cqrto' -- Allow auto insertion of comment lines when using o or O on a comment. -vim.opt.ignorecase = true -- Case-insensitive searching -vim.opt.list = true -- Show the listchars -vim.opt.listchars = 'tab:|·,trail:¬,extends:»,precedes:«,nbsp:+' -- Characters to display when showing whitespace -vim.opt.mouse = 'a' -- Enable mouse mode -vim.opt.number = true -- Show the line number in the gutter. -vim.opt.pumheight = 15 -- Maximum height of the auto complete floating window --- vim.opt.relativenumber = true -- Relative line number -vim.opt.sidescrolloff = 8 -- Side scrolling leadoff to keep the cursor a few characters from the screen edge instead of going all the way to it -vim.opt.shiftround = true -- Round indentation to shiftwidth -vim.opt.shiftwidth = 4 -- Number of spaces a tab counts for when converting tabs to spaces -vim.opt.shortmess = 'at' -- Abbreviations and truncation of cmd messages -vim.opt.showmatch = true -- Show matching bracket -vim.opt.signcolumn = 'yes' -- Always show the gutter -vim.opt.smartcase = true -- Keeps searches Case-insensitive until the search has an upper case character -vim.opt.smartindent = true -- Attempt to insert indentation to fit traditional languages. -vim.opt.softtabstop = 4 -- Number of spaces a tab counts for when converting tabs to spaces -vim.opt.splitbelow = true -- Split windows below when horizontal splitting -vim.opt.splitright = true -- Split windows right when vertical splitting -vim.opt.swapfile = false -- Disable the creation of swap files for open files -vim.opt.tabstop = 4 -- Setting the value of spaces per tab -vim.opt.termguicolors = true -- Enable the truecolor GUI colors in a terminal -vim.opt.undodir = os.getenv('HOME') .. '/.config/nvim/undodir' -- Set a specific undo file directory -vim.opt.undofile = true -- Enable undo files -vim.opt.updatetime = 300 -- Swapfile update time in milliseconds -vim.opt.wrap = false -- Do _not_ wrap lines +vim.opt.background = 'dark' -- Force a dark background for the colorscheme +vim.opt.clipboard = 'unnamed,unnamedplus' -- Use both the "*" and "+" registers for yanks and deletes (puts things in the system clipboard) +vim.opt.completeopt = 'fuzzy,menuone,noinsert,popup' -- Change how the completion menu is interacted with and displays +vim.opt.cursorcolumn = true -- Highlight the column the cursor is on +vim.opt.cursorline = true -- Highlight the line the cursor is on. +vim.opt.expandtab = true -- Expand tabs into spaces +vim.opt.fileformat = 'unix' -- Explicitly state that files should use the unix style EOL characters. +vim.opt.fillchars = 'fold: ' -- Sets the character that fills in a fold line (removes the dots) +vim.opt.foldcolumn = '0' -- Disables the foldcolumn +vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()' -- Uses Treesitter to determine where code folding should occur +vim.opt.foldlevel = 10 -- Sets the initial level at which folds will be closed +vim.opt.foldlevelstart = 4 -- Sets the initial fold level +vim.opt.foldmethod = 'expr' -- Attempt to use the syntax of a file to set folds. +vim.opt.foldnestmax = 4 -- Maximum level of fold nesting +vim.opt.formatoptions = 'cqrto' -- Allow auto insertion of comment lines when using o or O on a comment. +vim.opt.ignorecase = true -- Case-insensitive searching +vim.opt.list = true -- Show the listchars +vim.opt.listchars = 'tab:|·,trail:¬,extends:»,precedes:«,nbsp:+' -- Characters to display when showing whitespace +vim.opt.mouse = 'a' -- Enable mouse mode +vim.opt.number = true -- Show the line number in the gutter. +vim.opt.pumheight = 15 -- Maximum height of the auto complete floating window +vim.opt.sidescrolloff = 8 -- Side scrolling leadoff to keep the cursor a few characters from the screen edge instead of going all the way to it +vim.opt.shiftround = true -- Round indentation to shiftwidth +vim.opt.shiftwidth = 4 -- Number of spaces a tab counts for when converting tabs to spaces +vim.opt.shortmess = 'at' -- Abbreviations and truncation of cmd messages +vim.opt.showmatch = true -- Show matching bracket +vim.opt.signcolumn = 'yes' -- Always show the gutter +vim.opt.smartcase = true -- Keeps searches Case-insensitive until the search has an upper case character +vim.opt.smartindent = true -- Attempt to insert indentation to fit traditional languages. +vim.opt.softtabstop = 4 -- Number of spaces a tab counts for when converting tabs to spaces +vim.opt.splitbelow = true -- Split windows below when horizontal splitting +vim.opt.splitright = true -- Split windows right when vertical splitting +vim.opt.statuscolumn = "%!v:lua.require('statuscolumn').statusColumn()" -- Formatting for the statuscolumn (and gutter) +vim.opt.swapfile = false -- Disable the creation of swap files for open files +vim.opt.tabstop = 4 -- Setting the value of spaces per tab +vim.opt.termguicolors = true -- Enable the truecolor GUI colors in a terminal +vim.opt.undodir = os.getenv('HOME') .. '/.config/nvim/undodir' -- Set a specific undo file directory +vim.opt.undofile = true -- Enable undo files +vim.opt.updatetime = 300 -- Swapfile update time in milliseconds +vim.opt.wrap = false -- Do _not_ wrap lines vim.g.netrw_banner = 0 -vim.g.netrw_liststyle = 3 -- Use the tree style display for netrw directory listings -vim.g.netrw_winsize = 25 -- Percentage based pane size for directory exploring +vim.g.netrw_liststyle = 3 -- Use the tree style display for netrw directory listings +vim.g.netrw_winsize = 25 -- Percentage based pane size for directory exploring diff --git a/nvim/lua/statuscolumn.lua b/nvim/lua/statuscolumn.lua new file mode 100644 index 0000000..a1a03c3 --- /dev/null +++ b/nvim/lua/statuscolumn.lua @@ -0,0 +1,23 @@ +local statuscolumn = {} + +statuscolumn.border = function () + return '│' +end + +statuscolumn.numbers = function (config) + return string.format('%-3s %2s ', vim.v.lnum, vim.v.relnum) +end + +statuscolumn.statusColumn = function() + local column_text = '' + + column_text = table.concat({ + '%s', + statuscolumn.numbers(), + statuscolumn.border(), + }) + + return column_text +end + +return statuscolumn