vim-sentence-chopper : version-control friendly formatting of prose (and LaTeX markup)
| script karma
Downloaded by 8
Comments, bugs, improvements
script versions (upload new version)
|This Vim plug-in furnishes
- an operator mapping gw in normal mode, for example gwip operates on a
- a mapping gww (and gwgw) in normal mode that operates on a single line,
- a mapping gw that operates on the visual selection, and
- a command ChopSentences that operates on given range (equal to the whole
buffer if unspecified)
that put each sentence onto a single line.
That is, lines are only broken at punctuation marks .;:?! for better version
control of prose such as markdown, tex or text files.
For best results, ensure that latexindent is installed and the folder that
contains its executable is listed in $PATH (respectively in %PATH% on
This formatter will also distinguish TeX markup from prose to preserve
syntactic line breaks.
For example, hitting gwip on
Hello! How are you? Fine; after all.
turns it into
How are you?
The variable g:punctuation_marks defines punctuation marks at which sentences
are split up other than '.'; it is by default set to
let g:punctuation_marks = '?!'
The variable g:latexindent defines whether latexindent should be used by
default; it is by default set to
let g:latexindent = 1
The variable g:latexindent_options defines the command-line options passed to
latexindent as listed by latexindent -h ; it is by default set to
let g:latexindent_options = ''
The variable g:latexindent_yaml_options defines the documented YAML options
passed to latexindent; it is by default set to
let g:latexindent_yaml_options = ''
For example, to split up sentences after . or ; or : instead of . or ? or !,
and put every sentence in parentheses onto its proper line, add to your vimrc
let g:latexindent_yaml_options = 'modifyLineBreaks:oneSentencePerLine:sentencesEndWith:'
\ . 'other: \;|\:' . ';'
\ . 'questionMark: 0' . ';'
\ . 'exclamationMark: 0' . ','
\ . 'modifyLineBreaks:oneSentencePerLine:' . 'sentencesFollow:other: "\)"' . ','
\ . 'modifyLineBreaks:oneSentencePerLine:' . 'sentencesBeginWith:other: [a-z]'
To change mappings, for example, to use zy instead of gw, add the lines
nmap zy <plug>(ChopSentences)
xmap zy <plug>(ChopSentences)
to your vimrc.
To replace (or delete, or any other operation by Vim) up to the next punctuation mark, say . and ,;:!?, add
onoremap <silent> . :<c-u>call search('\v\C%(%([^[:digit:]IVX]\|[)''"])\zs[.]\|[,;:!?])[[:space:])''"]\|[.,;:!?]$','W')<CR>
to your vimrc! Then, for example, hitting "c." will change and "d." delete the
text up to the next punctuation mark. Say "c." turns "That's*it, Sir.",
where "*" stands for the cursor position, into "That's*, Sir".
This can be though of as a counterpart to Vim's built-in C and D commands
To normalize Unicode Homoglyphs, for example, of white spaces and punctuation
marks, before chopping sentences, see the Vim plug-in vim-unicode-homoglyphs
that highlights and normalizes Unicode homoglyphs.
vim-sentence-chopper is developed at https://github.com/Konfekt/vim-sentence-chopper where issues can be filed.
|Unzip vim-sentence-chopper.zip into ~/.vim on Linux or %USERPROFILE%\vimfiles on Windows.|
Click on the package to download.
ip used for rating: 188.8.131.52