mirror of
https://github.com/preservim/vim-pencil.git
synced 2025-11-19 23:33:39 -05:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e0f08de17 | ||
|
|
0205f78aac | ||
|
|
013587c347 | ||
|
|
68a8d0f3e4 | ||
|
|
2dcd974b72 | ||
|
|
aeba287111 | ||
|
|
6d01570f94 | ||
|
|
443187995a | ||
|
|
a5dbd88f30 | ||
|
|
9ad784bc23 | ||
|
|
fd75347422 | ||
|
|
f113c8c929 | ||
|
|
3e8b6f3417 | ||
|
|
670c62c39e | ||
|
|
99e2499500 | ||
|
|
f5f456ccdc | ||
|
|
cc63b20e03 | ||
|
|
f1df0f3030 | ||
|
|
735cc3b24e | ||
|
|
a4ad656d68 | ||
|
|
ad18a74cf0 | ||
|
|
470f9ca44c | ||
|
|
f9cbfca887 | ||
|
|
01a3a95c72 | ||
|
|
08ee355694 | ||
|
|
2f62713ed9 | ||
|
|
5e6ba37a94 | ||
|
|
ebbfc350b8 | ||
|
|
b36e21556d | ||
|
|
4e82b996e4 | ||
|
|
6b6c2f08bf | ||
|
|
dd8321a2d5 | ||
|
|
f89a3ac998 | ||
|
|
290b0872d0 | ||
|
|
632ae63c2c | ||
|
|
5f819bfec0 |
355
README.markdown
355
README.markdown
@@ -21,9 +21,6 @@ smooth the path to writing prose.
|
||||
* Adjusts navigation key mappings to suit the wrap mode
|
||||
* Creates undo points on common punctuation during Insert mode, including
|
||||
deletion via line `<C-U>` and word `<C-W>`
|
||||
* When using hard line breaks, _pencil_ enables Vim’s autoformat while
|
||||
inserting text, except for tables and code blocks where you won’t want
|
||||
it
|
||||
* Buffer-scoped configuration (with a few minor exceptions, _pencil_ preserves
|
||||
your global settings)
|
||||
* Support for Vim’s Conceal feature to hide markup defined by Syntax plugins
|
||||
@@ -31,6 +28,12 @@ smooth the path to writing prose.
|
||||
* Support for display of mode indicator (`␍` and `⤸`, e.g.) in the status line
|
||||
* Pure Vimscript with no dependencies
|
||||
|
||||
In addition, when using hard line break mode:
|
||||
|
||||
* Makes use of Vim’s powerful autoformat while inserting text, except for
|
||||
tables and code blocks where you won’t want it.
|
||||
* *NEW* Optional key mapping to suspend autoformat for the Insert.
|
||||
|
||||
Need spell-check, distraction-free editing, and other features? Vim is about
|
||||
customization. To complete your editing environment, learn to configure Vim and
|
||||
draw upon its rich ecosystem of plugins.
|
||||
@@ -54,7 +57,7 @@ switch away from the familiar word processor. Instead, you need
|
||||
a compelling reason—one that can appeal to a writer’s love for language
|
||||
and the tools of writing.
|
||||
|
||||
You can find that reason in Vim's mysterious command sequences. Take `cas`
|
||||
You can find that reason in Vim’s mysterious command sequences. Take `cas`
|
||||
for instance. You might see it as a mnemonic for _Change Around Sentence_
|
||||
to replace an existing sentence. But dig a bit deeper to discover that
|
||||
such commands have a grammar of their own, comprised of nouns, verbs, and
|
||||
@@ -63,14 +66,16 @@ specific language_ for manipulating text, one that can become a powerful
|
||||
tool in expressing yourself. For more details on vi-style editing, see...
|
||||
|
||||
* [Learn to speak vim – verbs, nouns, and modifiers!][ls] (December 2011)
|
||||
* [Your problem with Vim is that you don't grok vi][gv] (December 2011)
|
||||
* [Intro to Vim's Grammar][ig] (January 2013)
|
||||
* [Your problem with Vim is that you don’t grok vi][gv] (December 2011)
|
||||
* [Intro to Vim’s Grammar][ig] (January 2013)
|
||||
* [Why Atom Can’t Replace Vim, Learning the lesson of vi][wa] (March 2014)
|
||||
* [Language of Vim/Neovim][lovn] (January 2015)
|
||||
|
||||
[ls]: http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-nouns-and-modifiers/
|
||||
[gv]: http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118
|
||||
[ig]: http://takac.github.io/2013/01/30/vim-grammar/
|
||||
[wa]: https://medium.com/p/433852f4b4d1
|
||||
[lovn]: http://allsyed.com/language-of-vim-neovim/
|
||||
|
||||
# Installation
|
||||
|
||||
@@ -101,8 +106,6 @@ Plugin 'reedes/vim-pencil'
|
||||
:PluginInstall
|
||||
```
|
||||
|
||||
For Vundle version < 0.10.2, replace `Plugin` with `Bundle` above.
|
||||
|
||||
#### Plug
|
||||
|
||||
Add to your `.vimrc` and save:
|
||||
@@ -144,12 +147,26 @@ git clone https://github.com/reedes/vim-pencil
|
||||
|
||||
# Configuration
|
||||
|
||||
## Basic initialization
|
||||
## Initializing by command
|
||||
|
||||
Initializing _pencil_ by `FileType` is _optional_, though doing so will
|
||||
You can manually enable, disable, and toggle _pencil_ as a command:
|
||||
|
||||
* `Pencil` - initialize _pencil_ with auto-detect for the current buffer
|
||||
* `NoPencil` (or `PencilOff`) - removes navigation mappings and restores buffer to global settings
|
||||
* `TogglePencil` (or `PencilToggle`) - if on, turns off; if off, initializes with auto-detect
|
||||
|
||||
Because auto-detect might not work as intended, you can invoke a command
|
||||
to set the behavior for the current buffer:
|
||||
|
||||
* `SoftPencil` (or `PencilSoft`) - initialize _pencil_ with soft line wrap mode
|
||||
* `HardPencil` (or `PencilHard`) - initialize _pencil_ with hard line break mode (and Vim’s autoformat)
|
||||
|
||||
## Initializing by file type
|
||||
|
||||
Initializing _pencil_ by file type is _optional_, though doing so will
|
||||
automatically set up your buffers for editing prose.
|
||||
|
||||
Add support for your desired filetypes to your `.vimrc`:
|
||||
Add support for your desired file types to your `.vimrc`:
|
||||
|
||||
```vim
|
||||
set nocompatible
|
||||
@@ -182,7 +199,7 @@ also](#see-also) section below.
|
||||
|
||||
Coders will have the most experience with the former, and writers the
|
||||
latter. But whatever your background, chances are that you must contend
|
||||
with both conventions. This plugin doesn't force you to choose a side—you
|
||||
with both conventions. This plugin doesn’t force you to choose a side—you
|
||||
can configure each buffer independently.
|
||||
|
||||
In most cases you can set a default to suit your preference and let
|
||||
@@ -198,51 +215,25 @@ augroup pencil
|
||||
augroup END
|
||||
```
|
||||
|
||||
In the example above, for files of type `markdown` this plugin will
|
||||
In the example above, for buffers of type `markdown` this plugin will
|
||||
auto-detect the line wrap approach, with soft line wrap as the default.
|
||||
|
||||
For files of type `text`, it will initialize with hard line breaks, even
|
||||
if auto-detect might suggest soft line wrap.
|
||||
|
||||
## Commands
|
||||
|
||||
You can enable, disable, and toggle _pencil_ as a command:
|
||||
|
||||
* `Pencil` - initialize _pencil_ with auto-detect for the current buffer
|
||||
* `NoPencil` (or `PencilOff`) - removes navigation mappings and restores buffer to global settings
|
||||
* `TogglePencil` (or `PencilToggle`) - if on, turns off; if off, initializes with auto-detect
|
||||
|
||||
Because auto-detect might not work as intended, you can invoke a command
|
||||
to set the behavior for the current buffer:
|
||||
|
||||
* `SoftPencil` (or `PencilSoft`) - initialize _pencil_ with soft line wrap mode
|
||||
* `HardPencil` (or `PencilHard`) - initialize _pencil_ with hard line break mode (and Vim’s autoformat)
|
||||
For buffers of type `text`, it will initialize with hard line breaks,
|
||||
even if auto-detect might suggest soft line wrap.
|
||||
|
||||
## Automatic formatting
|
||||
|
||||
_The ‘autoformat’ feature affects *HardPencil* (hard line break) mode
|
||||
_The ‘autoformat’ feature affects `HardPencil` (hard line break) mode
|
||||
only._
|
||||
|
||||
When inserting text while in *HardPencil* mode, Vim’s autoformat feature
|
||||
will be enabled by default and can offer many of the same benefits as
|
||||
soft line wrap.
|
||||
When inserting text while in `HardPencil` mode, Vim’s powerful autoformat
|
||||
feature will be _enabled_ by default and can offer many of the same
|
||||
benefits as soft line wrap.
|
||||
|
||||
One useful exception (aka 'blacklisting'): if used with popular
|
||||
prose-oriented syntax plugins, _pencil_ will **not** enable autoformat when
|
||||
you enter Insert mode from inside a code block or table. (See the
|
||||
advanced section below for more details on the blacklisting feature.)
|
||||
|
||||
Where you need to manually enable/disable autoformat for the current
|
||||
buffer, you can do so with a command:
|
||||
|
||||
* `PFormat` - allows autoformat to be enabled (if not blacklisted)
|
||||
* `PFormatOff` - prevents autoformat from enabling (blacklist all)
|
||||
* `PFormatToggle` - toggle to allow if off, etc.
|
||||
|
||||
To set the default behavior, add to your `.vimrc`:
|
||||
To set the default behavior in your `.vimrc`:
|
||||
|
||||
```vim
|
||||
let g:pencil#autoformat = 1 " 0=manual, 1=auto (def)
|
||||
let g:pencil#autoformat = 1 " 0=disable, 1=enable (def)
|
||||
```
|
||||
|
||||
You can override this default during initialization, as in:
|
||||
@@ -250,43 +241,71 @@ You can override this default during initialization, as in:
|
||||
```vim
|
||||
augroup pencil
|
||||
autocmd!
|
||||
autocmd FileType text call pencil#init({'wrap': 'hard', 'autoformat': 0})
|
||||
autocmd FileType markdown call pencil#init({'wrap': 'hard', 'autoformat': 1})
|
||||
autocmd FileType text call pencil#init({'wrap': 'hard', 'autoformat': 0})
|
||||
...
|
||||
augroup END
|
||||
```
|
||||
|
||||
...where by default, files of type `text` will use hard line endings, but
|
||||
with autoformat disabled.
|
||||
...where buffers of type `markdown` and `text` will use hard line breaks,
|
||||
but `text` buffers will have autoformat disabled.
|
||||
|
||||
Optionally, you can map a toggle to control autoformat in your `.vimrc`:
|
||||
## Suspend automatic formatting for the Insert
|
||||
|
||||
There are two useful exceptions where autoformat (when enabled for the
|
||||
buffer) will be _temporarily disabled_ for the current Insert:
|
||||
|
||||
**First** is _pencil’s_ ‘blacklisting’ feature: if used with popular
|
||||
prose-oriented syntax plugins, _pencil_ will suspend autoformat when you
|
||||
enter Insert mode from inside a code block or table.
|
||||
|
||||
**Second**, where blacklisting falls short, you can optionally map
|
||||
a buffer-scoped ‘modifier’ key to suspend autoformat during the next
|
||||
Insert:
|
||||
|
||||
```vim
|
||||
noremap <buffer> <silent> <F7> :<C-u>PFormatToggle<cr>
|
||||
inoremap <buffer> <silent> <F7> <C-o>:PFormatToggle<cr>
|
||||
let g:pencil#map#suspend_af = 'K' " default is no mapping
|
||||
```
|
||||
|
||||
Using the above mapping, with `Ko` you’ll enter Insert mode with the
|
||||
cursor on a new line, but autoformat will suspend for that Insert. Using
|
||||
`o` by itself will retain autoformat.
|
||||
|
||||
By default no modifier key is mapped.
|
||||
|
||||
(See the advanced section below for details on how blacklisting is
|
||||
implemented and configured).
|
||||
|
||||
## Manual formatting
|
||||
|
||||
Note that you need not rely on Vim’s autoformat exclusively and can
|
||||
manually reformat paragraphs with standard Vim commands:
|
||||
|
||||
* `gqip` or `gwip` - format current paragraph
|
||||
* `vipJ` - unformat (i.e., join all lines with hard line breaks) in current paragraph
|
||||
* `gqap` - format current paragraph (see `:help gq` for details)
|
||||
* `vapJgqap` - merge two paragraphs (current and next) and format
|
||||
* `ggVGgq` or `:g/^/norm gqq` - format all paragraphs in buffer
|
||||
* `:%norm vipJ` - unformat all paragraphs in buffer
|
||||
|
||||
Optionally, you can map these operations to underutilized keys in your
|
||||
`.vimrc`:
|
||||
|
||||
```vim
|
||||
nnoremap <silent> Q gwip
|
||||
nnoremap <silent> Q gqap
|
||||
xnoremap <silent> Q gq
|
||||
nnoremap <silent> <leader>Q vapJgqap
|
||||
```
|
||||
|
||||
Or you may wish to ‘unformat’, (i.e., remove hard line breaks) when using
|
||||
soft line wrap.
|
||||
|
||||
* `vipJ` - join all lines in current paragraph
|
||||
* `:%norm vipJ` - unformat all paragraphs in buffer
|
||||
|
||||
## Default textwidth
|
||||
|
||||
You can configure the textwidth to be used in **HardPencil** mode when no
|
||||
textwidth is set globally, locally, or available via modeline. It
|
||||
defaults to `74`, but you can change that value in your `.vimrc`:
|
||||
You can configure the textwidth to be used in `HardPencil` (hard line
|
||||
break) mode when no textwidth is set globally, locally, or available via
|
||||
modeline. It defaults to `74`, but you can change that value in your
|
||||
`.vimrc`:
|
||||
|
||||
```vim
|
||||
let g:pencil#textwidth = 74
|
||||
@@ -315,13 +334,13 @@ let g:pencil#cursorwrap = 1 " 0=disable, 1=enable (def)
|
||||
|
||||
## Concealing \_\_markup\_\_
|
||||
|
||||
_pencil_ enables Vim's powerful Conceal feature, although support among
|
||||
_pencil_ enables Vim’s powerful Conceal feature, although support among
|
||||
Syntax and Colorscheme plugins is currently spotty.
|
||||
|
||||
You can change _pencil’s_ default settings for conceal in your `.vimrc`:
|
||||
|
||||
```vim
|
||||
let g:pencil#conceallevel = 3 " 0=disable, 1=onechar, 2=hidechar, 3=hideall (def)
|
||||
let g:pencil#conceallevel = 3 " 0=disable, 1=one char, 2=hide char, 3=hide all (def)
|
||||
let g:pencil#concealcursor = 'c' " n=normal, v=visual, i=insert, c=command (def)
|
||||
```
|
||||
|
||||
@@ -343,10 +362,10 @@ To use Vim’s Conceal feature with Markdown, you will need to install:
|
||||
1. [tpope/vim-markdown][tm] as it’s currently the only Markdown syntax
|
||||
plugin that supports conceal.
|
||||
|
||||
2. a monospaced font (such as [Cousine][co]) featuring the _italic_,
|
||||
2. A monospaced font (such as [Cousine][co]) featuring the _italic_,
|
||||
**bold**, and ***bold italic*** style variant for styled text.
|
||||
|
||||
3. a colorscheme (such as [reedes/vim-colors-pencil][cp]) which supports
|
||||
3. A colorscheme (such as [reedes/vim-colors-pencil][cp]) which supports
|
||||
the Markdown-specific highlight groups for styled text.
|
||||
|
||||
You should then only see the `_` and `*` markup for the cursor line and in
|
||||
@@ -375,12 +394,23 @@ or if using [bling/vim-airline][va]:
|
||||
let g:airline_section_x = '%{PencilMode()}'
|
||||
```
|
||||
|
||||
If you don’t like the default indicators, you can specify different ones:
|
||||
The default indicators now include ‘auto’ for when Vim’s autoformat is
|
||||
active in hard line break mode. (If autoformat is suspended for the
|
||||
Insert, it’ll show the ‘hard’ indicator.)
|
||||
|
||||
```vim
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'soft': '⤸', 'off': '',}
|
||||
let g:pencil#mode_indicators = {'hard': 'H', 'auto': 'A', 'soft': 'S', 'off': '',}
|
||||
```
|
||||
|
||||
If Unicode is detected, the default indicators are:
|
||||
|
||||
```vim
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'auto': 'ª', 'soft': '⤸', 'off': '',}
|
||||
```
|
||||
|
||||
If you don’t like the default indicators, you can specify your own in
|
||||
your `.vimrc`.
|
||||
|
||||
Note that `PencilMode()` will return blank for buffers in which _pencil_
|
||||
has not been initialized.
|
||||
|
||||
@@ -390,11 +420,55 @@ has not been initialized.
|
||||
|
||||
### Advanced initialization
|
||||
|
||||
Configurable options for `pencil#init()` include: `autoformat`,
|
||||
`concealcursor`, `conceallevel`, `cursorwrap`, `joinspaces`, `textwidth`,
|
||||
and `wrap`. These are detailed above.
|
||||
You may want to refactor initialization statements into a function in
|
||||
your `.vimrc` to set up a buffer for writing:
|
||||
|
||||
You can override _pencil_ and other configuration settings when initializing:
|
||||
```vim
|
||||
function! Prose()
|
||||
call pencil#init()
|
||||
call lexical#init()
|
||||
call litecorrect#init()
|
||||
call textobj#quote#init()
|
||||
call textobj#sentence#init()
|
||||
|
||||
" manual reformatting shortcuts
|
||||
nnoremap <buffer> <silent> Q gqap
|
||||
xnoremap <buffer> <silent> Q gq
|
||||
nnoremap <buffer> <silent> <leader>Q vapJgqap
|
||||
|
||||
" force top correction on most recent misspelling
|
||||
nnoremap <buffer> <c-s> [s1z=<c-o>
|
||||
inoremap <buffer> <c-s> <c-g>u<Esc>[s1z=`]A<c-g>u
|
||||
|
||||
" replace common punctuation
|
||||
iabbrev <buffer> -- –
|
||||
iabbrev <buffer> --- —
|
||||
iabbrev <buffer> << «
|
||||
iabbrev <buffer> >> »
|
||||
|
||||
" open most folds
|
||||
setlocal foldlevel=6
|
||||
|
||||
" replace typographical quotes (reedes/vim-textobj-quote)
|
||||
map <silent> <buffer> <leader>qc <Plug>ReplaceWithCurly
|
||||
map <silent> <buffer> <leader>qs <Plug>ReplaceWithStraight
|
||||
|
||||
" highlight words (reedes/vim-wordy)
|
||||
noremap <silent> <buffer> <F8> :<C-u>NextWordy<cr>
|
||||
xnoremap <silent> <buffer> <F8> :<C-u>NextWordy<cr>
|
||||
inoremap <silent> <buffer> <F8> <C-o>:NextWordy<cr>
|
||||
|
||||
endfunction
|
||||
|
||||
" automatically initialize buffer by file type
|
||||
autocmd FileType markdown,mkd,text call Prose()
|
||||
|
||||
" invoke manually by command for other file types
|
||||
command! -nargs=0 Prose call Prose()
|
||||
```
|
||||
|
||||
For highly-granular control, you can override _pencil_ and other configuration
|
||||
settings when initializing buffers by file type:
|
||||
|
||||
```vim
|
||||
augroup pencil
|
||||
@@ -416,57 +490,80 @@ augroup pencil
|
||||
augroup END
|
||||
```
|
||||
|
||||
Alternatives include `after/ftplugin` modules as well as refactoring initialization
|
||||
statements into a function.
|
||||
Configurable options for `pencil#init()` include: `autoformat`,
|
||||
`concealcursor`, `conceallevel`, `cursorwrap`, `joinspaces`, `textwidth`,
|
||||
and `wrap`. These are detailed above.
|
||||
|
||||
### Autoformat blacklisting
|
||||
### Autoformat manual control
|
||||
|
||||
_The ‘autoformat’ feature affects *HardPencil* (hard line break) mode
|
||||
_The ‘autoformat’ feature affects `HardPencil` (hard line break) mode
|
||||
only._
|
||||
|
||||
To suspend autoformat for the next Insert, see above.
|
||||
|
||||
When you need to manually enable/disable autoformat for the current
|
||||
buffer, you can do so with a command:
|
||||
|
||||
* `PFormat` - enable autoformat for buffer (can still be disabled via blacklisting)
|
||||
* `PFormatOff` - disable autoformat for buffer
|
||||
* `PFormatToggle` - toggle to enable if disabled, etc.
|
||||
|
||||
You can map a key in your `.vimrc` to toggle Vim’s autoformat:
|
||||
|
||||
```vim
|
||||
noremap <silent> <F7> :<C-u>PFormatToggle<cr>
|
||||
inoremap <silent> <F7> <C-o>:PFormatToggle<cr>
|
||||
```
|
||||
|
||||
### Autoformat blacklisting (and whitelisting)
|
||||
|
||||
_The ‘autoformat’ feature affects `HardPencil` (hard line break) mode
|
||||
only._
|
||||
|
||||
When editing formatted text, such as a table or code block, Vim’s
|
||||
autoformat will wreak havoc with the formatting. In these cases you will
|
||||
want to temporarily deactivate autoformat, such as with the `PFormatOff`
|
||||
or `PFormatToggle` commands described above. However, in most cases, you
|
||||
won’t need to do this.
|
||||
want autoformat suspended for the duration of the Insert.
|
||||
|
||||
_pencil_ will detect the syntax highlight group at the cursor position to
|
||||
determine whether or not autoformat should be activated.
|
||||
When entering Insert mode, _pencil_ will determine the highlight group at
|
||||
the cursor position. If that group has been blacklisted, _pencil_ will
|
||||
suspend autoformat for the Insert. For example, if editing a buffer of
|
||||
type ‘markdown’, autoformat will be suspended if you invoke Insert mode
|
||||
from inside a `markdownFencedCodeBlock` highlight group.
|
||||
|
||||
If autoformat is on, it will be activated at the time you enter Insert
|
||||
mode provided that the syntax highlighting group at the cursor position is
|
||||
_not_ in the blacklist. The current blacklist is:
|
||||
Blacklists are now declared by file type. The default blacklists (and
|
||||
whitelists) are declared in the `plugin/pencil.vim` module. Here’s an
|
||||
excerpt showing the configuration for the ‘markdown’ file type:
|
||||
|
||||
```vim
|
||||
let g:pencil#autoformat_blacklist = [
|
||||
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||
\ 'markdownOrderedListMarker',
|
||||
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
|
||||
\ 'htmlH[0-9]',
|
||||
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||
\ 'mmdTable[A-Za-z0-9]*',
|
||||
\ 'txtCode',
|
||||
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
|
||||
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)',
|
||||
\ 'texSection$',
|
||||
\ 'asciidoc(AttributeList|ListLabel|Literal|SideBar|Source|Sect[0-9])',
|
||||
\ 'asciidoc[A-Za-z]*(Block|Macro|Title)',
|
||||
\ ]
|
||||
let g:pencil#autoformat_config = {
|
||||
\ 'markdown': {
|
||||
\ 'black': [
|
||||
\ 'htmlH[0-9]',
|
||||
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
|
||||
\ 'mmdTable[A-Za-z0-9]*',
|
||||
\ ],
|
||||
\ 'white': [
|
||||
\ 'markdown(Code|Link)',
|
||||
\ ],
|
||||
\ },
|
||||
[snip]
|
||||
\ }
|
||||
```
|
||||
|
||||
_WARNING: the implementation of this blacklist will be changing in the
|
||||
future._
|
||||
|
||||
You can override this in your `.vimrc`. Additions to defaults with good
|
||||
use cases are welcome.
|
||||
The whitelist will override the blacklist and enable Vim’s autoformat if
|
||||
text that would normally be blacklisted doesn’t dominate the entire line.
|
||||
This allows autoformat to work with `inline` code and links.
|
||||
|
||||
### Auto-detecting wrap mode
|
||||
|
||||
If you didn't explicitly specify a wrap mode during initialization,
|
||||
If you didn’t explicitly specify a wrap mode during initialization,
|
||||
_pencil_ will attempt to detect it.
|
||||
|
||||
It will first look for a `textwidth` (or `tw`) specified in a modeline.
|
||||
Failing that, _pencil_ will then sample lines from the start of the file.
|
||||
Failing that, _pencil_ will then sample lines from the start of the
|
||||
buffer.
|
||||
|
||||
#### Detect via modeline
|
||||
|
||||
@@ -487,7 +584,8 @@ command upon loading the file into a buffer:
|
||||
```
|
||||
|
||||
It tells _pencil_ to assume hard line breaks, regardless of whether or
|
||||
not soft line wrap is the default editing mode for files of type ‘markdown’.
|
||||
not soft line wrap is the default editing mode for buffers of type
|
||||
‘markdown’.
|
||||
|
||||
You explicitly specify soft wrap mode by specifying a textwidth of `0`:
|
||||
|
||||
@@ -500,12 +598,12 @@ reasons) the textwidth will still be set by this plugin.
|
||||
|
||||
#### Detect via sampling
|
||||
|
||||
If no modeline with a textwidth is found, _pencil_ will sample the initial
|
||||
lines from the file, looking for those excessively-long.
|
||||
If no modeline with a textwidth is found, _pencil_ will sample the
|
||||
initial lines from the buffer, looking for those excessively-long.
|
||||
|
||||
There are two settings you can add to your `.vimrc` to tweak this behavior.
|
||||
|
||||
The maximum number of lines to sample from the start of the file:
|
||||
The maximum number of lines to sample from the start of the buffer:
|
||||
|
||||
```vim
|
||||
let g:pencil#softDetectSample = 20
|
||||
@@ -528,13 +626,30 @@ If no such lines found, _pencil_ falls back to the default wrap mode.
|
||||
* [Vim Training Class - Basic motions and commands][tc] - video tutorial by Shawn Biddle
|
||||
* [Vim for Writers][vw] - guide to the basics geared to writers
|
||||
|
||||
Bloggers and developers discuss _pencil_ and its brethern:
|
||||
|
||||
* [Reed Esau’s growing list of Vim plugins for writers][regl] (2014) - by @pengwynn
|
||||
* [Distraction Free Writing in Vim][dfwiv] (2014) - by @tlattimore
|
||||
* [Safari Blog: Turning vim into an IDE through vim plugins][tviai] (2014) - by @jameydeorio
|
||||
* [Quick tops for writing prose with Vim][qtfwp] (2014) - by @benoliver999
|
||||
* [UseVim: Reed Esau’s Writing Plugins][rewp] (2015) - by @alexyoung
|
||||
* [Tomasino Labs: Vim in Context][vic] (2015) - by @jamestomasino
|
||||
|
||||
Other plugins of specific interest to writers:
|
||||
|
||||
* [danielbmarques/vim-ditto][vd] - highlight repeated words
|
||||
* [tpope/vim-abolish][ab] - search for, substitute, and abbr. multiple variants of a word
|
||||
* [tommcdo/vim-exchange][ex] - easy text exchange operator for Vim
|
||||
* [junegunn/limelight.vim][jl] - focus mode that brightens current paragraph
|
||||
* [junegunn/goyo.vim][jg] - distraction-free editing mode
|
||||
|
||||
[vd]: https://github.com/danielbmarques/vim-ditto
|
||||
[qtfwp]: http://benoliver999.com/technology/2014/12/06/vimforprose/
|
||||
[vic]: https://labs.tomasino.org/vim-in-context/
|
||||
[rewp]: https://medium.com/usevim/reed-esaus-writing-plugins-5b6c65bc808f
|
||||
[tviai]: https://www.safaribooksonline.com/blog/2014/11/23/way-vim-ide/
|
||||
[regl]: http://wynnnetherland.com/journal/reed-esau-s-growing-list-of-vim-plugins-for-writers/
|
||||
[dfwiv]: http://tlattimore.com/blog/distraction-free-writing-in-vim/
|
||||
[ab]: http://github.com/tpope/vim-abolish
|
||||
[ex]: http://github.com/tommcdo/vim-exchange
|
||||
[jl]: http://github.com/junegunn/limelight.vim
|
||||
@@ -542,10 +657,24 @@ Other plugins of specific interest to writers:
|
||||
|
||||
Markdown syntax plugins
|
||||
|
||||
* [tpope/vim-markdown][tvm] - the latest version of the syntax plugin that ships with Vim
|
||||
Markdown users typically won’t need to install a syntax plugin unless
|
||||
they want the latest version of Pope’s syntax highlighting:
|
||||
|
||||
* [tpope/vim-markdown][tvm] - (recommended) the latest version of Pope’s
|
||||
syntax plugin which ships with Vim
|
||||
|
||||
Those using tables and footnotes should consider installing this plugin:
|
||||
|
||||
* [mattly/vim-markdown-enhancements][mvme]
|
||||
|
||||
Alternatives to Tim Pope’s syntax highlighting include:
|
||||
|
||||
* [plasticboy/vim-markdown][pvm]
|
||||
* [gabrielelana/vim-markdown][gvm]
|
||||
* [mattly/vim-markdown-enhancements][mvme] - highlighting for tables and footnotes
|
||||
|
||||
Note that the plasticboy and gabrielelana plugins may incorrectly
|
||||
reformat bulleted lists when Vim’s autoformat is active in _pencil_’s
|
||||
HardPencil mode.
|
||||
|
||||
[tvm]: http://github.com/tpope/vim-markdown
|
||||
[pvm]: http://github.com/plasticboy/vim-markdown
|
||||
@@ -559,7 +688,7 @@ If you find the _pencil_ plugin useful, check out these others by [@reedes][re]:
|
||||
* [vim-litecorrect][lc] - lightweight auto-correction for Vim
|
||||
* [vim-one][vo] - make use of Vim’s _+clientserver_ capabilities
|
||||
* [vim-textobj-quote][qu] - extends Vim to support typographic (‘curly’) quotes
|
||||
* [vim-textobj-sentence][ts] - improving on Vim's native sentence motion command
|
||||
* [vim-textobj-sentence][ts] - improving on Vim’s native sentence motion command
|
||||
* [vim-thematic][th] - modify Vim’s appearance to suit your task and environment
|
||||
* [vim-wheel][wh] - screen-anchored cursor movement for Vim
|
||||
* [vim-wordy][wo] - uncovering usage problems in writing
|
||||
@@ -584,9 +713,7 @@ with its own Markdown variant.
|
||||
|
||||
# Future development
|
||||
|
||||
If you’ve spotted a problem or have an idea on improving this plugin,
|
||||
please post it to the github project issue page or submit a pull request.
|
||||
If you’ve spotted a problem or have an idea on improving _pencil_, please
|
||||
report it as an issue, or better yet submit a pull request.
|
||||
|
||||
```
|
||||
<!-- vim: set tw=73 :-->
|
||||
```
|
||||
|
||||
@@ -53,7 +53,25 @@ fun! s:imap(preserve_completion, key, icmd) abort
|
||||
endf
|
||||
|
||||
fun! s:maybe_enable_autoformat() abort
|
||||
" don't enable autoformat if in a code block or table
|
||||
" don't enable autoformat if in a blacklisted code block or table,
|
||||
" allowing for reprieve via whitelist in certain cases
|
||||
|
||||
" a flag to suspend autoformat for the Insert
|
||||
if b:pencil_suspend_af
|
||||
let b:pencil_suspend_af = 0 " clear the flag
|
||||
return
|
||||
en
|
||||
|
||||
let l:ft = get(g:pencil#autoformat_aliases, &ft, &ft)
|
||||
let l:af_cfg = get(g:pencil#autoformat_config, l:ft, {})
|
||||
let l:black = get(l:af_cfg, 'black', [])
|
||||
let l:white = get(l:af_cfg, 'white', [])
|
||||
let l:has_black_re = len(l:black) > 0
|
||||
let l:has_white_re = len(l:white) > 0
|
||||
let l:black_re = l:has_black_re ? '\v(' . join( l:black, '|') . ')' : ''
|
||||
let l:white_re = l:has_white_re ? '\v(' . join( l:white, '|') . ')' : ''
|
||||
let l:enforce_previous_line = get(l:af_cfg, 'enforce-previous-line', 0)
|
||||
|
||||
let l:okay_to_enable = 1
|
||||
let l:line = line('.')
|
||||
let l:col = col('.')
|
||||
@@ -88,21 +106,21 @@ fun! s:maybe_enable_autoformat() abort
|
||||
endw
|
||||
en
|
||||
" enforce blacklist by scanning for syntax matches
|
||||
for l:sid in l:stack
|
||||
if match(synIDattr(l:sid, 'name'),
|
||||
\ g:pencil#autoformat_blacklist_re) >= 0
|
||||
let l:okay_to_enable = 0
|
||||
"echohl WarningMsg
|
||||
"echo 'hit blacklist line=' . l:line . ' col=' . l:col .
|
||||
" \ ' name=' . synIDattr(l:sid, 'name')
|
||||
"echohl NONE
|
||||
break
|
||||
en
|
||||
endfo
|
||||
" enforce whitelist by detecting inline `markup` for
|
||||
" which we DO want autoformat to be enabled (e.g.,
|
||||
" tpope's markdownCode)
|
||||
if !l:okay_to_enable
|
||||
if l:has_black_re
|
||||
for l:sid in l:stack
|
||||
if match(synIDattr(l:sid, 'name'), l:black_re) >= 0
|
||||
let l:okay_to_enable = 0
|
||||
"echohl WarningMsg
|
||||
"echo 'hit blacklist line=' . l:line . ' col=' . l:col .
|
||||
" \ ' name=' . synIDattr(l:sid, 'name')
|
||||
"echohl NONE
|
||||
break
|
||||
en
|
||||
endfo
|
||||
en
|
||||
" enforce whitelist by detecting inline `markup` for which we DO want
|
||||
" autoformat to be enabled (e.g., tpope's markdownCode)
|
||||
if l:has_white_re && !l:okay_to_enable
|
||||
" one final check for an empty stack at the start and end of line,
|
||||
" either of which greenlights a whitelist check
|
||||
if !l:found_empty
|
||||
@@ -113,8 +131,7 @@ fun! s:maybe_enable_autoformat() abort
|
||||
en
|
||||
if l:found_empty
|
||||
for l:sid in l:stack
|
||||
if match(synIDattr(l:sid, 'name'),
|
||||
\ g:pencil#autoformat_inline_whitelist_re) >= 0
|
||||
if match(synIDattr(l:sid, 'name'), l:white_re) >= 0
|
||||
let l:okay_to_enable = 1
|
||||
break
|
||||
en
|
||||
@@ -122,14 +139,11 @@ fun! s:maybe_enable_autoformat() abort
|
||||
en
|
||||
en
|
||||
" disallow enable if start of previous line is in blacklist,
|
||||
" (To avoid problem of autowrap screwing up adding a new item
|
||||
" to a list.)
|
||||
if l:okay_to_enable && l:line > 1
|
||||
if l:has_black_re && l:enforce_previous_line && l:okay_to_enable && l:line > 1
|
||||
let l:prev_stack = synstack(l:line - 1, 1)
|
||||
for l:sid in l:prev_stack
|
||||
if len(l:sid) > 0 &&
|
||||
\ match(synIDattr(l:sid, 'name'),
|
||||
\ g:pencil#autoformat_blacklist_re) >= 0
|
||||
\ match(synIDattr(l:sid, 'name'), l:black_re) >= 0
|
||||
let l:okay_to_enable = 0
|
||||
break
|
||||
en
|
||||
@@ -141,7 +155,7 @@ fun! s:maybe_enable_autoformat() abort
|
||||
endf
|
||||
|
||||
fun! pencil#setAutoFormat(af) abort
|
||||
" 1=auto, 0=manual, -1=toggle
|
||||
" 1=enable, 0=disable, -1=toggle
|
||||
if !exists('b:last_autoformat')
|
||||
let b:last_autoformat = 0
|
||||
en
|
||||
@@ -172,6 +186,9 @@ endf
|
||||
fun! pencil#init(...) abort
|
||||
let l:args = a:0 ? a:1 : {}
|
||||
|
||||
" flag to suspend autoformat for the next Insert
|
||||
let b:pencil_suspend_af = 0
|
||||
|
||||
if !exists('b:pencil_wrap_mode')
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_OFF
|
||||
en
|
||||
@@ -224,6 +241,14 @@ fun! pencil#init(...) abort
|
||||
setl textwidth<
|
||||
en
|
||||
setl nowrap
|
||||
|
||||
" flag to suspend autoformat for next Insert
|
||||
" optional user-defined mapping
|
||||
if exists('g:pencil#map#suspend_af') &&
|
||||
\ g:pencil#map#suspend_af != ''
|
||||
exe 'no <buffer> <silent> ' . g:pencil#map#suspend_af . ' :let b:pencil_suspend_af=1<CR>'
|
||||
en
|
||||
|
||||
elsei b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT
|
||||
setl textwidth=0
|
||||
setl wrap
|
||||
@@ -235,7 +260,7 @@ fun! pencil#init(...) abort
|
||||
setl breakat-=@ " avoid breaking at email addresses
|
||||
en
|
||||
|
||||
if has('syntax')
|
||||
if exists('&colorcolumn')
|
||||
setl colorcolumn=0 " doesn't align as expected
|
||||
en
|
||||
el
|
||||
@@ -247,7 +272,7 @@ fun! pencil#init(...) abort
|
||||
setl breakat<
|
||||
en
|
||||
|
||||
if has('syntax')
|
||||
if exists('&colorcolumn')
|
||||
setl colorcolumn<
|
||||
en
|
||||
en
|
||||
@@ -386,6 +411,10 @@ fun! pencil#init(...) abort
|
||||
vn <buffer> <silent> k gk
|
||||
no <buffer> <silent> <Up> gk
|
||||
no <buffer> <silent> <Down> gj
|
||||
nn <buffer> <silent> gj j
|
||||
nn <buffer> <silent> gk k
|
||||
vn <buffer> <silent> gj j
|
||||
vn <buffer> <silent> gk k
|
||||
|
||||
" preserve behavior of up/down keys in popups
|
||||
call s:imap(1, '<Up>' , '<C-o>g<Up>' )
|
||||
@@ -397,6 +426,10 @@ fun! pencil#init(...) abort
|
||||
sil! vu <buffer> k
|
||||
sil! unm <buffer> <Up>
|
||||
sil! unm <buffer> <Down>
|
||||
sil! nun <buffer> gj j
|
||||
sil! nun <buffer> gk k
|
||||
sil! vu <buffer> gj j
|
||||
sil! vu <buffer> gk k
|
||||
|
||||
sil! iu <buffer> <Up>
|
||||
sil! iu <buffer> <Down>
|
||||
@@ -413,7 +446,14 @@ fun! pencil#init(...) abort
|
||||
ino <buffer> : :<c-g>u
|
||||
ino <buffer> <c-u> <c-g>u<c-u>
|
||||
ino <buffer> <c-w> <c-g>u<c-w>
|
||||
ino <buffer> <cr> <c-g>u<cr>
|
||||
|
||||
" map <cr> only if not already mapped
|
||||
if empty(maparg('<cr>', 'i'))
|
||||
ino <buffer> <cr> <c-g>u<cr>
|
||||
let b:pencil_cr_mapped = 1
|
||||
el
|
||||
let b:pencil_cr_mapped = 0
|
||||
en
|
||||
el
|
||||
sil! iu <buffer> .
|
||||
sil! iu <buffer> !
|
||||
@@ -423,7 +463,11 @@ fun! pencil#init(...) abort
|
||||
sil! iu <buffer> :
|
||||
sil! iu <buffer> <c-u>
|
||||
sil! iu <buffer> <c-w>
|
||||
sil! iu <buffer> <cr>
|
||||
|
||||
" unmap <cr> only if we mapped it ourselves
|
||||
if exists('b:pencil_cr_mapped') && b:pencil_cr_mapped
|
||||
sil! iu <buffer> <cr>
|
||||
en
|
||||
en
|
||||
endf
|
||||
|
||||
|
||||
@@ -31,7 +31,11 @@ fun! PencilMode()
|
||||
if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT
|
||||
return get(g:pencil#mode_indicators, 'soft', 'S')
|
||||
elsei b:pencil_wrap_mode ==# s:WRAP_MODE_HARD
|
||||
return get(g:pencil#mode_indicators, 'hard', 'H')
|
||||
if &fo =~ 'a'
|
||||
return get(g:pencil#mode_indicators, 'auto', 'A')
|
||||
el
|
||||
return get(g:pencil#mode_indicators, 'hard', 'H')
|
||||
en
|
||||
el
|
||||
return get(g:pencil#mode_indicators, 'off', '')
|
||||
en
|
||||
@@ -57,9 +61,9 @@ if !exists('g:pencil#autoformat')
|
||||
let g:pencil#autoformat = 1
|
||||
en
|
||||
|
||||
if !exists('g:pencil#autoformat_blacklist')
|
||||
" do not engage autoformat if cursor is inside any of
|
||||
" the following syntax groups
|
||||
if !exists('g:pencil#autoformat_config')
|
||||
" Do not activate autoformat if entering Insert mode when
|
||||
" the cursor is inside any of the following syntax groups.
|
||||
"
|
||||
" markdown* (tpope/vim-markdown)
|
||||
" mkd*, htmlH[0-9] (plasticboy/vim-markdown)
|
||||
@@ -67,36 +71,66 @@ if !exists('g:pencil#autoformat_blacklist')
|
||||
" mmdTable[A-Za-z0-9]* (mattly/vim-markdown-enhancements)
|
||||
" txtCode (timcharper/textile.vim)
|
||||
" rst*,tex*,asciidoc* (syntax file shipped with vim)
|
||||
let g:pencil#autoformat_blacklist = [
|
||||
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||
\ 'markdownOrderedListMarker',
|
||||
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
|
||||
\ 'htmlH[0-9]',
|
||||
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||
\ 'mmdTable[A-Za-z0-9]*',
|
||||
\ 'txtCode',
|
||||
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
|
||||
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)',
|
||||
\ 'texSection$',
|
||||
\ 'asciidoc(AttributeList|ListLabel|Literal|SideBar|Source|Sect[0-9])',
|
||||
\ 'asciidoc[A-Za-z]*(Block|Macro|Title)',
|
||||
\ ]
|
||||
let g:pencil#autoformat_config = {
|
||||
\ 'markdown': {
|
||||
\ 'black': [
|
||||
\ 'htmlH[0-9]',
|
||||
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode|Snippet)',
|
||||
\ 'mmdTable[A-Za-z0-9]*',
|
||||
\ ],
|
||||
\ 'white': [
|
||||
\ 'markdown(Code|Link)',
|
||||
\ ],
|
||||
\ },
|
||||
\ 'asciidoc': {
|
||||
\ 'black': [
|
||||
\ 'asciidoc(AttributeList|AttributeEntry|ListLabel|Literal|SideBar|Source|Sect[0-9])',
|
||||
\ 'asciidoc[A-Za-z]*(Block|Macro|Title)',
|
||||
\ ],
|
||||
\ 'white': [
|
||||
\ 'asciidoc(AttributeRef|Macro)',
|
||||
\ ],
|
||||
\ 'enforce-previous-line': 1,
|
||||
\ },
|
||||
\ 'rst': {
|
||||
\ 'black': [
|
||||
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
|
||||
\ ],
|
||||
\ },
|
||||
\ 'tex': {
|
||||
\ 'black': [
|
||||
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Statement|Title)',
|
||||
\ 'texSection$',
|
||||
\ ],
|
||||
\ 'enforce-previous-line': 1,
|
||||
\ },
|
||||
\ 'textile': {
|
||||
\ 'black': [
|
||||
\ 'txtCode',
|
||||
\ ],
|
||||
\ },
|
||||
\ 'pandoc': {
|
||||
\ 'black': [
|
||||
\ '^pandoc.*Code.*',
|
||||
\ 'pandocHTML',
|
||||
\ 'pandocLaTeXMathBlock',
|
||||
\ '^pandoc.*List.*',
|
||||
\ '^pandoc.*Table.*',
|
||||
\ 'pandocYAMLHeader',
|
||||
\ ],
|
||||
\ }
|
||||
\ }
|
||||
en
|
||||
let g:pencil#autoformat_blacklist_re =
|
||||
\ '\v(' . join(g:pencil#autoformat_blacklist, '|') . ')'
|
||||
|
||||
if !exists('g:pencil#autoformat_inline_whitelist')
|
||||
" grant autoformat a reprieve (allow enabling) if any of
|
||||
" following syntax groups doesn't dominate the whole line
|
||||
"
|
||||
"'markdownCode' (tpope/vim-markdown)
|
||||
let g:pencil#autoformat_inline_whitelist = [
|
||||
\ 'markdown(Code|Link)',
|
||||
\ 'asciidoc(AttributeRef|Macro)',
|
||||
\ ]
|
||||
if !exists('g:pencil#autoformat_aliases')
|
||||
" Aliases used exclusively for autoformat config.
|
||||
" Pencil will NOT modify the filetype setting.
|
||||
let g:pencil#autoformat_aliases = {
|
||||
\ 'md': 'markdown',
|
||||
\ 'mkd': 'markdown',
|
||||
\ }
|
||||
en
|
||||
let g:pencil#autoformat_inline_whitelist_re =
|
||||
\ '\v(' . join(g:pencil#autoformat_inline_whitelist, '|') . ')'
|
||||
|
||||
if !exists('g:pencil#joinspaces')
|
||||
" by default, only one space after full stop (.)
|
||||
@@ -136,9 +170,9 @@ en
|
||||
if !exists('g:pencil#mode_indicators')
|
||||
" used to set PencilMode() for statusline
|
||||
if s:unicode_enabled()
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'soft': '⤸', 'off': '',}
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'auto': 'ª', 'soft': '⤸', 'off': '',}
|
||||
el
|
||||
let g:pencil#mode_indicators = {'hard': 'H', 'soft': 'S', 'off': '',}
|
||||
let g:pencil#mode_indicators = {'hard': 'H', 'auto': 'A', 'soft': 'S', 'off': '',}
|
||||
en
|
||||
en
|
||||
|
||||
@@ -157,9 +191,10 @@ com -nargs=0 PFormat call pencil#setAutoFormat(1)
|
||||
com -nargs=0 PFormatOff call pencil#setAutoFormat(0)
|
||||
com -nargs=0 PFormatToggle call pencil#setAutoFormat(-1)
|
||||
|
||||
" NOTE: legacy commands will be disabled by default on 31-Dec-15
|
||||
" NOTE: legacy commands have been disabled by default as of 31-Dec-15
|
||||
" These will be removed entirely on 31-Dec-16
|
||||
if !exists('g:pencil#legacyCommands')
|
||||
let g:pencil#legacyCommands = 1
|
||||
let g:pencil#legacyCommands = 0
|
||||
en
|
||||
if g:pencil#legacyCommands
|
||||
com -nargs=0 DropPencil call pencil#init({'wrap': 'off' })
|
||||
|
||||
Reference in New Issue
Block a user