goyo.vim icon indicating copy to clipboard operation
goyo.vim copied to clipboard

Buffer return to first line after close Goyo using :q

Open alihardan opened this issue 5 years ago • 2 comments

When I close Goyo using :q, buffer cursor jumps to first line of document. But when I use :Goyo, It doesn't jump.

My .vimrc:

call plug#begin('~/.vim/plugged')
Plug 'junegunn/goyo.vim' " Distraction-free writing in Vim. 
call plug#end()

alihardan avatar Nov 19 '18 08:11 alihardan

I just ran into the same thing and there is a comment in the script saying that switching the line number in the original file does not work when using :q

https://github.com/junegunn/goyo.vim/blob/6b6ed2734084fdbb6315357ddcaecf9c8e6f143d/autoload/goyo.vim#L323-L324

I fixed this with saving line/col on QuitPre and restoring in my goyo_leave (inspired by this example). One thing I don't know yet is why only the line number is restored, but not the column, but that isn't really a problem for me so didn't investigate.

function s:goyo_enter()
    let b:quitting = 0
    autocmd QuitPre <buffer> let b:quitting = 1 | let b:line_pos = line('.') | let b:col_pos = col('.')
endfunction

function s:goyo_leave()
    if b:quitting
        call cursor(b:line_pos, b:col_pos)
    endif
endfunction

autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()

mihalyr avatar May 24 '20 16:05 mihalyr

Thanks mihalyr, solved the problem (for me) :+1:

lirorc avatar Sep 18 '22 21:09 lirorc