Comments (6)
A good question.
It appears that Vim's autoformat (which pencil relies upon) will reformat when inserting characters and using backspace, but not with "dw", as you observed.
Marking as an enhancement, as it'll require someone to research and come up with an implementation.
from vim-pencil.
Marking as an enhancement, as it'll require someone to research and
come up with an implementation.
The best I could come up with so far is to use the TextChanged autocmd
trigger, however the following suffers from destroying the undo
history.
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let _cursor_pos = getpos('.')
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call setpos('.', _cursor_pos)
endfunction
autocmd TextChanged * call Preserve('normal gqap')
Unfortunately my vimscript skills are quite rudimentary and the above
is no doubt a very naive approach. It also quite clearly has global
impact and is not related to the pencil plugin. Perhaps it at least
helps the next person who takes a look to know where not to go :-)
Mark Lawrence
from vim-pencil.
I may have just found out the correct way to fix this issue. Reading
about the formatoptions variable I see that 'a' has the following
effect:
a Automatic formatting of paragraphs. Every time text is inserted or
deleted the paragraph will be reformatted. See auto-format.
When the 'c' flag is present this only happens for recognized
comments.
When I manually set formatoptions to "croqln1ta" (appending "a" to what
I discovered when in HardPencil mode) then the text appears to be
rebalanced properly when using "dw" and similar commands. I have no
idea what other effects the "a" has that may conflict with the goals of
pencil.
Mark Lawrence
from vim-pencil.
The a
formatoption is how pencil enables Vim's autoformat, as found here https://github.com/reedes/vim-pencil/blob/master/autoload/pencil.vim#L147
So, it should be deleting while autoformat is active, but isn't. A mystery that may be related to other formatoption configuration.
from vim-pencil.
Ah, I'm understanding this better now that I'm using Vim regularly again.
You're absolutely right that there's no reformatting in Command/Normal mode. Pencil only enables autoformat during insert mode.
Enabling autoformat in Command/Normal mode is a dual-edged sword. In my experience developing the plugin, it was disruptive, formatting things that I didn't want touched, such as quoted code in a markdown document.
I personally use a normal-mode mapping to Q or K to gqip
to manually reformat text that I'm manipulating. It's not idea, but seems to be the best tradeoff.
from vim-pencil.
Ah, ok. So no easy solution then. Thanks anyway for taking the time to
research this issue. I might steal your normal mappings for myself :-)
Mark Lawrence
from vim-pencil.
Related Issues (20)
- View list of things concealed (or change) HOT 7
- Enable smoothscroll for soft wrap mode
- Disable <cr> mapping HOT 3
- Underline title
- Vim pencil hides/removes colorcolumn HOT 4
- Normal Mode unexpected cursor behavior HOT 6
- In soft mode, map k and j to gj and gk
- vim-pencil applies 'set nolist' in soft wrap mode?
- Why is textwidth not used for soft wrap? HOT 2
- Cleanup key remapping technique HOT 1
- blacklist for rst (restructured text) missing various highlight groups
- g:pencil#textwidth setting not applied
- SoftPencil seems doesn't work HOT 3
- Suspending autoformatting doesn't work? HOT 2
- How disable line wrap in front matter (for Hugo or Jekyll) HOT 6
- Pencil and Markdown issue with lists HOT 8
- Respect indentation of lists in Markdown
- SoftPencil on, then off, then on again -breaks navigation mappings HOT 8
- Can't enter newline when editing vimwiki markdown
- "Undefined variable" and "Invalid arguments" errors HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-pencil.