Compare commits
2 commits
88969e03a2
...
a11caa4c50
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a11caa4c50 | ||
|
|
1cd9fc15e8 |
3 changed files with 30 additions and 0 deletions
7
init.lua
7
init.lua
|
|
@ -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")
|
||||
23
sentence_lines.lua
Normal file
23
sentence_lines.lua
Normal 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
|
||||
})
|
||||
Loading…
Reference in a new issue