Compare commits

..

2 commits

Author SHA1 Message Date
Pagwin
a11caa4c50
split into multiple files 2025-09-25 01:09:18 -04:00
Pagwin
1cd9fc15e8
v1 2025-09-25 01:00:46 -04:00
3 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,7 @@
-- get directory of this file
local config_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h")
-- prepend it to Lua's search path
package.path = config_dir .. "/?.lua;" .. config_dir .. "/?/init.lua;" .. package.path
require("sentence_lines")

View file

23
sentence_lines.lua Normal file
View file

@ -0,0 +1,23 @@
local function split_sentences_paragraph()
-- save cursor and window view
local view = vim.fn.winsaveview()
-- find the paragraph boundaries
local start_line = vim.fn.search('^\\s*$', 'bnW') + 1
if start_line == 1 then start_line = 1 end
local end_line = vim.fn.search('^\\s*$', 'nW') - 1
if end_line < start_line then end_line = vim.fn.line('$') end
-- build a range and run substitute with 'e' flag
local cmd = string.format("%d,%ds/\\([.?!]\\)\\s\\+/\\1\r/ge", start_line, end_line)
vim.cmd(cmd)
-- restore cursor
vim.fn.winrestview(view)
end
-- run after leaving insert mode
vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, {
pattern = { "*.md", "*.txt" },
callback = split_sentences_paragraph
})