preservim / vim-pencil

Rethinking Vim as a tool for writing
Other
1.57k stars 38 forks source link

SoftPencil on, then off, then on again -breaks navigation mappings #96

Open pooriajr opened 3 years ago

pooriajr commented 3 years ago

Love the plugin! I've been trying to fix this one little nuisance but no luck. If I run:

:SoftPencil
:NoPencil
:SoftPencil

Then j and k no longer perform like gj and jk. And even typing gj and gk directly doesn't work like normal - they just work like j and k.

Same thing with $ and 0. Any ideas?

alerque commented 3 years ago

Thanks for the report. I've actually run into this myself but never managed to track down what is causing it even as far as you have. I don't have the bandwidth to sit and mess with it right now, but if anybody does have ideas and finds this a PR would be welcome!

I don't typically turn Pencil on or off except once based on the file type on open so this is rare, but I have noted that g prefixed motions are occasionally getting screwed up.

pooriajr commented 3 years ago

No worries!

For me, the use case is that I want to have a "Prose Mode" in vim that is tied to when I enter/leave the Goyo mode from goyo.vim

And when using Goyo, there are a lot of reasons to switch in and out, so Pencil was getting toggled a lot.

For anyone else who might be wanting to do the same, my solution was to drop pencil and manually set up/tear down the mappings and settings I want, like so:

function! StartProse()
  setlocal linebreak
  setlocal wrap
  nnoremap <buffer> j gj
  nnoremap <buffer> k gk
  inoremap <buffer> . .<c-g>u
  inoremap <buffer> ! !<c-g>u
  inoremap <buffer> ? ?<c-g>u
  inoremap <buffer> , ,<c-g>u
  inoremap <buffer> ; ;<c-g>u
  inoremap <buffer> : :<c-g>u
endfunction

function! StopProse()
  setlocal nolinebreak
  setlocal nowrap
  unmap <buffer> j
  unmap <buffer> k
  iunmap <buffer> .
  iunmap <buffer> !
  iunmap <buffer> ?
  iunmap <buffer> ,
  iunmap <buffer> ;
  iunmap <buffer> :
endfunction

autocmd! User GoyoEnter nested call StartProse()
autocmd! User GoyoLeave nested call StopProse()
evantravers commented 3 years ago

I have always had this problem as well. The only nuance I have:

If you enter pencil mode :PencilSoft and then leave :PencilOff… if you enter it again :PencilSoft the mappings are broken… if you leave the second time and re-enter a third time… the mappings are restored!

It's always alternate… the solution has been for me to quickly "restart" it, but I've never been able to track down why the mappings break the second time.

charlescochran commented 5 months ago

Facing this issue as well.

evantravers commented 5 months ago

I wound up doing the same as @pooriajr: https://github.com/evantravers/dotfiles/blob/4cb528afb37a1e87fcbd71ce75a91d1c02de3eef/nvim/.config/nvim/init.lua#L532-L579

I've been using that happily without vim-pencil for quite a while now.

It doesn't have the smart "autodetect what kind of line" stuff that vim-pencil has, but it also doesn't have this bug.

charlescochran commented 5 months ago

Yeah, I may do this as well. But hopefully this can be fixed at some point, because it's pretty crippling for soft-wrap users.

Expressive-Synapse commented 5 months ago

as a soft-wrap fan this bug is pretty problematic for me. hopefully some sort of solution can be found.

charlescochran commented 5 months ago

Funnily enough, this bug drove me (like others) to give up on vim-pencil and make my own Lua-based config. But then I convinced myself to go back to automatic hard-wrapping because I want my markdown files to be viewable in any format. But I decided to stick with a custom config anyway.