Removed pencil plugin
This commit is contained in:
parent
7c52136278
commit
dc8539ff79
@ -1,23 +0,0 @@
|
||||
License: The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013,2014 Reed Esau
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
<!-- vim: set tw=74 :-->
|
||||
@ -1,696 +0,0 @@
|
||||
# vim-pencil
|
||||
|
||||
> Rethinking Vim as a tool for writers
|
||||
|
||||
<br/>
|
||||
|
||||
- - -
|
||||

|
||||
- - -
|
||||
|
||||
# Features
|
||||
|
||||
The _pencil_ plugin aspires to make Vim as powerful a tool for writers as
|
||||
it is for coders by focusing narrowly on the handful of tweaks needed to
|
||||
smooth the path to writing prose.
|
||||
|
||||
* For editing prose-oriented file types such as _text_, _markdown_,
|
||||
_mail_, _rst_, _tex_, _textile_, and _asciidoc_
|
||||
* Agnostic on soft line wrap _versus_ hard line breaks, supporting both
|
||||
* Auto-detects wrap mode via `modeline` and sampling
|
||||
* 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>`
|
||||
* 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
|
||||
(e.g., `_` and `*` markup for styled text in \_*Markdown*\_)
|
||||
* 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.
|
||||
|
||||
# Why use Vim for writing?
|
||||
|
||||
With plenty of word processing applications available, including those
|
||||
that specifically cater to writers, why use a modal editor like Vim?
|
||||
Several reasons have been offered:
|
||||
|
||||
* Your hands can rest in a neutral ‘home’ position, only rarely straying
|
||||
to reach for mouse, track pad, or arrow keys
|
||||
* Minimal chording, with many mnemonic-friendly commands
|
||||
* Sophisticated capabilities for navigating and manipulating text
|
||||
* Highly configurable, enabling you to build a workflow that suits your
|
||||
needs, with many great plugins available
|
||||
* No proprietary format lock-in
|
||||
|
||||
But while such reasons might be sound, they remain scant justification to
|
||||
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`
|
||||
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
|
||||
modifiers. Think of them as the composable building blocks of a _domain
|
||||
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)
|
||||
* [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
|
||||
|
||||
_pencil_ is best installed using a Vim package manager, such as
|
||||
[Vundle][vnd], [Plug][plg], [NeoBundle][nbn], or [Pathogen][pth].
|
||||
|
||||
_For those new to Vim: before installing this plugin, consider getting
|
||||
comfortable with the basics of Vim by working through one of the many
|
||||
tutorials available._
|
||||
|
||||
[vnd]: https://github.com/gmarik/Vundle.vim
|
||||
[plg]: https://github.com/junegunn/vim-plug
|
||||
[nbn]: https://github.com/Shougo/neobundle.vim
|
||||
[pth]: https://github.com/tpope/vim-pathogen
|
||||
|
||||
#### Vundle
|
||||
|
||||
Add to your `.vimrc` and save:
|
||||
|
||||
```vim
|
||||
Plugin 'reedes/vim-pencil'
|
||||
```
|
||||
|
||||
…then run the following in Vim:
|
||||
|
||||
```vim
|
||||
:source %
|
||||
:PluginInstall
|
||||
```
|
||||
|
||||
#### Plug
|
||||
|
||||
Add to your `.vimrc` and save:
|
||||
|
||||
```vim
|
||||
Plug 'reedes/vim-pencil'
|
||||
```
|
||||
|
||||
…then run the following in Vim:
|
||||
|
||||
```vim
|
||||
:source %
|
||||
:PlugInstall
|
||||
```
|
||||
|
||||
#### NeoBundle
|
||||
|
||||
Add to your `.vimrc` and save:
|
||||
|
||||
```vim
|
||||
NeoBundle 'reedes/vim-pencil'
|
||||
```
|
||||
|
||||
…then run the following in Vim:
|
||||
|
||||
```vim
|
||||
:source %
|
||||
:NeoBundleInstall
|
||||
```
|
||||
|
||||
#### Pathogen
|
||||
|
||||
Run the following in a terminal:
|
||||
|
||||
```bash
|
||||
cd ~/.vim/bundle
|
||||
git clone https://github.com/reedes/vim-pencil
|
||||
```
|
||||
|
||||
# Configuration
|
||||
|
||||
## Initializing by command
|
||||
|
||||
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 file types to your `.vimrc`:
|
||||
|
||||
```vim
|
||||
set nocompatible
|
||||
filetype plugin on " may already be in your .vimrc
|
||||
|
||||
augroup pencil
|
||||
autocmd!
|
||||
autocmd FileType markdown,mkd call pencil#init()
|
||||
autocmd FileType text call pencil#init()
|
||||
augroup END
|
||||
```
|
||||
|
||||
You can initialize several prose-oriented plugins together:
|
||||
|
||||
```vim
|
||||
augroup pencil
|
||||
autocmd!
|
||||
autocmd FileType markdown,mkd call pencil#init()
|
||||
\ | call lexical#init()
|
||||
\ | call litecorrect#init()
|
||||
\ | call textobj#quote#init()
|
||||
\ | call textobj#sentence#init()
|
||||
augroup END
|
||||
```
|
||||
|
||||
For a list of other prose-oriented plugins, consult the [See
|
||||
also](#see-also) section below.
|
||||
|
||||
## Hard line breaks or soft line wrap?
|
||||
|
||||
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
|
||||
can configure each buffer independently.
|
||||
|
||||
In most cases you can set a default to suit your preference and let
|
||||
auto-detection figure out what to do.
|
||||
|
||||
```vim
|
||||
let g:pencil#wrapModeDefault = 'soft' " default is 'hard'
|
||||
|
||||
augroup pencil
|
||||
autocmd!
|
||||
autocmd FileType markdown,mkd call pencil#init()
|
||||
autocmd FileType text call pencil#init({'wrap': 'hard'})
|
||||
augroup END
|
||||
```
|
||||
|
||||
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 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
|
||||
only._
|
||||
|
||||
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.
|
||||
|
||||
To set the default behavior in your `.vimrc`:
|
||||
|
||||
```vim
|
||||
let g:pencil#autoformat = 1 " 0=disable, 1=enable (def)
|
||||
```
|
||||
|
||||
You can override this default during initialization, as in:
|
||||
|
||||
```vim
|
||||
augroup pencil
|
||||
autocmd!
|
||||
autocmd FileType markdown call pencil#init({'wrap': 'hard', 'autoformat': 1})
|
||||
autocmd FileType text call pencil#init({'wrap': 'hard', 'autoformat': 0})
|
||||
...
|
||||
augroup END
|
||||
```
|
||||
|
||||
...where buffers of type `markdown` and `text` will use hard line breaks,
|
||||
but `text` buffers will have autoformat disabled.
|
||||
|
||||
## 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.
|
||||
|
||||
[**NEW**] Second, where blacklisting falls short, you can optionally map
|
||||
a buffer-scoped ‘modifier’ key to suspend autoformat during the next
|
||||
Insert:
|
||||
|
||||
```vim
|
||||
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.
|
||||
|
||||
(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:
|
||||
|
||||
* `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
|
||||
|
||||
Optionally, you can map these operations to underutilized keys in your
|
||||
`.vimrc`:
|
||||
|
||||
```vim
|
||||
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 **Hard Pencil** mode when no
|
||||
textwidth is set globally, locally, or available via modeling. It
|
||||
defaults to `74`, but you can change that value in your `.vimrc`:
|
||||
|
||||
```vim
|
||||
let g:pencil#textwidth = 74
|
||||
```
|
||||
|
||||
## Sentence spacing
|
||||
|
||||
By default, when formatting text (through `gwip`, e.g.) only one space
|
||||
will be inserted after a period(`.`), exclamation point(`!`), or question
|
||||
mark(`?`). You can change this default:
|
||||
|
||||
```vim
|
||||
let g:pencil#joinspaces = 0 " 0=one_space (def), 1=two_spaces
|
||||
```
|
||||
|
||||
## Cursor wrap
|
||||
|
||||
By default, `h`/`l` and the left/right cursor keys will move to the
|
||||
previous/next line after reaching first/last character in a line with
|
||||
a hard break. If you wish to retain the default Vim behavior, set the
|
||||
`cursorwrap` value to `0` in your `.vimrc`:
|
||||
|
||||
```vim
|
||||
let g:pencil#cursorwrap = 1 " 0=disable, 1=enable (def)
|
||||
```
|
||||
|
||||
## Concealing \_\_markup\_\_
|
||||
|
||||
_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=one char, 2=hide char, 3=hide all (def)
|
||||
let g:pencil#concealcursor = 'c' " n=normal, v=visual, i=insert, c=command (def)
|
||||
```
|
||||
|
||||
For more details on Vim’s Conceal feature, see:
|
||||
|
||||
```vim
|
||||
:help conceallevel
|
||||
:help concealcursor
|
||||
```
|
||||
|
||||
### Concealing styled text in Markdown
|
||||
|
||||
Syntax plugins such as [tpope/vim-markdown][tm] support concealing the
|
||||
markup characters when displaying \_*italic*\_, \*\*__bold__\*\*, and
|
||||
\*\*\*___bold italic___\*\*\* styled text.
|
||||
|
||||
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_,
|
||||
**bold**, and ***bold italic*** style variant for styled text.
|
||||
|
||||
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
|
||||
visual selections.
|
||||
|
||||
**Terminal users:** consult your terminal’s documentation to configure your
|
||||
terminal to support **bold** and _italic_ styles.
|
||||
|
||||
[co]: http://www.google.com/fonts/specimen/Cousine
|
||||
[tm]: http://github.com/tpope/vim-markdown
|
||||
|
||||
## Status line indicator
|
||||
|
||||
Your status line can reflect the wrap mode for _pencil_ buffers. For
|
||||
example, `␍` to represent `HardPencil` (hard line break) mode. To
|
||||
configure your status line and ruler, add to your `.vimrc`:
|
||||
|
||||
```vim
|
||||
set statusline=%<%f\ %h%m%r%w\ \ %{PencilMode()}\ %=\ col\ %c%V\ \ line\ %l\,%L\ %P
|
||||
set rulerformat=%-12.(%l,%c%V%)%{PencilMode()}\ %P
|
||||
```
|
||||
|
||||
or if using [bling/vim-airline][va]:
|
||||
|
||||
```vim
|
||||
let g:airline_section_x = '%{PencilMode()}'
|
||||
```
|
||||
|
||||
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': '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.
|
||||
|
||||
[va]: http://github.com/bling/vim-airline
|
||||
|
||||
## Advanced pencil
|
||||
|
||||
### Advanced initialization
|
||||
|
||||
You may want to refactor initialization statements into a function in
|
||||
your `.vimrc` to set up a buffer for writing:
|
||||
|
||||
```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
|
||||
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
|
||||
autocmd!
|
||||
autocmd FileType markdown,mkd call pencil#init()
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us fdl=4 noru nonu nornu
|
||||
\ | setl fdo+=search
|
||||
autocmd Filetype git,gitsendemail,*commit*,*COMMIT*
|
||||
\ call pencil#init({'wrap': 'hard', 'textwidth': 72})
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us et sw=2 ts=2 noai
|
||||
autocmd Filetype mail call pencil#init({'wrap': 'hard', 'textwidth': 60})
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us et sw=2 ts=2 noai nonu nornu
|
||||
autocmd Filetype html,xml call pencil#init({'wrap': 'soft'})
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us et sw=2 ts=2
|
||||
augroup END
|
||||
```
|
||||
|
||||
Configurable options for `pencil#init()` include: `autoformat`,
|
||||
`concealcursor`, `conceallevel`, `cursorwrap`, `joinspaces`, `textwidth`,
|
||||
and `wrap`. These are detailed above.
|
||||
|
||||
### Autoformat manual control
|
||||
|
||||
_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 autoformat suspended for the duration of the Insert.
|
||||
|
||||
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.
|
||||
|
||||
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_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]
|
||||
\ }
|
||||
```
|
||||
|
||||
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,
|
||||
_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
|
||||
buffer.
|
||||
|
||||
#### Detect via modeline
|
||||
|
||||
Will the wrap mode be detected accurately? Maybe. But you can improve its
|
||||
chances by giving _pencil_ an explicit hint.
|
||||
|
||||
At the bottom of this document is a odd-looking code:
|
||||
|
||||
```html
|
||||
<!-- vim: set tw=73 :-->
|
||||
```
|
||||
|
||||
This is an **optional** ‘modeline’ that tells Vim to run the following
|
||||
command upon loading the file into a buffer:
|
||||
|
||||
```vim
|
||||
:set textwidth=73
|
||||
```
|
||||
|
||||
It tells _pencil_ to assume hard line breaks, regardless of whether or
|
||||
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`:
|
||||
|
||||
```html
|
||||
<!-- vim: set tw=0 :-->
|
||||
```
|
||||
|
||||
Note that if the modelines feature is disabled (such as for security
|
||||
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 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 buffer:
|
||||
|
||||
```vim
|
||||
let g:pencil#softDetectSample = 20
|
||||
```
|
||||
|
||||
Set that value to `0` to disable detection via line sampling.
|
||||
|
||||
When the number of bytes on a sampled line per exceeds this next value,
|
||||
then _pencil_ assumes soft line wrap.
|
||||
|
||||
```vim
|
||||
let g:pencil#softDetectThreshold = 130
|
||||
```
|
||||
|
||||
If no such lines found, _pencil_ falls back to the default wrap mode.
|
||||
|
||||
# See also
|
||||
|
||||
* [To Vim][tv] - Writer and psychologist Ian Hocking on using Vim for writing
|
||||
* [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
|
||||
* [Writing with Vim][wwv] (2015) - by Pat Ambrosio
|
||||
|
||||
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/
|
||||
[wwv]: https://lilii.co/aardvark/writing-with-vim
|
||||
[vic]: https://labs.tomasino.org/vim-in-context.html
|
||||
[rewp]: http://usevim.com/2015/05/27/reedes/
|
||||
[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
|
||||
[jg]: http://github.com/junegunn/goyo.vim
|
||||
|
||||
Markdown syntax plugins
|
||||
|
||||
* [tpope/vim-markdown][tvm] - the latest version of the syntax plugin that ships with Vim
|
||||
* [plasticboy/vim-markdown][pvm]
|
||||
* [gabrielelana/vim-markdown][gvm]
|
||||
* [mattly/vim-markdown-enhancements][mvme] - highlighting for tables and footnotes
|
||||
|
||||
[tvm]: http://github.com/tpope/vim-markdown
|
||||
[pvm]: http://github.com/plasticboy/vim-markdown
|
||||
[gvm]: http://github.com/gabrielelana/vim-markdown
|
||||
[mvme]: http://github.com/mattly/vim-markdown-enhancements
|
||||
|
||||
If you find the _pencil_ plugin useful, check out these others by [@reedes][re]:
|
||||
|
||||
* [vim-colors-pencil][cp] - color scheme for Vim inspired by IA Writer
|
||||
* [vim-lexical][lx] - building on Vim’s spell-check and thesaurus/dictionary completion
|
||||
* [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-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
|
||||
|
||||
Unimpressed by _pencil_? [vim-pandoc][vp] offers prose-oriented features
|
||||
with its own Markdown variant.
|
||||
|
||||
[cp]: http://github.com/reedes/vim-colors-pencil
|
||||
[lc]: http://github.com/reedes/vim-litecorrect
|
||||
[lx]: http://github.com/reedes/vim-lexical
|
||||
[qu]: http://github.com/reedes/vim-textobj-quote
|
||||
[re]: http://github.com/reedes
|
||||
[tc]: https://www.youtube.com/watch?v=Nim4_f5QUxA
|
||||
[th]: http://github.com/reedes/vim-thematic
|
||||
[ts]: http://github.com/reedes/vim-textobj-sentence
|
||||
[tv]: http://ianhocking.com/2013/11/17/to-vim/
|
||||
[vo]: http://github.com/reedes/vim-one
|
||||
[vw]: http://therandymon.com/woodnotes/vim-for-writers/vimforwriters.html
|
||||
[wh]: http://github.com/reedes/vim-wheel
|
||||
[wo]: http://github.com/reedes/vim-wordy
|
||||
[vp]: http://github.com/vim-pandoc/vim-pandoc
|
||||
|
||||
# Future development
|
||||
|
||||
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 :-->
|
||||
```
|
||||
@ -1,514 +0,0 @@
|
||||
" ============================================================================
|
||||
" File: pencil.vim
|
||||
" Description: autoload functions for vim-pencil plugin
|
||||
" Maintainer: Reed Esau <github.com/reedes>
|
||||
" Created: December 28, 2013
|
||||
" License: The MIT License (MIT)
|
||||
" ============================================================================
|
||||
if exists("autoloaded_pencil") | fini | en
|
||||
let autoloaded_pencil = 1
|
||||
|
||||
let s:WRAP_MODE_DEFAULT = -1
|
||||
let s:WRAP_MODE_OFF = 0
|
||||
let s:WRAP_MODE_HARD = 1
|
||||
let s:WRAP_MODE_SOFT = 2
|
||||
|
||||
" Wrap-mode detector
|
||||
" Scan lines at end and beginning of file to determine the wrap mode.
|
||||
" Modelines has priority over long lines found.
|
||||
fun! s:detect_wrap_mode() abort
|
||||
|
||||
let b:max_textwidth = -1 " assume no relevant modeline
|
||||
call s:doModelines()
|
||||
|
||||
if b:max_textwidth > 0
|
||||
" modelines(s) found with positive textwidth, so hard line breaks
|
||||
return s:WRAP_MODE_HARD
|
||||
en
|
||||
|
||||
if b:max_textwidth ==# 0 || g:pencil#wrapModeDefault ==# 'soft'
|
||||
" modeline(s) found only with zero textwidth, so it's soft line wrap
|
||||
" or, the user wants to default to soft line wrap
|
||||
return s:WRAP_MODE_SOFT
|
||||
en
|
||||
|
||||
" attempt to rule out soft line wrap
|
||||
" scan initial lines in an attempt to detect long lines
|
||||
for l:line in getline(1, g:pencil#softDetectSample)
|
||||
if len(l:line) > g:pencil#softDetectThreshold
|
||||
return s:WRAP_MODE_SOFT
|
||||
en
|
||||
endfo
|
||||
|
||||
" punt
|
||||
return s:WRAP_MODE_DEFAULT
|
||||
endf
|
||||
|
||||
fun! s:imap(preserve_completion, key, icmd) abort
|
||||
if a:preserve_completion
|
||||
exe ":ino <buffer> <silent> <expr> " . a:key . " pumvisible() ? \"" . a:key . "\" : \"" . a:icmd . "\""
|
||||
el
|
||||
exe ":ino <buffer> <silent> " . a:key . " " . a:icmd
|
||||
en
|
||||
endf
|
||||
|
||||
fun! s:maybe_enable_autoformat() abort
|
||||
" 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('.')
|
||||
let l:last_col = col('$')
|
||||
let l:stack = []
|
||||
let l:found_empty = 0
|
||||
" at end of line there may be no synstack, so scan back
|
||||
while l:col > 0
|
||||
let l:stack = synstack(l:line, l:col)
|
||||
if l:stack != []
|
||||
break
|
||||
en
|
||||
" the last column will always be empty, so ignore it
|
||||
if l:col < l:last_col
|
||||
let l:found_empty = 1
|
||||
en
|
||||
let l:col -= 1
|
||||
endw
|
||||
" if needed, scan towards end of line looking for highlight groups
|
||||
if l:stack == []
|
||||
let l:col = col('.') + 1
|
||||
while l:col <= l:last_col
|
||||
let l:stack = synstack(l:line, l:col)
|
||||
if l:stack != []
|
||||
break
|
||||
en
|
||||
" the last column will always be empty, so ignore it
|
||||
if l:col < l:last_col
|
||||
let l:found_empty = 1
|
||||
en
|
||||
let l:col += 1
|
||||
endw
|
||||
en
|
||||
" enforce blacklist by scanning for syntax matches
|
||||
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
|
||||
if synstack(l:line, 1) == [] ||
|
||||
\ (l:last_col > 1 && synstack(l:line, l:last_col-1) == [])
|
||||
let l:found_empty = 1
|
||||
en
|
||||
en
|
||||
if l:found_empty
|
||||
for l:sid in l:stack
|
||||
if match(synIDattr(l:sid, 'name'), l:white_re) >= 0
|
||||
let l:okay_to_enable = 1
|
||||
break
|
||||
en
|
||||
endfo
|
||||
en
|
||||
en
|
||||
" disallow enable if start of previous line is in blacklist,
|
||||
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'), l:black_re) >= 0
|
||||
let l:okay_to_enable = 0
|
||||
break
|
||||
en
|
||||
endfo
|
||||
en
|
||||
if l:okay_to_enable
|
||||
set formatoptions+=a
|
||||
en
|
||||
endf
|
||||
|
||||
fun! pencil#setAutoFormat(af) abort
|
||||
" 1=enable, 0=disable, -1=toggle
|
||||
if !exists('b:last_autoformat')
|
||||
let b:last_autoformat = 0
|
||||
en
|
||||
let l:nu_af = a:af ==# -1 ? !b:last_autoformat : a:af
|
||||
let l:is_hard =
|
||||
\ exists('b:pencil_wrap_mode') &&
|
||||
\ b:pencil_wrap_mode ==# s:WRAP_MODE_HARD
|
||||
if l:nu_af && l:is_hard
|
||||
aug pencil_autoformat
|
||||
au InsertEnter <buffer> call s:maybe_enable_autoformat()
|
||||
au InsertLeave <buffer> set formatoptions-=a
|
||||
aug END
|
||||
el
|
||||
sil! au! pencil_autoformat * <buffer>
|
||||
if l:nu_af && !l:is_hard
|
||||
echohl WarningMsg
|
||||
echo "autoformat can only be enabled in hard line break mode"
|
||||
echohl NONE
|
||||
return
|
||||
en
|
||||
en
|
||||
let b:last_autoformat = l:nu_af
|
||||
endf
|
||||
|
||||
" Create mappings for word processing
|
||||
" args:
|
||||
" 'wrap': 'detect|off|hard|soft|toggle'
|
||||
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
|
||||
if !exists("b:max_textwidth")
|
||||
let b:max_textwidth = -1
|
||||
en
|
||||
|
||||
" If user explicitly requested wrap_mode thru args, go with that.
|
||||
let l:wrap_arg = get(l:args, 'wrap', 'detect')
|
||||
|
||||
if (b:pencil_wrap_mode && l:wrap_arg ==# 'toggle') ||
|
||||
\ l:wrap_arg =~# '^\(0\|off\|disable\|false\)$'
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_OFF
|
||||
elsei l:wrap_arg ==# 'hard'
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_HARD
|
||||
elsei l:wrap_arg ==# 'soft'
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_SOFT
|
||||
elsei l:wrap_arg ==# 'default'
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_DEFAULT
|
||||
el
|
||||
" this can return s:WRAP_MODE_ for soft, hard or default
|
||||
let b:pencil_wrap_mode = s:detect_wrap_mode()
|
||||
en
|
||||
|
||||
" translate default(-1) to soft(1) or hard(2) or off(0)
|
||||
if b:pencil_wrap_mode ==# s:WRAP_MODE_DEFAULT
|
||||
if g:pencil#wrapModeDefault =~# '^\(0\|off\|disable\|false\)$'
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_OFF
|
||||
elsei g:pencil#wrapModeDefault ==# 'soft'
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_SOFT
|
||||
el
|
||||
let b:pencil_wrap_mode = s:WRAP_MODE_HARD
|
||||
en
|
||||
en
|
||||
|
||||
" autoformat is only used in Hard mode, and then only during
|
||||
" Insert mode
|
||||
call pencil#setAutoFormat(
|
||||
\ b:pencil_wrap_mode ==# s:WRAP_MODE_HARD &&
|
||||
\ get(l:args, 'autoformat', g:pencil#autoformat))
|
||||
|
||||
if b:pencil_wrap_mode ==# s:WRAP_MODE_HARD
|
||||
if &modeline ==# 0 && b:max_textwidth > 0
|
||||
" Compensate for disabled modeline
|
||||
exe 'setl textwidth=' . b:max_textwidth
|
||||
elsei &textwidth ==# 0
|
||||
exe 'setl textwidth=' .
|
||||
\ get(l:args, 'textwidth', g:pencil#textwidth)
|
||||
el
|
||||
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
|
||||
|
||||
if has('linebreak')
|
||||
setl linebreak
|
||||
" TODO breakat not working yet with n and m-dash
|
||||
setl breakat-=* " avoid breaking footnote*
|
||||
setl breakat-=@ " avoid breaking at email addresses
|
||||
en
|
||||
|
||||
if exists('&colorcolumn')
|
||||
setl colorcolumn=0 " doesn't align as expected
|
||||
en
|
||||
el
|
||||
setl textwidth<
|
||||
setl wrap< nowrap<
|
||||
|
||||
if has('linebreak')
|
||||
setl linebreak< nolinebreak<
|
||||
setl breakat<
|
||||
en
|
||||
|
||||
if exists('&colorcolumn')
|
||||
setl colorcolumn<
|
||||
en
|
||||
en
|
||||
|
||||
if ( v:version > 704 ||
|
||||
\ (v:version ==# 704 && has('patch-7.4.338')))
|
||||
if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT
|
||||
setl breakindent
|
||||
el
|
||||
setl breakindent<
|
||||
en
|
||||
en
|
||||
|
||||
" global settings
|
||||
if b:pencil_wrap_mode
|
||||
set display+=lastline
|
||||
set backspace=indent,eol,start
|
||||
if get(l:args, 'joinspaces', g:pencil#joinspaces)
|
||||
set joinspaces " two spaces after .!?
|
||||
el
|
||||
set nojoinspaces " only one space after a .!? (default)
|
||||
en
|
||||
en
|
||||
|
||||
" because ve=onemore is relatively rare and could break
|
||||
" other plugins, restrict its presence to buffer
|
||||
" Better: restore ve to original setting
|
||||
if has('virtualedit')
|
||||
if b:pencil_wrap_mode && get(l:args, 'cursorwrap', g:pencil#cursorwrap)
|
||||
set whichwrap+=<,>,b,s,h,l,[,]
|
||||
aug pencil_cursorwrap
|
||||
au BufEnter <buffer> set virtualedit+=onemore
|
||||
au BufLeave <buffer> set virtualedit-=onemore
|
||||
aug END
|
||||
el
|
||||
sil! au! pencil_cursorwrap * <buffer>
|
||||
en
|
||||
en
|
||||
|
||||
" Because syntax for fenced code blocks will mess with the
|
||||
" definition of a word (via iskeyword) we'll impose a prose-
|
||||
" oriented definition.
|
||||
" e.g., let g:markdown_fenced_languages = ['sh',] " adds '.'
|
||||
"
|
||||
" Support $20 30% D&D #40 highest-rated O'Toole Mary's
|
||||
" TODO how to separate quote from apostrophe use?
|
||||
if b:pencil_wrap_mode
|
||||
aug pencil_iskeyword
|
||||
au BufEnter <buffer> setl isk& | setl isk-=_ | setl isk+=$,%,&,#,-,',+
|
||||
aug END
|
||||
el
|
||||
sil! au! pencil_iskeyword * <buffer>
|
||||
en
|
||||
|
||||
" window/buffer settings
|
||||
if b:pencil_wrap_mode
|
||||
setl nolist
|
||||
setl wrapmargin=0
|
||||
setl autoindent " needed by formatoptions=n
|
||||
setl indentexpr=
|
||||
if has('smartindent')
|
||||
setl nosmartindent " avoid c-style indents in prose
|
||||
en
|
||||
if has('cindent')
|
||||
setl nocindent " avoid c-style indents in prose
|
||||
en
|
||||
|
||||
setl formatoptions+=n " recognize numbered lists
|
||||
setl formatoptions+=1 " don't break line before 1 letter word
|
||||
setl formatoptions+=t " autoformat of text (vim default)
|
||||
"setl formatoptions+=2 " preserve indent based on 2nd line for rest of paragraph
|
||||
|
||||
" clean out stuff we likely don't want
|
||||
setl formatoptions-=v " only break line at blank entered during insert
|
||||
setl formatoptions-=w " avoid erratic behavior if mixed spaces
|
||||
setl formatoptions-=a " autoformat will turn on with Insert in HardPencil mode
|
||||
setl formatoptions-=2 " doesn't work with with fo+=n, says docs
|
||||
|
||||
" plasticboy/vim-markdown sets these to handle bullet points
|
||||
" as comments. Not changing for now.
|
||||
"setl formatoptions-=o " don't insert comment leader
|
||||
"setl formatoptions-=c " no autoformat of comments
|
||||
"setl formatoptions+=r " don't insert comment leader
|
||||
|
||||
if has('conceal') && v:version >= 703
|
||||
exe ':setl conceallevel=' .
|
||||
\ get(l:args, 'conceallevel', g:pencil#conceallevel)
|
||||
exe ':setl concealcursor=' .
|
||||
\ get(l:args, 'concealcursor', g:pencil#concealcursor)
|
||||
en
|
||||
el
|
||||
if has('smartindent')
|
||||
setl smartindent< nosmartindent<
|
||||
en
|
||||
if has('cindent')
|
||||
setl cindent< nocindent<
|
||||
en
|
||||
if has('conceal')
|
||||
setl conceallevel<
|
||||
setl concealcursor<
|
||||
en
|
||||
|
||||
setl indentexpr<
|
||||
setl autoindent< noautoindent<
|
||||
setl list< nolist<
|
||||
setl wrapmargin<
|
||||
setl formatoptions<
|
||||
en
|
||||
|
||||
if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT
|
||||
nn <buffer> <silent> $ g$
|
||||
nn <buffer> <silent> 0 g0
|
||||
vn <buffer> <silent> $ g$
|
||||
vn <buffer> <silent> 0 g0
|
||||
no <buffer> <silent> <Home> g<Home>
|
||||
no <buffer> <silent> <End> g<End>
|
||||
|
||||
" preserve behavior of home/end keys in popups
|
||||
call s:imap(1, '<Home>', '<C-o>g<Home>')
|
||||
call s:imap(1, '<End>' , '<C-o>g<End>' )
|
||||
el
|
||||
sil! nun <buffer> $
|
||||
sil! nun <buffer> 0
|
||||
sil! vu <buffer> $
|
||||
sil! vu <buffer> 0
|
||||
sil! nun <buffer> <Home>
|
||||
sil! nun <buffer> <End>
|
||||
sil! iu <buffer> <Home>
|
||||
sil! iu <buffer> <End>
|
||||
en
|
||||
|
||||
if b:pencil_wrap_mode
|
||||
nn <buffer> <silent> j gj
|
||||
nn <buffer> <silent> k gk
|
||||
vn <buffer> <silent> j gj
|
||||
vn <buffer> <silent> k gk
|
||||
no <buffer> <silent> <Up> gk
|
||||
no <buffer> <silent> <Down> gj
|
||||
|
||||
" preserve behavior of up/down keys in popups
|
||||
call s:imap(1, '<Up>' , '<C-o>g<Up>' )
|
||||
call s:imap(1, '<Down>', '<C-o>g<Down>')
|
||||
el
|
||||
sil! nun <buffer> j
|
||||
sil! nun <buffer> k
|
||||
sil! vu <buffer> j
|
||||
sil! vu <buffer> k
|
||||
sil! unm <buffer> <Up>
|
||||
sil! unm <buffer> <Down>
|
||||
|
||||
sil! iu <buffer> <Up>
|
||||
sil! iu <buffer> <Down>
|
||||
en
|
||||
|
||||
" set undo points around common punctuation,
|
||||
" line <c-u> and word <c-w> deletions
|
||||
if b:pencil_wrap_mode
|
||||
ino <buffer> . .<c-g>u
|
||||
ino <buffer> ! !<c-g>u
|
||||
ino <buffer> ? ?<c-g>u
|
||||
ino <buffer> , ,<c-g>u
|
||||
ino <buffer> ; ;<c-g>u
|
||||
ino <buffer> : :<c-g>u
|
||||
ino <buffer> <c-u> <c-g>u<c-u>
|
||||
ino <buffer> <c-w> <c-g>u<c-w>
|
||||
|
||||
" 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> !
|
||||
sil! iu <buffer> ?
|
||||
sil! iu <buffer> ,
|
||||
sil! iu <buffer> ;
|
||||
sil! iu <buffer> :
|
||||
sil! iu <buffer> <c-u>
|
||||
sil! iu <buffer> <c-w>
|
||||
|
||||
" 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
|
||||
|
||||
" attempt to find a non-zero textwidth, etc.
|
||||
fun! s:doOne(item) abort
|
||||
let l:matches = matchlist(a:item, '^\([a-z]\+\)=\([a-zA-Z0-9_\-.]\+\)$')
|
||||
if len(l:matches) > 1
|
||||
if l:matches[1] =~ 'textwidth\|tw'
|
||||
let l:tw = str2nr(l:matches[2])
|
||||
if l:tw > b:max_textwidth
|
||||
let b:max_textwidth = l:tw
|
||||
en
|
||||
en
|
||||
en
|
||||
endf
|
||||
|
||||
" attempt to find a non-zero textwidth, etc.
|
||||
fun! s:doModeline(line) abort
|
||||
let l:matches = matchlist(a:line, '\%(\S\@<!\%(vi\|vim\([<>=]\?\)\([0-9]\+\)\?\)\|\sex\):\s*\%(set\s\+\)\?\([^:]\+\):\S\@!')
|
||||
if len(l:matches) > 0
|
||||
for l:item in split(l:matches[3])
|
||||
call s:doOne(l:item)
|
||||
endfo
|
||||
en
|
||||
let l:matches = matchlist(a:line, '\%(\S\@<!\%(vi\|vim\([<>=]\?\)\([0-9]\+\)\?\)\|\sex\):\(.\+\)')
|
||||
if len(l:matches) > 0
|
||||
for l:item in split(l:matches[3], '[ \t:]')
|
||||
call s:doOne(l:item)
|
||||
endfo
|
||||
en
|
||||
endf
|
||||
|
||||
" sample lines for detection, capturing both
|
||||
" modeline(s) and max line length
|
||||
" Hat tip to https://github.com/ciaranm/securemodelines
|
||||
fun! s:doModelines() abort
|
||||
if line("$") > &modelines
|
||||
let l:lines={ }
|
||||
call map(filter(getline(1, &modelines) +
|
||||
\ getline(line("$") - &modelines, "$"),
|
||||
\ 'v:val =~ ":"'), 'extend(l:lines, { v:val : 0 } )')
|
||||
for l:line in keys(l:lines)
|
||||
call s:doModeline(l:line)
|
||||
endfo
|
||||
el
|
||||
for l:line in getline(1, "$")
|
||||
call s:doModeline(l:line)
|
||||
endfo
|
||||
en
|
||||
endf
|
||||
|
||||
" vim:ts=2:sw=2:sts=2
|
||||
@ -1,198 +0,0 @@
|
||||
" ============================================================================
|
||||
" File: pencil.vim
|
||||
" Description: vim-pencil plugin
|
||||
" Maintainer: Reed Esau <github.com/reedes>
|
||||
" Created: December 28, 2013
|
||||
" License: The MIT License (MIT)
|
||||
" ============================================================================
|
||||
"
|
||||
if exists('g:loaded_pencil') || &cp | fini | en
|
||||
let g:loaded_pencil = 1
|
||||
|
||||
" Save 'cpoptions' and set Vim default to enable line continuations.
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let s:WRAP_MODE_DEFAULT = -1
|
||||
let s:WRAP_MODE_OFF = 0
|
||||
let s:WRAP_MODE_HARD = 1
|
||||
let s:WRAP_MODE_SOFT = 2
|
||||
|
||||
fun! s:unicode_enabled()
|
||||
retu &encoding ==# 'utf-8'
|
||||
endf
|
||||
|
||||
" helper for statusline
|
||||
"
|
||||
" Note that it shouldn't be dependent on init(), which
|
||||
" won't have been called for non-prose modules.
|
||||
fun! PencilMode()
|
||||
if exists('b:pencil_wrap_mode')
|
||||
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
|
||||
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
|
||||
else
|
||||
return '' " should be blank for non-prose modes
|
||||
en
|
||||
endf
|
||||
|
||||
if !exists('g:pencil#wrapModeDefault')
|
||||
" user-overridable default, if detection fails
|
||||
" should be 'soft' or 'hard' or 'off'
|
||||
let g:pencil#wrapModeDefault = 'hard'
|
||||
en
|
||||
|
||||
if !exists('g:pencil#textwidth')
|
||||
" textwidth used when in hard linebreak mode
|
||||
let g:pencil#textwidth = 74
|
||||
en
|
||||
|
||||
if !exists('g:pencil#autoformat')
|
||||
" by default, automatically format text when in Insert mode
|
||||
" with hard wrap.
|
||||
let g:pencil#autoformat = 1
|
||||
en
|
||||
|
||||
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)
|
||||
" markdownFencedCodeBlock, markdownInlineCode, markdownRule, markdownH[0-9] (gabrielelana/vim-markdown)
|
||||
" 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_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)',
|
||||
\ ],
|
||||
\ },
|
||||
\ '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',
|
||||
\ ],
|
||||
\ },
|
||||
\ }
|
||||
en
|
||||
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
|
||||
|
||||
if !exists('g:pencil#joinspaces')
|
||||
" by default, only one space after full stop (.)
|
||||
let g:pencil#joinspaces = 0
|
||||
en
|
||||
|
||||
if !exists('g:pencil#cursorwrap')
|
||||
" by default, h/l and cursor keys will wrap around hard
|
||||
" linebreaks. Set to 0 if you don't want this behavior
|
||||
let g:pencil#cursorwrap = 1
|
||||
en
|
||||
|
||||
if !exists('g:pencil#conceallevel')
|
||||
" by default, concealing capability in your syntax plugin
|
||||
" will be enabled. See tpope/vim-markdown for example.
|
||||
" 0=disable, 1=onechar, 2=hidecust, 3=hideall
|
||||
let g:pencil#conceallevel = 3
|
||||
en
|
||||
if !exists('g:pencil#concealcursor')
|
||||
" n=normal, v=visual, i=insert, c=command
|
||||
let g:pencil#concealcursor = 'c'
|
||||
en
|
||||
|
||||
if !exists('g:pencil#softDetectSample')
|
||||
" if no modeline, read as many as this many lines at
|
||||
" start of file in attempt to detect at least one line
|
||||
" whose byte count exceeds g:pencil#softDetectThreshold
|
||||
let g:pencil#softDetectSample = 20
|
||||
en
|
||||
|
||||
if !exists('g:pencil#softDetectThreshold')
|
||||
" if the byte count of at least one sampled line exceeds
|
||||
" this number, then pencil assumes soft line wrapping
|
||||
let g:pencil#softDetectThreshold = 130
|
||||
en
|
||||
|
||||
if !exists('g:pencil#mode_indicators')
|
||||
" used to set PencilMode() for statusline
|
||||
if s:unicode_enabled()
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'auto': 'ª', 'soft': '⤸', 'off': '',}
|
||||
el
|
||||
let g:pencil#mode_indicators = {'hard': 'H', 'auto': 'A', 'soft': 'S', 'off': '',}
|
||||
en
|
||||
en
|
||||
|
||||
" Commands
|
||||
|
||||
com -nargs=0 Pencil call pencil#init({'wrap': 'on' })
|
||||
com -nargs=0 PencilOff call pencil#init({'wrap': 'off' })
|
||||
com -nargs=0 NoPencil call pencil#init({'wrap': 'off' })
|
||||
com -nargs=0 HardPencil call pencil#init({'wrap': 'hard'})
|
||||
com -nargs=0 PencilHard call pencil#init({'wrap': 'hard'})
|
||||
com -nargs=0 SoftPencil call pencil#init({'wrap': 'soft'})
|
||||
com -nargs=0 PencilSoft call pencil#init({'wrap': 'soft'})
|
||||
com -nargs=0 PencilToggle call pencil#init({'wrap': 'toggle'})
|
||||
com -nargs=0 TogglePencil call pencil#init({'wrap': 'toggle'})
|
||||
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 have been disabled by default as of 31-Dec-15
|
||||
if !exists('g:pencil#legacyCommands')
|
||||
let g:pencil#legacyCommands = 0
|
||||
en
|
||||
if g:pencil#legacyCommands
|
||||
com -nargs=0 DropPencil call pencil#init({'wrap': 'off' })
|
||||
com -nargs=0 AutoPencil call pencil#setAutoFormat(1)
|
||||
com -nargs=0 ManualPencil call pencil#setAutoFormat(0)
|
||||
com -nargs=0 ShiftPencil call pencil#setAutoFormat(-1)
|
||||
en
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:ts=2:sw=2:sts=2
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 626 KiB |
@ -1,7 +0,0 @@
|
||||
|
||||
Captured with Quicktime.
|
||||
|
||||
Processed with:
|
||||
|
||||
$ ffmpeg -i four.mov -s 700x242 -pix_fmt rgb24 -vf "lutyuv=y=val*1.3" -r 10 -f gif - | \
|
||||
gifsicle --optimize=3 --delay=3 > out.gif
|
||||
Loading…
x
Reference in New Issue
Block a user