Giter Club home page Giter Club logo

Comments (6)

reedes avatar reedes commented on May 25, 2024

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.

mlawren avatar mlawren commented on May 25, 2024

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.

mlawren avatar mlawren commented on May 25, 2024

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.

reedes avatar reedes commented on May 25, 2024

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.

reedes avatar reedes commented on May 25, 2024

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.

mlawren avatar mlawren commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.