preservim / vim-pencil Goto Github PK
View Code? Open in Web Editor NEWRethinking Vim as a tool for writing
License: Other
Rethinking Vim as a tool for writing
License: Other
Hello,
I am pretty new to Vim and I stumbled on your cool plugin. I like it a lot for editing Markdown files. In general I prefer a black theme (molokai) and CamingoCode as my default font.
But for editing Markdown files I would prefer to have Cousine as a font and vim-colors-pencil (light) as colourscheme. How can I automatically switch to that for Markdown files and switch automatically back to my default theme for non Markdown files?
I hope you can help me with that topic.
Greetings from Germany
Need to investigate behavior of the 'w' format option to determine if any benefits are had in adding support for it.
Found in a user's blacklist:
liquidYamlHead
When calling pencil#init({'wrap':'hard'}) on a window without a modeline:
Error detected while processing function pencil#init:
line 42:
E121: Undefined variable: b:max_textwidth
E15: Invalid expression: &modeline == 0 && b:max_textwidth > 0
E121: Undefined variable: b:max_textwidth
E15: Invalid expression: &modeline == 0 && b:max_textwidth > 0
I've tracked it down to line 109 of autoload/pencil.vim
, and it seems through some combination of conditionals that because I'm specifying hard mode, detect_wrap_mode()
never gets called, and this is where b:max_textwidth
gets set. It seems like there should be some sort of default, but looking over detect_wrap_mode()
I'm not entirely sure if that should be &textwidth
or not. I'll poke around a bit at it and see if setting that helps, but in the mean time I wanted to record the issue.
Hello,
Just wanna say that I love using MacVim as word processor with your plugins like thematic, vim-colors-pencil, vim-pencil, ... It'll be superb to change font size :) Is it possible to have multiple font sizes in the same file?
Thank you & best regards,
Artem
Given:
<!-- vim: tw=65 -->
"50k/4.md" 26L, 641C
Error detected while processing modelines:
line 26:
E518: Unknown option: -->
Press ENTER or type command to continue
Need combo of auto indent (already enabled) and fo+=2 to ensure that paragraph indent is preserved.
Word definitions in markdown shouldn't include a '.' by default, but if you define fenced code blocks the relevant syntax files (such as 'sh') may change that.
Try to restore a prose-oriented iskeyword, for example:
@,48-57,192-255
I remapped my movement keys from hjkl
to jkl;
. When I turn on pencil mode it is hard-coded to set j
to gj
(down) and k
to gk
(up).
Ideally, the plugin would remap the currently used movement keys for up/down to gj
and gk
.
How to reproduce:
" set russian keymap
set keymap=russian-jcukewin
" activate vim-pencil
:Pencil
" switch to specified keymap
<C-^>
" try to input letter "б" (same key as , and <)
" ',' (comma) is entered instead of the letter "б"
If the keymap is reset after Pencil is activated, the mappings work as they should.
when in hard wrap mode, I can't input exactly as the following:
```
this is a code block
```
Pencil will auto reposition this is a code block
to the end of the first ```
Maybe this is standard functionality? Seems like something funky is going on though... being able to type two lines without spaces between them is hopefully an option? To repro: if I'm making a list in markdown, for example, when I type one entry, hit enter and start to type the next bullet or dash immediately below the line above it (with no space in between), then it jumps up to the previous line.
Is there a setting to stop that? Or is one of my other plugins messing with me?
Thanks!!
Full support may be tricky, as the asciidoc syntax file that ships with Vim does not play well with Vim's autoformat capability, specifically on formatting list elements (hi asciidocList).
To reproduce problem, outside of pencil compare editing list elements in markdown and asciidoc with Vim's autoformat enabled.
Provisionally blacklisting asciidocList until this is sorted out.
Using https://github.com/FooSoft/md2vim or similar.
I can't disable conceal even if I have the following codes in my .vimrc
let g:pencil#conceallevel = 0
so **word**
still show as word
without the surrounding **
Starting with this text for example:
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
If I add text in the middle of the paragraph then it fails to wrap properly at the occurance of the "3":
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
A B C D E F G H I J K L M N O P Q R S T Free Software Foundation;
either version
3 of the License, or (at your option) any later version.
Using the tpope/vim-markdown syntax plugin with pencil.
In 'hard' mode.
I have a small feature proposal. I haven't forked this project, but I wouldn't mind doing so and creating a pull request if that sort of thing is welcomed.
My current workflow using vim-pencil with LaTeX involves frequently toggling autoformat on and off (for instance, to switch from writing a paragraph to writing an equation, where I want to manually specify all formatting), as I haven't quite figured out g:pencil#autoformat_blacklist
. I thought it might be nice to provide a convenience function, similar to PencilMode()
, which returns a string (preferably user-overridable) indicating whether or not autoformat is enabled. To this end, I put the following in my .vimrc and it seems to work for my purposes:
let g:pencil#autoformat_indicators = {'auto': 'auto', 'noauto': 'noauto'}
fun! PencilAutoformat()
if exists('b:last_autoformat')
if b:last_autoformat
return get(g:pencil#autoformat_indicators, 'auto', 'auto')
else
return get(g:pencil#autoformat_indicators, 'noauto', 'noauto')
en
else
return ''
en
endf
If this were built into plugin/pencil.vim
(again, like PencilMode()
), people could then add something like this to their .vimrc:
let g:pencil#autoformat_indicators = {'auto': 'a+', 'noauto': 'a-',}
let statusline=%<%f\ %{PencilMode()}\ %{PencilAutoformat()}
Given a list in a document in pencil's hard line break mode:
*foo
bar
baz
With the cursor at the *
, use the commands <C-v>jjIxyz
you should end up with
xyz foo
xyz bar
xyz baz
but instead you weirdly get
xyz foo bar baz
xyz foo bar
xyz foo bar
steps to reproduce the issue:
function! ToggleGUICruft()
if &guioptions=='i'
exec('set guioptions=imTrL')
else
exec('set guioptions=i')
endif
endfunction
3, vip=
to format the code
4. run :HardPencil
5. yip
to copy the code snippet and paste it to the blank space.
6. move the cursor the beginning of endfuntion
and press <BS>
key.
result:
function! ToggleGUICruft()
if &guioptions=='i'
exec('set guioptions=imTrL')
else
exec('set guioptions=i')
endif
endfunction
function! ToggleGUICruft()
if &guioptions=='i'
exec('set guioptions=imTrL')
else exec('set guioptions=i') endifendfunction
Reorganize commands to make them more friendly to command-line completion.
I don't know what I'm doing wrong here. Maybe I misunderstand the readme. I have the following in my .vimrc
augroup pencil
autocmd!
autocmd FileType text call pencil#init()
autocmd FileType mail call pencil#init({'wrap': 'hard', 'textwidth': '72'})
autocmd FileType markdown call pencil#init()
augroup END
Nonetheless, if I start writing an email with ft=mail
textwidth
remains 0
. As I got it from the readme, even without enforcing both wrap
and textwidth
I should get textwidth
set -- doesn't work either.
If I verbose set tw?
it says that it got loaded from pencil but it 0
. On the contrary, if I do :HardPencil
everything works as expected.
Any help appreciated.
For example, whichwrap and virtualedit are globally-scoped settings. Setlocal for these doesn't appear to be working as expected.
Investigate how to automatically set/unset these for the buffers in which a pencil mode is active.
Use BufEnter and BufLeave events to set/restore these global settings.
Occurs in HardPencil mode and interferes with ability to add new items to a list.
When a heading is on the preceding line, autoformat will include that line in the reformat.
Need lookbehind to disable autoformat if the heading is present on that previous line. Otherwise allow autoformat.
Example: http://cl.ly/3j1P2u331t01
This is a .md
file. Seems to me that the desired behavior would be for the nested list items to always be displayed at the indentation level dictated by markdown format (i.e. Two spaces for each indentation level, not one).
Sorry in case this is actually obvious: How do I add additional rules for blacklisting? I would like code blocks in ft=mail
not to be automatically formatted.
Sorry to bother you with that filetype
. :-) I would flattr your work, if I could!
For plasticboy/vim-markdown, the [mkdNonListItemBlock]
should be treated like a []
when scanning a line looking for a blacklisted highlight group.
Otherwise we're not finding the blacklist item.
Note that mkdNonListItemBlock should be removed from the blacklist and moved to an IgnoreList.
Example of table in a Markdown variant:
Tables | Are | Cool |
---|---|---|
col 1 is | left-aligned | $1600 |
col 2 is | centered | $12 |
col 3 is | right-aligned | $1 |
If the user enters Insert mode from inside table, there may be no highlight code on the synstack to exclude.
One option is to have pencil parse the line, looking for leading '|' when filetype is markdown. That might best go into a new vim-pencil-markdown project
Better yet, provide pull request to Syntax plugins to provide highlighting for tables. Then those highlights can be added to Pencil's exclude list.
If
It'll go to soft mode when it should be detected with hard mode.
Is it possible to disable pencil in Markdown's code blocks? Right now it reformats things pretty terribly.
Global variable would reflect 'Hard' or 'Soft' when either of those two modes are active.
Currently a single regex is used for blacklisting.
Break that up by file type.
If there's an obvious benefit, automatically configure an external formatter like par
for use in wrapping text.
Is it possible to add support to automatically disable default autofomatting when recognising YAML header in markdown file? Since it tries to format YAML header to one line in auto mode. And it is pretty annoying to switch modes manually.
Hi there!
I love Pencil, and I'd like to use some of the features (hard wrap at 80 chars at least) when editing my Vimwiki, but if I do that some of the auto-formatting on <cr>
, amongst other things breaks for that filetype which means things like new todo list entries don't get created, for example.
Any idea if it's possible to do the hard wrap portion of this plugin in a vimwiki context?
Thanks!
If for whatever reason a file has been incorrectly detected as text, changing the filetype won't disable vim-pencil. The previous settings need to be save, then restored.
Perhaps :mkview
in init(), with autocmd FileType * loadview
followed be a delete-view-file-operation.
Though it might be simpler in the long run to individual save each option to a buffer-local dictionary?
This would also be useful when switching from code to embedded prose.
Evaluate how it best fits into pencil
if exists('+breakindent')
setlocal breakindent
endif
See https://retracile.net/wiki/VimBreakIndent for more details.
When toggling between hard/soft modes on a file with long lines (I've commented out any vim-pencil autocmd
s for the sake of debugging) :SoftPencil
works as expected (setting wrap
w/o cutting off words, remapping nav keys, etc.), while :HardPencil
, though it sets nowrap
and textwidth=80
correctly, does not create hard line breaks upon mode switch. The lines simply run off the screen until an edit is attempted, at which point the line is finally auto formatted to the appropriate textwidth
.
I can't tell 100% from the documentation -- isn't vim-pencil supposed to create and undo hard line breaks upon mode switches? If so, what would be interfering with this initial wrap (my .vimrc and a list of plugins are below)? Note also that, after hard line breaks have been created via auto format on a given line, calling :SoftPencil
does not rejoin these lines into the original line, now softly wrapped, it merely soft wraps the lines that have not yet been touched by autoformat.
If not, where would you recommend I insert this behavior into my vim-pencil version (just some execute "normal gggqG"
commands, etc.)? I just thought this was the whole point of vim-pencil!
Hopefully this helps other users get set-up with vim-pencil, as I have spent some time trying to figure out where my setup might have gone wrong.
It is unlikely that conflicts are here... I leave the setting of formatoptions
, etc. to vim-pencil, though in vim-pencil section below I have experimented (to no avail) with setting, e.g., textwidth
to some non-zero value manually.
set nocompatible
let mapleader=" "
execute pathogen#infect()
"mappings ===============================================
"removes key functionality when learning new maps
":inoremap <esc> <nop>
":inoremap jk <esc>
:nnoremap <leader>ev :vsplit $MYVIMRC<cr>
:nnoremap <leader>sv :source $MYVIMRC<cr>
:nnoremap <leader>el :vsplit #<cr>
:nnoremap <leader>et :vsplit ~/Dropbox/Notes/todo.taskpaper<cr>
"quotes around word
":nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
"python specific commenting
":autocmd FileType python nnoremap <buffer> <localleader>c I#<esc>
":autocmd FileType python :iabbrev <buffer> iff if:<left>
"operator mappings
:onoremap p i(
:onoremap in( :<c-u>normal! f(vi(<cr>
:onoremap il( :<c-u>normal! F)vi(<cr>
"markdown mappings
"change header if marked with equal signs
":onoremap ih :<c-u>execute "normal! ?^==\\+$\r:nohlsearch\rkvg_"<cr>
"snippets
:iabbrev eml sdfasdfddfsfd@gmail.com
:iabbrev zml sadfasasdfds@gmail.com
"=============================================================
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set history=1000 " keep 50 lines of command line history
set showcmd " display incomplete commands
set incsearch " do incremental searching
"set autochdir "
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
filetype plugin indent on
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
":set spell
":set spelllang=en,de
set backupdir=~/.vimbackups,/tmp
set pastetoggle=<F1>
:nnoremap <F5> "=strftime("%c")<CR>P
:inoremap <F5> <C-R>=strftime("%c")<CR>
"from theunixschool.com
map #2 :wq!
"prevents sync discrepancies by checking for changes to the files of
"open buffers
au CursorHold * checktime
let g:session_autosave = 'no'
"will auto wrap text
"set formatoptions+=a
"see for navigating by sentences etc.
":help text-objects
"VIM-PENCIL=========================================================
"let g:pencil#wrapModeDefault = 'hard' " default is 'hard'
"set number
"set nopaste
"set tw=80
"set nowrap
"set fo+=tca
"let g:pencil#textwidth = 74
augroup pencil
"autocmd!
"autocmd FileType markdown,mkd,md call pencil#init({'wrap': 'hard'})
"autocmd FileType text,txt call
"pencil#init({'wrap': 'hard'}) had to manually add a macro to correctly
"hard wrap existing lines don't kno what's pencil's deal is autocmd
"FileType text,txt,markdown,mkd,md :HardPencil
"autocmd FileType markdown,mkd,md execute "normal magggqG`a"
"autocmd FileType text,txt,markdown,mkd,md execute "normal magggqG`a"
"autocmd BufWritePre text,txt,markdown,mkd,md :SoftPencil
"autocmd BufWritePost text,txt,markdown,mkd,md :HardPencil
augroup END
"GOYO===============================================================
function! s:goyo_enter()
"Setup to quit vim in GOYO
let b:quitting = 0
let b:quitting_bang = 0
autocmd QuitPre <buffer> let b:quitting = 1
cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
endfunction
function! s:goyo_leave()
" Quit Vim if this is the only remaining buffer
if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
if b:quitting_bang
qa!
else
qa
endif
endif
endfunction
"autocmd FileType markdown,mkd,md :Goyo
"autocmd FileType text,txt :Goyo
let g:goyo_margin_top=2
let g:goyo_margin_bottom=2
:set scrolloff=999
"autocmd User GoyoEnter call <SID>goyo_enter()
"autocmd User GoyoLeave call <SID>goyo_leave()
It's not extending the visual block selection to the end of each line.
http://stackoverflow.com/a/11310113
In SoftPencil (soft wrap) mode.
A configurable setting to set a neutral background on inline and fenced code blocks.
Hello,
I really want to use Pencil, but it breaks my own mapping of <cr>
. Could add an option to change or disable the default mappings?
The auto formatting feature is super useful. I wish I had that for multi-line comments in Python. Is there a way to get that?
I just installed this plugin as I wanted to explore using vim to write prose. I think I may be confused as to what 'soft' wrapping mode actually is because in all my attempts to use it so far it doesn't do anything.
So I've got the textwidth set to 74 (default I think but I set it explicitly anyway). In hard wrapping mode if I try to type more than 74 chars it inserts a line break at a convenient point and moves me on to the next line. I understand this and it works how I expect.
In soft mode I can just keep typing until I myself decide to hit enter and insert a line break. Which is the behaviour I'm used to from using Vim as a code editor. I was expecting soft wrap mode to be something like it wrapping the lines visually but there being no line breaks inserted. I suppose it is doing this but at the terminal width not at 74 characters.
Sorry if this is not appropriate for an 'issue', I realise it's not a bug or enhancement but I couldn't find anywhere to ask the question (I tried IRC but got no response).
Thanks.
Guessing this is a conflict with one of my other plugins or my environment, I'd be surprised if it was globally broken (but who knows?).
To reproduce:
:NoPencil
(or :TogglePencil
- same behavior for both)A strange but hopefully illuminating wrinkle:
vim
by itself w/ no filename, with Pencil enabled in the rc file:set ft=markdown
vim
by itself, as above, still with Pencil enabled:NoPencil
:set ft=markdown
, type stuff, and things work fine - no #31 behavior occurs.Other notes:
.vimrc
and .vim/
, can be seen here: https://github.com/bitprophet/dotfilesI was hoping (expecting?) that running "dw" in the middle of a paragraph (with hard wrapping) that the paragraph would be reformatted. That doesn't seem to be the case. Is that possible in some way?
Hello,
I have a small list of custom insert mode abbreviations for some unicode symbols, however, whenever I edit a filetype that Pencil is called for they appear to no longer function. If I check :ab
they appear to be loaded though.
I'm also using Litecorrect however disabling that does not yield any difference. Disabling Pencil fixes the issue (but I obviously don't want that :-))
Is there anything I should be doing different to prevent this?
If no modeline, read the first N lines of the file (as modelines does) to look for long lines indicating that soft-wrap mode should be used.
W can be used to traverse words separated by spaces, which is the common case.
My experiments:
" skip over punctuation inside and adjacent to words
setl iskeyword+=.,?,;,!,(,),[,],{,},',-,`
setl iskeyword+=\,
setl iskeyword+=\"
" TODO «» “” ‘’
" for D&D, #3, ~40, 100%, $200, etc.
setl iskeyword+=&,#,~,%,$
setl iskeyword+=\|
"setl iskeyword+=^ not working?
" and various math operators (200+3=203)
setl iskeyword+=+
setl iskeyword+=*
setl iskeyword+=>
setl iskeyword+==
setl iskeyword+=<
setl iskeyword+=:,/ " consider urls to be words
setl iskeyword+=\\ " and escaped markdown chars, like \_
setl iskeyword+=@-@ " and email@addresses
setl iskeyword+=-
"set iskeyword=!-~,^*,^45,^124,^34,192-255,^_
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.