nerdtree icon indicating copy to clipboard operation
nerdtree copied to clipboard

NERDTree jumps to open file on write

Open nickolashkraus opened this issue 6 years ago • 35 comments

Environment

  • Operating System: macOS Mojave Version 10.14.4
  • Vim version :version: VIM - Vi IMproved 8.1 macOS version
  • NERDTree version git rev-parse --short HEAD: f4d2b30
  • NERDTree settings applied in your vimrc, if any:
" map toggle NERDTree to ^Ctrl + n
map <C-N> :NERDTreeToggle<CR>

" show hidden files by default
let NERDTreeShowHidden=1

" ignore specifc files
let NERDTreeIgnore=['\.pyc$', '\~$', '\.swp$']

Process

  1. Open vim.
  2. Open file.
  3. Cause Quickfix or Location List to open.
  4. Close Quickfix or Location List.
  5. Write file (:w).

Current Result

NERDTree navigation moves to current file (see GIF).

Expected Result

NERDTree does not move.

Screenshot(s)

2019-04-19 14 33 21

Possible Fix

Not sure..


Updates

01.09.2020

Bug occurs when opening a location list, not a quickfix list.

nickolashkraus avatar Apr 19 '19 19:04 nickolashkraus

I'm having this issue too:

OS: Manjaro Linux with Linux 4.19.36 Vim: VIM - Vi IMproved 8.1 (2018 May 18, compiled Mar 29 2019 20:08:59) NerdTree: 3c06335

NerdTree related configuration:

let NERDTreeHijackNetrw=1
let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git$', '\.hg', '\.svn', '\.bzr']
let NERDTreeChDirMode=0
let NERDTreeMouseMode=2
let NERDTreeShowHidden=1
let NERDTreeKeepTreeInNewTab=1
let g:nerdtree_tabs_open_on_gui_startup=0
let g:NERDShutUp=1
let g:NERDTreeWinSize=41 " original + 10

noremap <silent> <F4> :NERDTreeToggle<Cr>
noremap <leader>n :NERDTreeFind<Cr>

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

hbarcelos avatar May 20 '19 00:05 hbarcelos

Can either of you give me a clearer set of steps to reproduce this? I see that @NickolasHKraus is using syntastic and @hbarcelos is using ALE. I'm wondering if there is some interaction between either of those plugins and NERDTree that's causing this issue. I've tried both, and I don't see the problem that you've described.

PhilRunninger avatar Jul 03 '19 19:07 PhilRunninger

I can trigger this bug reliably by opening a file that causes the quickfix dialog to open, opening another file, then writing that file. Here is another example GIF:

2019-07-05 15 20 37

nickolashkraus avatar Jul 05 '19 20:07 nickolashkraus

To me, this issue occurs when there's any open floating window (I'm using Coc.nvim) as seen here:

Screen-Recording-2020-01-06-at-16 22 44

After debugging to find which setting was responsible, I found that setting set updatetime=<value> would change how soon this would happen as it affects CursorHold but I could not figure out how NERDTree uses this setting.

I also raised an issue in chat with Coc.nvim's maintainer who advised that I should avoid jump to float window but unfortunately I couldn't get any pointers on how to do that.

codingedward avatar Jan 07 '20 08:01 codingedward

@NickolasHKraus @hbarcelos @codingedward I suspect there is an autocommand that is calling some other function, which causing this behavior. Please add a comment with the contents of these Vim commands:

autocmd CursorHold
autocmd CursorHoldI
autocmd CursorMoved
autocmd CursorMovedI
autocmd BufEnter
autocmd BufLeave
autocmd WinEnter
autocmd WinLeave

I'm sure this is only the first step in tracking this down. Thanks for your help.

PhilRunninger avatar Jan 07 '20 14:01 PhilRunninger

Here's what I got: autocmd CursorHold:

:autocmd CursorHold
--- Autocommands ---
coc_nvim  CursorHold
    *         call s:Autocmd('CursorHold', +expand('<abuf>'))
gitgutter  CursorHold
    *         call gitgutter#process_buffer(bufnr(''), 0)
nerdtreegitplugin  CursorHold
    *         silent! call s:CursorHoldUpdate()
webdevicons_cursor_hold  CursorHold
    *         silent! call s:CursorHoldUpdate()
airline_whitespace  CursorHold
    *         call <sid>ws_refresh()

autocmd CursorHoldI:

:autocmd CursorHoldI
--- Autocommands ---
coc_nvim  CursorHoldI
    *         call s:Autocmd('CursorHoldI', +expand('<abuf>'))
gitgutter  CursorHoldI
    *         call gitgutter#process_buffer(bufnr(''), 0)

autocmd CursorMoved:

:autocmd CursorMoved
--- Autocommands ---
coc_nvim  CursorMoved
    *         call s:Autocmd('CursorMoved', +expand('<abuf>'), [line('.'), col('.')])
airline  CursorMoved
    *         call <sid>on_cursor_moved()
matchparen  CursorMoved
    *         call s:Highlight_Matching_Pair()
jsx_comment  CursorMoved
    <buffer=5>
              call jsx_pretty#comment#update_commentstring(b:original_commentstring)
    <buffer=6>
              call jsx_pretty#comment#update_commentstring(b:original_commentstring)
    <buffer=7>
              call jsx_pretty#comment#update_commentstring(b:original_commentstring)
    <buffer=15>
              call jsx_pretty#comment#update_commentstring(b:original_commentstring)
    <buffer=16>
              call jsx_pretty#comment#update_commentstring(b:original_commentstring)
    <buffer=19>
              call jsx_pretty#comment#update_commentstring(b:original_commentstring)

// ... these go on upto <buffer=104> 

autocmd CursorMovedI:

:autocmd CursorMovedI
--- Autocommands ---
coc_nvim  CursorMovedI
    *         call s:Autocmd('CursorMovedI', +expand('<abuf>'), [line('.'), col('.')])
matchparen  CursorMovedI
    *         call s:Highlight_Matching_Pair()

autocmd BufEnter:

:autocmd BufEnter
--- Autocommands ---
filetypedetect  BufEnter
    *.xpm     if getline(1) =~ "XPM2" |   setf xpm2 | else |   setf xpm | endif
    *.xpm2    setf xpm2
numbertoggle  BufEnter
    *         set relativenumber
coc_nvim  BufEnter
    *         call s:Autocmd('BufEnter', +expand('<abuf>'))
gitgutter  BufEnter
    *         call s:on_bufenter()
BufEnter
    *         :call AutoPairsTryInit()
NERDTree  BufEnter
    NERD_tree_*
              stopinsert
NERDTreeHijackNetrw  BufEnter
    *         call nerdtree#checkForBrowse(expand('<amatch>'))
Vimball  BufEnter
    *.vba     setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.gz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.bz2 setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.zip setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.xz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb     setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.gz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.bz2 setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.zip setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.xz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
fugitive_status  BufEnter
    index     call s:ReloadWinStatus()
    index.lock
              call s:ReloadWinStatus()
fugitive_merge  BufEnter
    *         if exists('s:rebase_continue') |   if has('timers') |      call timer_start(0, function('s:RebaseContinue', [remove(s:, 'rebase_continue')])) |   else |      call s:RebaseContinue(remove(s:, 'rebase_continue')) |   endif | e
ndif

autocmd BufLeave:

:autocmd BufLeave
--- Autocommands ---
numbertoggle  BufLeave
    *         set norelativenumber
gitgutter  BufLeave
    term://*  call gitgutter#all(1)
NERDTree  BufLeave
    NERD_tree_*
              if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif

autocmd WinEnter:

:autocmd WinEnter
--- Autocommands ---
NERDTree  WinEnter
    NERD_tree_*
              stopinsert
tmux_navigator  WinEnter
    *         let s:tmux_is_last_pane = 0
GoldenView  WinEnter
    *         call GoldenView#Enter({'event' : 'WinEnter'})
fzf_popd  WinEnter
    *         call s:dopopd()
fzf_buffers  WinEnter
    *         let g:fzf#vim#buffers[bufnr('')] = reltimefloat(reltime())
airline  WinEnter
    *         call <sid>on_window_changed('WinEnter')
matchparen  WinEnter
    *         call s:Highlight_Matching_Pair()

autocmd WinLeave:

:autocmd WinLeave
--- Autocommands ---
coc_nvim  WinLeave
    *         call coc#util#clearmatches(get(w:, 'coc_matchids', []))
NERDTree  WinLeave
    NERD_tree_*
              if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif
GoldenView  WinLeave
    *         call GoldenView#Leave()

codingedward avatar Jan 07 '20 16:01 codingedward

@hbarcelos @codingedward are you using nerdtree-git-plugin?

nickolashkraus avatar Jan 07 '20 17:01 nickolashkraus

Hi @NickolasHKraus Yes, I am using it.

About the commands you asked for:

`autocmd CursorHold`:
ALEEvents  CursorHold
*         if exists('*ale#engine#Cleanup') | call ale#cursor#EchoCursorWarningWithDelay() | endif
    signify  CursorHold
*         call sy#start()
    webdevicons_cursor_hold  CursorHold
    *         silent! call s:CursorHoldUpdate()
    nerdtreegitplugin  CursorHold
    *         silent! call s:CursorHoldUpdate()
`autocmd CursorHoldI`: ``` signify CursorHoldI * call sy#start() ```
`autocmd CursorMoved`: ``` ALEEvents CursorMoved * if exists('*ale#engine#Cleanup') | call ale#cursor#EchoCursorWarningWithDelay() | endif lightline CursorMoved * call lightline#update_once() matchparen CursorMoved * call s:Highlight_Matching_Pair() ycmcompletemecursormove CursorMoved * call s:OnCursorMovedNormalMode() startify CursorMoved call s:set_cursor() ContextCommentstringEnabled CursorMoved call UpdateCommentString() ```
`autocmd CursorMovedI`: ``` matchparen CursorMovedI * call s:Highlight_Matching_Pair() better_whitespace CursorMovedI * call HighlightEOLWhitespaceExceptCurrentLine() call HighlightEOLWhitespaceExceptCurrentLine() ```
`autocmd BufEnter`:
filetypedetect  BufEnter
*.xpm     if getline(1) =~ "XPM2" |   setf xpm2 | else |   setf xpm | endif
*.xpm2    setf xpm2
    BufEnter
*         call MyLastWindow()
    NERDTree  BufEnter
    *         if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
    ALEEvents  BufEnter
    *         call ale#events#ReadOrEnterEvent(str2nr(expand('<abuf>')))
    lightline  BufEnter
*         call lightline#update()
    signify  BufEnter
*         call sy#start()
    NERDTree  BufEnter
    NERD_tree_*
    stopinsert
    NERDTreeHijackNetrw  BufEnter
    *         call nerdtree#checkForBrowse(expand("<amatch>"))
    BufEnter
    *         :call AutoPairsTryInit()
    Vimball  BufEnter
    *.vba     setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.gz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.bz2 setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.zip setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vba.xz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb     setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.gz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.bz2 setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.zip setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    *.vmb.xz  setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
    youcompleteme  BufEnter
    *         call s:OnBufferEnter()
    call s:UpdateMatches()
    BufExplorer  BufEnter
    *         call s:ActivateBuffer()
    ALEHighlightBufferGroup  BufEnter
*         call ale#highlight#UpdateHighlights()
`autocmd BufLeave`: ``` NERDTree BufLeave NERD_tree_* if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif ```
`autocmd WinEnter`: ``` WinEnter * call SetupAutoCommands() lightline WinEnter * call lightline#update() signify WinEnter * call sy#start() NERDTree WinEnter NERD_tree_* stopinsert tmux_navigator WinEnter * let s:tmux_is_last_pane = 0 matchparen WinEnter * call s:Highlight_Matching_Pair() youcompleteme WinEnter * call s:UpdateMatches() ```
`autocmd WinLeave`:
NERDTree  WinLeave
    NERD_tree_*
              if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif

hbarcelos avatar Jan 07 '20 19:01 hbarcelos

Yes @NickolasHKraus I'm using it.

codingedward avatar Jan 07 '20 19:01 codingedward

I have tried disabling it (by commenting out the Plug 'Xuyuanp/nerdtree-git-plugin' entry) but the problem persists.

codingedward avatar Jan 07 '20 19:01 codingedward

Alright, I have a down day so I am going to dig into this issue. I have had problems with nerdtree-git-plugin in the past, since it hijacks NERDTree's functions.

nickolashkraus avatar Jan 08 '20 19:01 nickolashkraus

@codingedward You may need to run PlugClean to remove the plugin after commenting it out in your .vimrc.

nickolashkraus avatar Jan 08 '20 19:01 nickolashkraus

I was able to reliably reproduce the issue. After removing nerdtree-git-plugin, NERDTree no longer jumped to the open file on write. Looking into why this is the case. I like nerdtree-git-plugin, however it is buggy as hell and the maintainer is unresponsive.

nickolashkraus avatar Jan 08 '20 20:01 nickolashkraus

Hello @NickolasHKraus, I removed nerd-tree-git-plugin (by running :PlugClean) but the problem still persists, unfortunately.

I'll also do a bit of debugging on my side and see if I can provide a minimal .vimrc that reproduces the issue. I am guessing I might have another plugin that could be using the same function (or vim API call?) as nerdtree-git-plugin.

codingedward avatar Jan 09 '20 08:01 codingedward

Hello @NickolasHKraus, @PhilRunninger.

After a bit of debugging, I can confirm that the culprit is nerd-tree-git-plugin as @NickolasHKraus has pointed out.

Interestingly, since I use another NERDTree plugin vim-devicons, disabling nerd-tree-git-plugin alone was not enough to stop the jumpy behavior.

It turns out that these two plugins share a chunk of code that is responsible for the malfunction:

In nerdtree-git-plugin, here,

" FUNCTION: s:CursorHoldUpdate() {{{2
function! s:CursorHoldUpdate()
    if g:NERDTreeUpdateOnCursorHold != 1
        return
    endif

    if !g:NERDTree.IsOpen()
        return
    endif

    " Do not update when a special buffer is selected
    if !empty(&l:buftype)
        return
    endif

    let l:winnr = winnr()
    let l:altwinnr = winnr('#')

    call g:NERDTree.CursorToTreeWin() " <-------- the offending call
    call b:NERDTree.root.refreshFlags()
    call NERDTreeRender()

    exec l:altwinnr . 'wincmd w'
    exec l:winnr . 'wincmd w'
endfunction

and in vim-devicons here

" scope: local
" stole solution/idea from nerdtree-git-plugin :)
function! s:CursorHoldUpdate()
  if g:NERDTreeUpdateOnCursorHold != 1
    return
  endif

  if !exists('g:NERDTree') || !g:NERDTree.IsOpen()
    return
  endif

  " Do not update when a special buffer is selected
  if !empty(&l:buftype)
    return
  endif

  " winnr need to make focus go to opened file
  " CursorToTreeWin needed to avoid error on opening file
  let l:winnr = winnr()
  let l:altwinnr = winnr('#')

  call g:NERDTree.CursorToTreeWin() " <-------- the offending call
  call b:NERDTree.root.refreshFlags()
  call NERDTreeRender()

  exec l:altwinnr . 'wincmd w'
  exec l:winnr . 'wincmd w'
endfunction

The function causing the issues is the call to g:NERDTree.CursorToTreeWin() as commenting it out solves the problem.

Instead of this, I am guessing both authors ought to have called g:NERDTreeFocus(). I would have raised a PR but I'm not entirely conversant with VimScript.

codingedward avatar Jan 09 '20 23:01 codingedward

Excellent sleuthing @codingedward. Even if you don't submit PR's to fix them, raising issues on both the other repositories and linking them back here is probably the best first step to getting fixes landed in the right places.

alerque avatar Jan 10 '20 04:01 alerque

@NickolasHKraus @codingedward Thanks for digging into the code, while I currently cannot spare the time to do so. Regarding your proposed solution, I'm not sure it's that simple, because NERDTreeFocus calls NERDTree.CursorToTreeWin().

function! NERDTreeFocus()
    if g:NERDTree.IsOpen()
        call g:NERDTree.CursorToTreeWin()
    else
        call g:NERDTreeCreator.ToggleTabTree('')
    endif
endfunction
function! s:NERDTree.CursorToTreeWin()
    call g:NERDTree.MustBeOpen()
    call nerdtree#exec(g:NERDTree.GetWinNum() . 'wincmd w', 1)
endfunction

function! s:NERDTree.MustBeOpen()
    if !s:NERDTree.IsOpen()
        throw 'NERDTree.TreeNotOpen'
    endif
endfunction

PhilRunninger avatar Jan 10 '20 06:01 PhilRunninger

Agreed. I don't think it is NERDTree.CursorToTreeWin(), but rather the call to NERDTreeRender(). Here is the call chain:

NERDTreeRender

function! NERDTreeRender()
    call nerdtree#renderView()
endfunction

renderView

"FUNCTION: nerdtree#renderView {{{2
function! nerdtree#renderView()
    call b:NERDTree.render()
endfunction

render

" FUNCTION: s:UI.render() {{{1
function! s:UI.render()
    setlocal noreadonly modifiable

    " remember the top line of the buffer and the current line so we can
    " restore the view exactly how it was
    let curLine = line(".")
    let curCol = col(".")
    let topLine = line("w0")

    " delete all lines in the buffer (being careful not to clobber a register)
    silent 1,$delete _

    call self._dumpHelp()

    " delete the blank line before the help and add one after it
    if !self.isMinimal()
        call setline(line(".")+1, "")
        call cursor(line(".")+1, col("."))
    endif

    if self.getShowBookmarks()
        call self._renderBookmarks()
    endif

    " add the 'up a dir' line
    if !self.isMinimal()
        call setline(line(".")+1, s:UI.UpDirLine())
        call cursor(line(".")+1, col("."))
    endif

    " draw the header line
    let header = self.nerdtree.root.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
    call setline(line(".")+1, header)
    call cursor(line(".")+1, col("."))

    " draw the tree
    silent put =self.nerdtree.root.renderToString()

    " delete the blank line at the top of the buffer
    silent 1,1delete _

    " restore the view
    let old_scrolloff=&scrolloff
    let &scrolloff=0
    call cursor(topLine, 1)
    normal! zt
    call cursor(curLine, curCol)
    let &scrolloff = old_scrolloff

    setlocal readonly nomodifiable
endfunction

Of interest are the last few lines:

" restore the view
let old_scrolloff=&scrolloff
let &scrolloff=0
call cursor(topLine, 1)
normal! zt
call cursor(curLine, curCol)
let &scrolloff = old_scrolloff

This is responsible for returning the view by repositioning the edit window.

nickolashkraus avatar Jan 10 '20 10:01 nickolashkraus

This only occurs however when the window height is sufficiently small (execute :echo winheight('%') to get the window height) and/or the buffer is sufficiently large (execute :echo line('$') to get the last line of the current buffer). AND there needs to be a Location List buffer (execute :lopen).

nickolashkraus avatar Jan 10 '20 10:01 nickolashkraus

Steps to repro for me are:

  1. Open vim.
  2. Open file.
  3. Open location list (:lopen).
  4. Write file (:w). Location list closes.
  5. Write file (:w). NERDTree jumps to open file.

nickolashkraus avatar Jan 10 '20 10:01 nickolashkraus

I can confirm that disabling the call to NERDTreeRender() removes the problem entirely.

Interestingly, also calling g:NERDTree.NERDTreeFocus() instead of g:NERDTree.CursorToTreeWin() also solves it.

codingedward avatar Jan 10 '20 11:01 codingedward

g:NERDTree.NERDTreeFocus() is not a function. Did you mean NERDTreeFocus()?

nickolashkraus avatar Jan 10 '20 11:01 nickolashkraus

NERDTreeFocus() simply calls g:NERDTree.CursorToTreeWin() then exits.

nickolashkraus avatar Jan 10 '20 11:01 nickolashkraus

My bad, I was using g:NERDTree.NERDTreeFocus() and it must have been failing at that point, leading me to believe it was the solution.

Disabling NERDTreeRender() is indeed the solution 👍

I could raise issues on the two plugins (nerdtree-git-plugin and vim-devicons) but I'm afraid I might not have enough context (Vim API knowledge) to know how to phrase this in the best way.

codingedward avatar Jan 10 '20 11:01 codingedward

Disabling NERDTreeRender() renders these plugins rather inert.. I think we are getting close.

nickolashkraus avatar Jan 10 '20 11:01 nickolashkraus

I'd be more inclined to find a root cause and a solution in NERDTreeRender. These and other plugins need to know that's a safe function to call after their Listener functions do their thing.

PhilRunninger avatar Jan 10 '20 12:01 PhilRunninger

@hbarcelos @codingedward can you provide the output of :autocmd BufWritePost?

nickolashkraus avatar Jan 10 '20 12:01 nickolashkraus

Hello @NickolasHKraus,

Here's what I got:

:autocmd BufWritePost
--- Autocommands ---
vimrc  BufWritePost
    .vimrc    so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
    _vimrc    so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
    vimrc     so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
    .gvimrc   so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
    _gvimrc   so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
    gvimrc    so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
coc_nvim  BufWritePost
    *         call s:Autocmd('BufWritePost', +expand('<abuf>'))
airline  BufWritePost
    */autoload/airline/themes/*.vim
              exec 'source '.split(globpath(&rtp, 'autoload/airline/themes/'.g:airline_theme.'.vim', 1), "\n")[0] | call airline#load_theme()
gzip  BufWritePost
    *.gz      call gzip#write("gzip")
    *.bz2     call gzip#write("bzip2")
    *.Z       call gzip#write("compress -f")
    *.lzma    call gzip#write("lzma -z")
    *.xz      call gzip#write("xz -z")
    *.lz      call gzip#write("lzip")
    *.zst     call gzip#write("zstd --rm")
BufWritePost
    *         call s:reset_untracked_cache(0)
airline_whitespace  BufWritePost
    *         call <sid>ws_refresh()
fugitive_status  BufWritePost
    *         call fugitive#ReloadStatus(-1, 0)

codingedward avatar Jan 10 '20 17:01 codingedward

There you go:

ALEEvents  BufWritePost
    *         call ale#events#SaveEvent(str2nr(expand('<abuf>')))
CtrlPMRUF  BufWritePost
    *         cal s:record(expand('<abuf>', 1))
signify  BufWritePost
    *         call sy#start()
nerdtreegitplugin  BufWritePost
    *         call s:FileUpdate(expand('%:p'))
gzip  BufWritePost
    *.gz      call gzip#write("gzip")
    *.bz2     call gzip#write("bzip2")
    *.Z       call gzip#write("compress -f")
    *.lzma    call gzip#write("lzma -z")
    *.xz      call gzip#write("xz -z")
    *.lz      call gzip#write("lzip")
    *.zst     call gzip#write("zstd --rm")

Sorry not being able to help with the debugging process, it's been some pretty busy days for me :disappointed:

hbarcelos avatar Jan 15 '20 14:01 hbarcelos

I just merged a pull request that addresses three other issues. Given it also was related to autocommands, it may fix this one too. No guarantees though. Give it a shot with the latest master, and let us know.

PhilRunninger avatar Jan 17 '20 04:01 PhilRunninger