From d3ac84b6ddc90932271eb889525285d13bc44857 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 19 Jan 2025 23:37:30 +0000 Subject: [PATCH] Automatically add a blank line to the end of text ...files --- nvim/after/ftplugin/text.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nvim/after/ftplugin/text.lua b/nvim/after/ftplugin/text.lua index f1eaea8..8bdd7ab 100644 --- a/nvim/after/ftplugin/text.lua +++ b/nvim/after/ftplugin/text.lua @@ -4,3 +4,14 @@ opt.number = false opt.relativenumber = false opt.spell = true opt.wrap = true + +vim.api.nvim_create_autocmd("BufWritePre", { + buffer = 0, + callback = function() + local last_line = vim.api.nvim_buf_get_lines(0, -2, -1, false)[1] + + if last_line ~= "" then + vim.api.nvim_buf_set_lines(0, -1, -1, false, { "" }) + end + end, +})