diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-05-19 19:46:22 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-05-19 19:46:22 +0200 |
| commit | 80f74b2f218ea622be2cdf791494b4d5f91bbd06 (patch) | |
| tree | b0758218bcc7d70cbdb51fbd8e9115f94f5693b6 | |
| parent | 19e20f1e23c5ba926a76957a1d20efcc83ff3fd2 (diff) | |
| download | nvim-config-80f74b2f218ea622be2cdf791494b4d5f91bbd06.tar.gz nvim-config-80f74b2f218ea622be2cdf791494b4d5f91bbd06.zip | |
refactor(nvim): single source of truth for per-ft formatting width
- vim.g.dotfiles.textwidth = { sh=80, lua=120, markdown=120, gitcommit=72 }
defined once in init.lua.
- bash/lua/markdown/gitcommit ftplugins + render-markdown read from it;
mdformat --wrap already follows vim.bo.textwidth.
- gitcommit gets an explicit textwidth line (was implicit runtime 72).
- Behavior unchanged; one number now propagates everywhere.
| -rw-r--r-- | after/ftplugin/bash.lua | 2 | ||||
| -rw-r--r-- | after/ftplugin/gitcommit.lua | 1 | ||||
| -rw-r--r-- | after/ftplugin/lua.lua | 2 | ||||
| -rw-r--r-- | after/ftplugin/markdown.lua | 2 | ||||
| -rw-r--r-- | init.lua | 7 | ||||
| -rw-r--r-- | plugin/50-markdown.lua | 2 |
6 files changed, 11 insertions, 5 deletions
diff --git a/after/ftplugin/bash.lua b/after/ftplugin/bash.lua index d46657d..6e10433 100644 --- a/after/ftplugin/bash.lua +++ b/after/ftplugin/bash.lua @@ -1,4 +1,4 @@ -vim.opt_local.textwidth = 80 -- gw wraps at this value +vim.opt_local.textwidth = vim.g.dotfiles.textwidth.sh -- gw wraps at this value vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth' vim.opt_local.complete = { "o", -- 'omnifunc' diff --git a/after/ftplugin/gitcommit.lua b/after/ftplugin/gitcommit.lua index fea0559..26cac51 100644 --- a/after/ftplugin/gitcommit.lua +++ b/after/ftplugin/gitcommit.lua @@ -1,3 +1,4 @@ +vim.opt_local.textwidth = vim.g.dotfiles.textwidth.gitcommit -- gw wraps at this value vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth' vim.opt_local.tabstop = 2 -- CommonMark expects two spaces for indentation vim.opt_local.shiftwidth = 0 diff --git a/after/ftplugin/lua.lua b/after/ftplugin/lua.lua index 756026e..05e4978 100644 --- a/after/ftplugin/lua.lua +++ b/after/ftplugin/lua.lua @@ -24,7 +24,7 @@ local function format() vim.fn.winrestview(view) end -vim.opt_local.textwidth = 120 -- gw wraps at this value +vim.opt_local.textwidth = vim.g.dotfiles.textwidth.lua -- gw wraps at this value vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth' vim.opt_local.complete = { "o", -- 'omnifunc' diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua index c7be170..c18397e 100644 --- a/after/ftplugin/markdown.lua +++ b/after/ftplugin/markdown.lua @@ -57,7 +57,7 @@ vim.opt_local.relativenumber = false vim.opt_local.signcolumn = "auto" vim.opt_local.foldcolumn = "0" -- -vim.opt_local.textwidth = 120 -- gw wraps at this value +vim.opt_local.textwidth = vim.g.dotfiles.textwidth.markdown -- gw wraps at this value vim.opt_local.foldlevel = 1 -- Replace concealed text with a character from `'listchars'` -- With `'foldmethod'` set to `expr` and `'foldlevel'` set to 2 fenced code blocks are concealed and completely invisible @@ -2,7 +2,12 @@ if vim.env.DOTFILES_DIR == nil then vim.notify("DOTFILES_DIR is not set!", vim.log.levels.WARN) end -vim.g.dotfiles = { augroup = vim.api.nvim_create_augroup("dotfiles", {}) } +vim.g.dotfiles = { + augroup = vim.api.nvim_create_augroup("dotfiles", {}), + -- Single source of truth for per-filetype formatting width + -- (textwidth → gw, mdformat --wrap, render-markdown block widths). + textwidth = { sh = 80, lua = 120, markdown = 120, gitcommit = 72 }, +} ------------------------------------------------------------------------------------------------------------------------ -- Local functions diff --git a/plugin/50-markdown.lua b/plugin/50-markdown.lua index 9642617..87a7838 100644 --- a/plugin/50-markdown.lua +++ b/plugin/50-markdown.lua @@ -17,7 +17,7 @@ require("nvim-treesitter").install({ "yaml", }) -local markdown_textwidth = 120 +local markdown_textwidth = vim.g.dotfiles.textwidth.markdown require("render-markdown").setup({ heading = { width = "block", min_width = markdown_textwidth }, code = { position = "center", sign = false, width = "block", min_width = markdown_textwidth / 2, left_margin = 2 }, |
