-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-sentence.vim
44 lines (41 loc) · 1.08 KB
/
format-sentence.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
" This is a function to format a sentence in Markdown.
" It will put one sentence on one line, and put a newline after the period
" character.
" It currently doesn't work with colons or question marks on the same line.
function! FormatSentence()
" save line
let fline = line(".")
" go to next [.:?]
execute "normal! /[\\.:?]\<cr>"
" save line
let sline = line(".")
" if on another line
if fline != sline
" line selection mode
execute "normal! V"
" go back to initial line
execute fline
" join lines
execute "normal! J"
endif
execute "normal! ^"
" save current line
let fline = line(".")
" go to next period with another sentence after it
execute "normal! /\\. [a-zA-Z]\\+\<cr>"
" save current line
let sline = line(".")
" if period is on same line
if fline == sline
" Replace period that has an additional paragraph after it with a newline
s/\. /.\r&/
" Go to next line and remove first period and space
s/^\. //
else
" go back to initial line, go to next line
execute fline
execute "normal! j"
endif
" go to beginning of line
execute "normal! ^"
endfunction