junegunn / fzf.vim

fzf :heart: vim
MIT License
9.51k stars 581 forks source link

cursor shape changed from underscore to block in iTerm2 #1518

Closed marslo closed 4 months ago

marslo commented 6 months ago

I'm using specific cursor shape settings in my vimrc

if $TERM_PROGRAM =~ "iTerm"
  let &t_SI = "\<Esc>]50;CursorShape=4\x7"                          " INSERT MODE  : solid underscore
  let &t_SR = "\<Esc>]50;CursorShape=2\x7"                          " REPLACE MODE : solid block
  let &t_EI = "\<Esc>]50;CursorShape=3\x7"                          " NORMAL MODE  : blinking underscore
else
  let &t_SI .= "\e[4 q"                                             " SI = INSERT mode
  let &t_SR .= "\e[4 q"                                             " SR = REPLACE mode
  let &t_EI .= "\e[3 q"                                             " EI = NORMAL mode (ELSE)
endif

it should be the underscore normally. However it changed automatically to block after fzf.vim commands ( i.e.: :Files ). What's interesting is cursor shape back normal when press r ( why ? ). Exact same result by using self-build vim and latest release vim from macvim-dev/macvim details:

fzf vim cursorshape

I've checked with a minimal configuration, there's no abnormal since &t_SI, &t_EI and &t_SR are all unset:

fzf vim cursorshape-miin vimrc

here are detail info:

fzf and fzf.vim

vimrc

click to check full vimrc

set runtimepath+=/usr/local/opt/fzf
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'

" junegunn/fzf.vim
nnoremap <C-p> :Files<CR>
nnoremap <C-g> :GFiles<CR>
nnoremap <C-s> :Ag<CR>
nnoremap <silent><leader>l  :Buffers<CR>
nnoremap <silent> <Leader>H :Helptags<CR>
nnoremap <silent> <Leader>g :Commits<CR>
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
  \ 'prefix': '^.*$',
  \ 'source': 'rg -n ^ --color always',
  \ 'options': '--ansi --delimiter : --nth 3..',
  \ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }
\ }))
let g:fzf_vim                     = {}
let g:fzf_vim.preview_window      = [ 'right,50%', 'ctrl-\' ]
let g:fzf_vim.tags_command        = 'ctags -R'
let g:fzf_vim.commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
command! -bang -nargs=? -complete=dir Files
    \ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', 'bat --color=always {}']}, <bang>0)
command! -bang -complete=dir -nargs=? LS
    \ call fzf#run(fzf#wrap('ls', {'source': 'ls', 'dir': <q-args>}, <bang>0))
let g:fzf_layout                  = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true } }
let g:fzf_history_dir             = '~/.vim/cache/fzf-history'
let g:fzf_action                  = {
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-x': 'split',
  \ 'ctrl-v': 'vsplit'
\ }
let g:fzf_colors                  = {
  \ 'fg':         ['fg', 'Normal'                               ] ,
  \ 'bg':         ['bg', 'Normal'                               ] ,
  \ 'preview-bg': ['bg', 'NormalFloat'                          ] ,
  \ 'hl':         ['fg', 'Comment'                              ] ,
  \ 'fg+':        ['fg', 'CursorLine', 'CursorColumn', 'Normal' ] ,
  \ 'bg+':        ['bg', 'CursorLine', 'CursorColumn'           ] ,
  \ 'hl+':        ['fg', 'Statement'                            ] ,
  \ 'info':       ['fg', 'PreProc'                              ] ,
  \ 'border':     ['fg', 'Ignore'                               ] ,
  \ 'prompt':     ['fg', 'Conditional'                          ] ,
  \ 'pointer':    ['fg', 'Exception'                            ] ,
  \ 'marker':     ['fg', 'Keyword'                              ] ,
  \ 'spinner':    ['fg', 'Label'                                ] ,
  \ 'header':     ['fg', 'Comment'                              ]
\ }

os

$ sw_vers
ProductName:        macOS
ProductVersion:     14.2.1
BuildVersion:       23C71

iTerm2

vim --version

$ $(type -P vim) --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Dec 28 2023 15:48:16)
macOS version - x86_64
Included patches: 1-2189
Compiled by marslo <marslo.jiao@gmail.com>
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
+autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby/dyn          +wildignore
+cursorbind        +lua/dyn           +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            -X11
+digraphs          +mouse             +sound             -xattr
-dnd               -mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       -xim
+emacs_tags        -mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      -xsmp
+ex_extra          +mouse_netterm     +syntax            -xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/vim/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -I/usr/local/include -I/usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/include -I/usr/local/opt/openldap/include -I/usr/local/opt/curl/include -I/usr/local/opt/binutils/include -I/usr/local/opt/sqlite/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I/usr/local/opt/node@20/include -I/usr/local/opt/tcl-tk/include -I/usr/local/Cellar/icu4c@71.1/71.1/include -I/usr/local/opt/llvm/include -I/usr/local/opt/libiconv/include -I/usr/local/opt/ncurses/include -DMACOS_X -DMACOS_X_DARWIN -I/usr/local/include -I/usr/local/opt/tcl-tk/include -I/usr/local/Cellar/libsodium/1.0.19/include -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/openldap/lib -L/usr/local/opt/curl/lib -L/usr/local/opt/binutils/lib -L/usr/local/opt/python@3.12/lib -L/usr/local/opt/tcl-tk/lib -L/usr/local/opt/sqlite/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/node@20/lib -L/usr/local/Cellar/icu4c@71.1/71.1/lib -L/usr/local/opt/ncurses/lib -L/usr/local/opt/libiconv/lib -L/usr/local/opt/llvm/lib -L/usr/local/opt/llvm/lib/c++ -Wl,-rpath,/usr/local/opt/llvm/lib/c++ -o vim -lm -lncurses -L/usr/local/Cellar/libsodium/1.0.19/lib -lsodium -liconv -lintl -framework AppKit
marslo commented 5 months ago

Hi there, any update on this ?

junegunn commented 5 months ago

I can't reproduce the problem (iTerm 3.5.0beta18). Tested with:

set nocompatible hidden laststatus=2

if !filereadable('/tmp/plug.vim')
  silent !curl --insecure -fLo /tmp/plug.vim
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

source /tmp/plug.vim
call plug#begin('/tmp/plugged')
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
call plug#end()

autocmd VimEnter * PlugClean! | PlugUpdate --sync

let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=0\x7"
let &t_EI = "\<Esc>]50;CursorShape=2\x7"
marslo commented 5 months ago

Hey @junegunn,

Thanks for your time on this. Can you please help try with :

let &t_SI = "\<Esc>]50;CursorShape=4\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=3\x7"

here is my test result: 1518-simple-vimrc

btw, I've upgraded the vim to 9.1:

$ $(type -P vim) --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan  8 2024 16:50:47)
macOS version - x86_64
Included patches: 1-16
Compiled by marslo <marslo.jiao@gmail.com>
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
+autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby/dyn          +wildignore
+cursorbind        +lua/dyn           +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            -X11
+digraphs          +mouse             +sound             -xattr
-dnd               -mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       -xim
+emacs_tags        -mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      -xsmp
+ex_extra          +mouse_netterm     +syntax            -xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/vim/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -I/usr/local/include -I/usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/include -I/usr/local/opt/openldap/include -I/usr/local/opt/curl/include -I/usr/local/opt/binutils/include -I/usr/local/opt/sqlite/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I/usr/local/opt/node@21/include -I/usr/local/opt/tcl-tk/include -I/usr/local/Cellar/icu4c@71.1/71.1/include -I/usr/local/opt/llvm/include -I/usr/local/opt/libiconv/include -I/usr/local/opt/ncurses/include -DMACOS_X -DMACOS_X_DARWIN -I/usr/local/include -I/usr/local/opt/tcl-tk/include -I/usr/local/Cellar/libsodium/1.0.19/include -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/openldap/lib -L/usr/local/opt/curl/lib -L/usr/local/opt/binutils/lib -L/usr/local/opt/python@3.12/lib -L/usr/local/opt/tcl-tk/lib -L/usr/local/opt/sqlite/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/node@21/lib -L/usr/local/Cellar/icu4c@71.1/71.1/lib -L/usr/local/opt/ncurses/lib -L/usr/local/opt/libiconv/lib -L/usr/local/opt/llvm/lib -L/usr/local/opt/llvm/lib/c++ -Wl,-rpath,/usr/local/opt/llvm/lib/c++ -o vim -lm -lncurses -L/usr/local/Cellar/libsodium/1.0.19/lib -lsodium -liconv -lintl -framework AppKit
marslo commented 5 months ago

Hi @junegunn ,

I suppose the issue is from vim itself. I've merged all changes into neovim this afternoon, and cursor shape looks pretty normal now 4214-nvim