diff --git a/autoload/fern.vim b/autoload/fern.vim index 0fc5a9e..b77c2bf 100644 --- a/autoload/fern.vim +++ b/autoload/fern.vim @@ -18,6 +18,7 @@ call s:Config.config(expand(':p'), { \ 'loglevel': g:fern#INFO, \ 'opener': 'edit', \ 'hide_cursor': 0, + \ 'hide_cursorline': 0, \ 'keepalt_on_edit': 0, \ 'keepjumps_on_edit': 0, \ 'disable_auto_buffer_delete': 0, diff --git a/autoload/fern/internal/viewer.vim b/autoload/fern/internal/viewer.vim index f9594cd..aba6841 100644 --- a/autoload/fern/internal/viewer.vim +++ b/autoload/fern/internal/viewer.vim @@ -61,6 +61,7 @@ function! s:init() abort augroup END call fern#internal#viewer#auto_duplication#init() call fern#internal#viewer#hide_cursor#init() + call fern#internal#viewer#hide_cursorline#init() " Add unique fragment to make each buffer uniq let bufname = bufname('%') diff --git a/autoload/fern/internal/viewer/hide_cursor.vim b/autoload/fern/internal/viewer/hide_cursor.vim index fa0449a..6f44b2a 100644 --- a/autoload/fern/internal/viewer/hide_cursor.vim +++ b/autoload/fern/internal/viewer/hide_cursor.vim @@ -1,24 +1,14 @@ function! fern#internal#viewer#hide_cursor#init() abort - if !g:fern#hide_cursor - return + if g:fern#hide_cursor + call s:hide_cursor_init() endif - call s:hide_cursor_init() endfunction function! s:hide_cursor_init() abort augroup fern_internal_viewer_smart_cursor_init autocmd! * - autocmd BufEnter,WinEnter,TabLeave,CmdwinLeave,CmdlineLeave setlocal cursorline - autocmd BufLeave,WinLeave,TabLeave,CmdwinEnter,CmdlineEnter setlocal nocursorline autocmd BufEnter,WinEnter,TabLeave,CmdwinLeave,CmdlineLeave call fern#internal#cursor#hide() autocmd BufLeave,WinLeave,TabLeave,CmdwinEnter,CmdlineEnter call fern#internal#cursor#restore() autocmd VimLeave call fern#internal#cursor#restore() augroup END - - " Do NOT allow cursorlineopt=number while the cursor is hidden (Fix #182) - if exists('+cursorlineopt') - " NOTE: - " Default value is `number,line` (or `both` prior to patch-8.1.2029) - setlocal cursorlineopt& - endif endfunction diff --git a/autoload/fern/internal/viewer/hide_cursorline.vim b/autoload/fern/internal/viewer/hide_cursorline.vim new file mode 100644 index 0000000..64ae0e1 --- /dev/null +++ b/autoload/fern/internal/viewer/hide_cursorline.vim @@ -0,0 +1,20 @@ +function! fern#internal#viewer#hide_cursorline#init() abort + if g:fern#hide_cursorline + call s:hide_cursorline_init() + endif +endfunction + +function! s:hide_cursorline_init() abort + augroup fern_internal_viewer_smart_cursor_line_init + autocmd! * + autocmd BufEnter,WinEnter,TabLeave,CmdwinLeave,CmdlineLeave setlocal cursorline + autocmd BufLeave,WinLeave,TabLeave,CmdwinEnter,CmdlineEnter setlocal nocursorline + augroup END + + " Do NOT allow cursorlineopt=number while the cursor is hidden (Fix #182) + if exists('+cursorlineopt') + " NOTE: + " Default value is `number,line` (or `both` prior to patch-8.1.2029) + setlocal cursorlineopt& + endif +endfunction diff --git a/doc/fern.txt b/doc/fern.txt index d365d74..b5fbbd3 100644 --- a/doc/fern.txt +++ b/doc/fern.txt @@ -327,13 +327,15 @@ VARIABLE *fern-variable* Default: 'edit' *g:fern#hide_cursor* - Set 1 to hide cursor and forcedly enable |cursorline| to visualize the - cursor node. The |cursorline| is automatically enabled when the focus - is on the buffer and automatically disabled when the cursor is out of - the buffer. + Set 1 to forcibly hide the cursor for the fern window (see |t_ve|). + Note that Neovim prior to 0.5.0 cannot hide the cursor thus faint vertical bar is used instead. +*g:fern#hide_cursorline* + Set 1 to forcibly disable |cursorline| for the fern window + when focus is not on the fern window. + *g:fern#keepalt_on_edit* Set 1 to apply |keepalt| on the "open:edit" action to keep an |alternate-file| in a split windows style like: