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

Line numbers in "padding" buffers

Open ryanneph opened this issue 5 years ago • 7 comments

I couldn't find any reference to this issue elsewhere so I decided to make one.

I've recently installed Goyo in nvim 0.3.1 and I love it but I cannot seem to figure out how to disable line numbering in the "padding" buffers that are created around the active buffer. screenshot_20190123_105203

This is the relevant configuration from my init.vim file:

" GOYO + Limelight Config
"-----------------------------------------------------------------
let g:goyo_width = 140
let g:goyo_linenr=0
function! s:goyo_enter()
    call s:disable_autonumber() 
    set nocursorcolumn nocursorline
    set nonumber
    let g:undotree_CustomUndotreeCmd = 'leftabove vertical 32 new'
    let g:undotree_CustomDiffpanelCmd = 'belowright 12 new'
    Limelight
endfunction
function! s:goyo_leave()
    call s:enable_autonumber()
    set cursorcolumn cursorline
    set number
    unlet g:undotree_CustomUndotreeCmd
    unlet g:undotree_CustomDiffpanelCmd
    Limelight!
endfunction
augroup rn_distraction_free
    au!
    autocmd! User GoyoEnter nested call <SID>goyo_enter()
    autocmd! User GoyoLeave nested call <SID>goyo_leave()
augroup END

" hybrid (auto-switching) line numbers - see https://jeffkreeftmeijer.com/vim-number/
function! s:disable_autonumber()
    au! rn_autonumber
endfunction
function! s:enable_autonumber()
    augroup rn_autonumber
        au!
        au BufEnter,FocusGained,InsertLeave * set norelativenumber
        au BufLeave,FocusLost,InsertEnter   * set relativenumber
    augroup END
endfunction
set number
call s:enable_autonumber()

Does anybody have any idea how I can resolve (i.e. disable all line numbers when in :Goyo mode)?

ryanneph avatar Jan 23 '19 18:01 ryanneph

So, I've been able properly hide the line numbers in the "padding" buffers by editing https://github.com/junegunn/goyo.vim/blob/master/autoload/goyo.vim#L71 to include a resetting of nornu to 0:

function! s:setup_pad(bufnr, vert, size, repel)
  :
  augroup goyop
    execute 'autocmd WinEnter,CursorMoved <buffer> nested call s:blank("'.a:repel.'")'
    autocmd WinLeave <buffer> call s:hide_statusline() | setlocal nornu
  augroup END
  :
endfunction

I still haven't isolated the position in the code where &rnu is reset to 1 after being explicitly set to 0 by s:hide_linenr() but if this change doesn't break anything and helps others I can open a PR.

ryanneph avatar Jan 24 '19 19:01 ryanneph

how to disable line numbering in the "padding" buffers that are created around the active buffer

I don't have the issue. Sounds like a configuration issue. You might want to find out which part of your Vim configuration (or a plugin) is causing this.

junegunn avatar Feb 20 '19 08:02 junegunn

Will do. I'll report back if I find the cause

ryanneph avatar Mar 02 '19 01:03 ryanneph

Will do. I'll report back if I find the cause

@ryanneph did you find the source of this issue? I'm seeing the same thing.

heliostatic avatar Jun 13 '19 00:06 heliostatic

@heliostatic Not yet. I abandoned the search temporarily to finish some work. The workaround I posted above has been fine in the meantime. I’ll take another look this week if I have time.

ryanneph avatar Jun 13 '19 01:06 ryanneph

This issue also exists with vim-scripts/numbers.vim, which does pretty much the same as the augroup rn_autonumber above. The culprit seems to be set relativenumber on BufLeave, which is why the workaround works. I'm not sure if it will be affected by the order in which the autocommands get executed, though.

numbers.vim allows listing filetypes on which it should not activate. Can Goyo set a filetype on padding buffers so that it can be excluded in numbers.vim? If a filetype exists I haven't been able to locate it.

phanimahesh avatar Oct 21 '19 06:10 phanimahesh

With #209, I believe a better fix would be to setup

autocmd BufLeave goyo_pad setlocal norelativenumber for the configuration above, and to use

let g:numbers_exclude = ['goyo_pad'] for numbers.vim

phanimahesh avatar Oct 21 '19 06:10 phanimahesh