From fedeedb070c1233b5bab8101778d1986e96e93b6 Mon Sep 17 00:00:00 2001 From: Henrik Bakken Date: Fri, 16 Oct 2026 14:16:28 +0200 Subject: [PATCH] nvim ftplugin tweaks --- CONFIG/nvim/{ => after}/ftplugin/fugitive.lua | 0 CONFIG/nvim/after/ftplugin/javascript.lua | 20 ++++++++++++++++++ CONFIG/nvim/after/ftplugin/lua.lua | 18 ++++++++++++++++ CONFIG/nvim/after/ftplugin/markdown.lua | 21 +++++++++++++++++++ CONFIG/nvim/after/ftplugin/python.lua | 19 +++++++++++++++++ CONFIG/nvim/ftplugin/javascript.lua | 4 ---- CONFIG/nvim/ftplugin/lua.lua | 4 ---- CONFIG/nvim/ftplugin/markdown.lua | 5 ----- CONFIG/nvim/ftplugin/python.lua | 4 ---- 9 files changed, 78 insertions(+), 17 deletions(-) rename CONFIG/nvim/{ => after}/ftplugin/fugitive.lua (100%) create mode 100644 CONFIG/nvim/after/ftplugin/javascript.lua create mode 100644 CONFIG/nvim/after/ftplugin/lua.lua create mode 100644 CONFIG/nvim/after/ftplugin/markdown.lua create mode 100644 CONFIG/nvim/after/ftplugin/python.lua delete mode 100644 CONFIG/nvim/ftplugin/javascript.lua delete mode 100644 CONFIG/nvim/ftplugin/lua.lua delete mode 100644 CONFIG/nvim/ftplugin/markdown.lua delete mode 100644 CONFIG/nvim/ftplugin/python.lua diff --git a/CONFIG/nvim/ftplugin/fugitive.lua b/CONFIG/nvim/after/ftplugin/fugitive.lua similarity index 100% rename from CONFIG/nvim/ftplugin/fugitive.lua rename to CONFIG/nvim/after/ftplugin/fugitive.lua diff --git a/CONFIG/nvim/after/ftplugin/javascript.lua b/CONFIG/nvim/after/ftplugin/javascript.lua new file mode 100644 index 0000000..5f3e201 --- /dev/null +++ b/CONFIG/nvim/after/ftplugin/javascript.lua @@ -0,0 +1,20 @@ +local bufname = vim.api.nvim_buf_get_name(0) +local filename_arg = bufname ~= "" and (" --stdin-filepath " .. vim.fn.shellescape(bufname)) or "" + +-- Indentation & Layout +vim.opt_local.colorcolumn = "100" +vim.opt_local.textwidth = 100 +vim.opt_local.tabstop = 4 +vim.opt_local.shiftwidth = 4 +vim.opt_local.softtabstop = 4 +vim.opt_local.expandtab = true + +-- Formatting Behavior +vim.opt_local.formatoptions:remove("t") -- Don't autowrap while typing +vim.opt_local.formatoptions:append("j") -- Remove comment markers when joining lines + +-- gq Formatters (Prettier fallback, LSP primary) +-- Prefers local/global binary first to avoid slow npx invocation overhead +local prettier_bin = vim.fn.executable("prettier") == 1 and "prettier" or "npx prettier" +vim.bo.formatprg = prettier_bin .. filename_arg +vim.bo.formatexpr = "v:lua.vim.lsp.formatexpr()" diff --git a/CONFIG/nvim/after/ftplugin/lua.lua b/CONFIG/nvim/after/ftplugin/lua.lua new file mode 100644 index 0000000..b634210 --- /dev/null +++ b/CONFIG/nvim/after/ftplugin/lua.lua @@ -0,0 +1,18 @@ +local bufname = vim.api.nvim_buf_get_name(0) +local filename_arg = bufname ~= "" and ("--stdin-filepath " .. vim.fn.shellescape(bufname) .. " ") or "" + +-- Indentation & Layout +vim.opt_local.colorcolumn = "120" +vim.opt_local.textwidth = 120 +vim.opt_local.tabstop = 4 +vim.opt_local.shiftwidth = 4 +vim.opt_local.softtabstop = 4 +vim.opt_local.expandtab = true + +-- Formatting Behavior +vim.opt_local.formatoptions:remove("t") +vim.opt_local.formatoptions:append("j") + +-- gq Formatters (StyLua fallback, LSP primary) +vim.bo.formatprg = "stylua " .. filename_arg .. "-" +vim.bo.formatexpr = "v:lua.vim.lsp.formatexpr()" diff --git a/CONFIG/nvim/after/ftplugin/markdown.lua b/CONFIG/nvim/after/ftplugin/markdown.lua new file mode 100644 index 0000000..1f11c22 --- /dev/null +++ b/CONFIG/nvim/after/ftplugin/markdown.lua @@ -0,0 +1,21 @@ +local bufname = vim.api.nvim_buf_get_name(0) +local filename_arg = bufname ~= "" and (" --stdin-filepath " .. vim.fn.shellescape(bufname)) or "" + +-- Indentation & Layout +vim.opt_local.colorcolumn = "" +vim.opt_local.wrap = true +vim.opt_local.textwidth = 80 +vim.opt_local.tabstop = 2 +vim.opt_local.shiftwidth = 2 +vim.opt_local.softtabstop = 2 +vim.opt_local.expandtab = true + +-- Formatting Behavior: wrap text, keep comment/quote headers, parse lists +vim.opt_local.formatoptions:append("tqn") + +-- gq Formatter: Prettier handles links/parentheses cleanly; par as fallback +if vim.fn.executable("prettier") == 1 then + vim.bo.formatprg = "prettier --parser markdown" .. filename_arg +elseif vim.fn.executable("par") == 1 then + vim.bo.formatprg = "par -w80req" +end diff --git a/CONFIG/nvim/after/ftplugin/python.lua b/CONFIG/nvim/after/ftplugin/python.lua new file mode 100644 index 0000000..acd57a1 --- /dev/null +++ b/CONFIG/nvim/after/ftplugin/python.lua @@ -0,0 +1,19 @@ +local bufname = vim.api.nvim_buf_get_name(0) +local filename_arg = bufname ~= "" and ("--stdin-filename " .. vim.fn.shellescape(bufname) .. " ") or "" + +-- Indentation & Layout +vim.opt_local.colorcolumn = "100" +vim.opt_local.textwidth = 100 +vim.opt_local.tabstop = 4 +vim.opt_local.shiftwidth = 4 +vim.opt_local.softtabstop = 4 +vim.opt_local.expandtab = true + +-- Formatting Behavior +vim.opt_local.formatoptions:remove("t") -- Don't autowrap while typing +vim.opt_local.formatoptions:append("j") -- Remove comment markers when joining lines + +-- gq Formatters (Ruff fallback, LSP primary) +-- The trailing '-' is required for Ruff to read from stdin +vim.bo.formatprg = "ruff format " .. filename_arg .. "-" +vim.bo.formatexpr = "v:lua.vim.lsp.formatexpr()" diff --git a/CONFIG/nvim/ftplugin/javascript.lua b/CONFIG/nvim/ftplugin/javascript.lua deleted file mode 100644 index badd24c..0000000 --- a/CONFIG/nvim/ftplugin/javascript.lua +++ /dev/null @@ -1,4 +0,0 @@ -vim.opt_local.colorcolumn = "100" -vim.opt_local.tabstop = 4 -vim.opt_local.shiftwidth = 4 -vim.opt_local.softtabstop = 4 diff --git a/CONFIG/nvim/ftplugin/lua.lua b/CONFIG/nvim/ftplugin/lua.lua deleted file mode 100644 index a5e25c1..0000000 --- a/CONFIG/nvim/ftplugin/lua.lua +++ /dev/null @@ -1,4 +0,0 @@ -vim.opt_local.colorcolumn = "120" -vim.opt_local.tabstop = 4 -vim.opt_local.shiftwidth = 4 -vim.opt_local.softtabstop = 4 diff --git a/CONFIG/nvim/ftplugin/markdown.lua b/CONFIG/nvim/ftplugin/markdown.lua deleted file mode 100644 index 451134d..0000000 --- a/CONFIG/nvim/ftplugin/markdown.lua +++ /dev/null @@ -1,5 +0,0 @@ -vim.opt_local.colorcolumn = "" -vim.opt_local.wrap = true -vim.opt_local.tabstop = 2 -vim.opt_local.shiftwidth = 2 -vim.opt_local.softtabstop = 2 diff --git a/CONFIG/nvim/ftplugin/python.lua b/CONFIG/nvim/ftplugin/python.lua deleted file mode 100644 index badd24c..0000000 --- a/CONFIG/nvim/ftplugin/python.lua +++ /dev/null @@ -1,4 +0,0 @@ -vim.opt_local.colorcolumn = "100" -vim.opt_local.tabstop = 4 -vim.opt_local.shiftwidth = 4 -vim.opt_local.softtabstop = 4