junegunn / goyo.vim

:tulip: Distraction-free writing in Vim
MIT License
4.52k stars 116 forks source link

Manual :Goyo command vs autocmd triggered and clicking in protected area #73

Closed sdothum closed 9 years ago

sdothum commented 9 years ago

Great plugin. I was using lite-dfm for my coding and writing, but now I use goyo for writing. Just a couple of observations..

For my purposes, to get the proper centering in a herbstluftwm subframe, I used "Goyo 78-4" -- my textwidth=72. This worked when I manually entered goyo mode. But when I placed tried to automatically (autocmd VimEnter) enter goyo mode with the same command, there was soft line wrap encountered as if the textwidth was reduced and the offset position no longer centered the text.

I solved this in the autocmd with "Goyo 85-5". Works beautifully. I must not understand something about the margin width specification and the way goyo calculates the protected border regions.

The other thing I noticed is that if one errantly clicks the mouse in the "blank" margin area (protected windows used), gogo shifts the text window right and the odd soft lin wrap described above occurs. This is easily remedied by issuing a "<C-w>=" to redraw the window (reset margins). Of course, not clicking the mouse in the protected areas is simple enough.. but I had to test it out!

Again, lovely plugin. I use it for composing emails and with vimwiki.

junegunn commented 9 years ago

I think it's caused by some autocmds from your vimrc or other plugins. Check if the problems are still reproducible even when you have nothing but Goyo runtimepath in your configuration.

sdothum commented 9 years ago

Well.. I commented out everything except the plugin load of goyo. Added "execute 'Goyo'" after the plugin load (using vim-plug, by the way).

Vim complains that the exec is using an invalid command "Goyo". But I can manually :Goyo -- it works and the mouse click behaviour described above does not happen, Goyo just works.

So.. it will take quite awhile for me to dig a little deeper, as I use a lot of plugins. I'll try to isolate the plugin that causes the mouse click anomaly first.

junegunn commented 9 years ago

Added "execute 'Goyo'" after the plugin load (using vim-plug, by the way). Vim complains that the exec is using an invalid command "Goyo".

Vim loads plugin files in &runtimepath only after it has finished processing vimrc, so it's the expected behavior. (See :help startup) A workaround is autocmd VimEnter * Goyo.

You might want to take a look at the output of :autocmd. See stuff under BufWinEnter, BufWinLeave, WinEnter, WinLeave, etc.

sdothum commented 9 years ago

Found it.. foldcolumn and numberwidth settings from lite-dfm caused the text shift when the protected borders were clicked. Setting both to 1 prior to entering goyo fixed the above problem.

Have some trouble shooting to do as line numbering artifacts result in the protected borders when switching from goyo to lite-dfm and back to goyo. Other than that though and a minor text shift likely the result of lite-dfm (seldom need to switch dfm's when writing), goyo works flawlessly.

junegunn commented 9 years ago

I see, note that you can always reset the size of the goyo window by pressing CTRL-W =