diff --git a/autoload/fern.vim b/autoload/fern.vim index 65cdd150..27d6ef05 100644 --- a/autoload/fern.vim +++ b/autoload/fern.vim @@ -28,6 +28,7 @@ call s:Config.config(expand(':p'), { \ 'keepjumps_on_edit': 0, \ 'disable_default_mappings': 0, \ 'disable_viewer_auto_duplication': 0, + \ 'disable_viewer_hide_cursor': 0, \ 'disable_drawer_auto_winfixwidth': 0, \ 'disable_drawer_auto_resize': 0, \ 'disable_drawer_auto_quit': 0, diff --git a/autoload/fern/internal/cursor.vim b/autoload/fern/internal/cursor.vim new file mode 100644 index 00000000..9b8cb9be --- /dev/null +++ b/autoload/fern/internal/cursor.vim @@ -0,0 +1,52 @@ +let s:t_ve_saved = &t_ve +let s:guicursor_saved = &guicursor + +function! fern#internal#cursor#hide() abort + call s:hide() +endfunction + +function! fern#internal#cursor#restore() abort + call s:restore() +endfunction + +if has('nvim') + if has('nvim-0.5.0') + " https://github.com/neovim/neovim/issues/3688#issuecomment-574544618 + function! s:hide() abort + set guicursor+=a:FernTransparentCursor/lCursor + endfunction + + function! s:restore() abort + set guicursor+=a:Cursor/lCursor + let &guicursor = s:guicursor_saved + endfunction + + function! s:highlight() abort + highlight default FernTransparentCursor gui=strikethrough blend=100 + endfunction + call s:highlight() + + augroup fern_internal_cursor + autocmd! + autocmd ColorScheme * call s:highlight() + augroup END + else + " No way thus use narrow cursor instead + function! s:hide() abort + set guicursor+=a:ver1 + endfunction + + function! s:restore() abort + let &guicursor = s:guicursor_saved + endfunction + endif +else + " Vim supports 't_ve' + function! s:hide() abort + set t_ve= + endfunction + + function! s:restore() abort + let &t_ve = s:t_ve_saved + endfunction +endif diff --git a/autoload/fern/internal/viewer.vim b/autoload/fern/internal/viewer.vim index 4e44911b..547d5c89 100644 --- a/autoload/fern/internal/viewer.vim +++ b/autoload/fern/internal/viewer.vim @@ -55,6 +55,11 @@ function! s:init() abort if !g:fern#disable_viewer_auto_duplication autocmd WinEnter ++nested call s:WinEnter() endif + + if !g:fern#disable_viewer_hide_cursor + autocmd BufEnter,WinEnter,CmdwinLeave,CmdlineLeave call fern#internal#cursor#hide() + autocmd BufLeave,WinLeave,CmdwinEnter,CmdlineEnter call fern#internal#cursor#restore() + endif augroup END " Add unique fragment to make each buffer uniq diff --git a/doc/fern.txt b/doc/fern.txt index 9d3d6a7a..56b88f75 100644 --- a/doc/fern.txt +++ b/doc/fern.txt @@ -376,6 +376,10 @@ VARIABLE *fern-variable* The duplication is mainly occured when user execute |split| or |vsplit| command to duplicate window. +*g:fern#disable_viewer_hide_cursor* + Set 1 to disable viewer hide cursor. Note that Neovim prior to 0.5.0 + cannot hide cursor thus the cursor is shown as a vertical bar instead. + *g:fern#disable_drawer_auto_winfixwidth* Set 1 to disable automatically enable 'winfixwidth' to drawer on |BufEnter| autocmd.