Skip to main content
added 46 characters in body
Source Link

I want to disable cursorline when leaving the NERD tree window and enable it when entering the window again.

The following setting works fine when using <C-w>w or similar, but not when <CR>. Hitting <CR> opens the file in other window, moves to it, and cursorline remains visible. How can I make it work?

augroup Cursorline
  au!
  au WinEnter * if exists('t:NERDTreeBufName') && bufname("%") == t:NERDTreeBufName | setlocal cursorline | endif
  au WinLeave * setlocal nocursorline
augroup END

Environment:

- vim
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 14 2017 20:07:29)
Included patches: 1-1297
- NERDTree
master (461ea6d2d854100f7954c21453bb3b926ad930e6)
- OS
Linux
- Terminal
mintty on Windows
GNU screen
TERM=screen-256color-bce

.vimrc (simplified for testing):

set nocompatible
syntax enable

set runtimepath^=~/git/nerdtree/
    
autocmd! BufEnter * call ToggleCursorLine()

function! ToggleCursorLine()
  if (bufname("%") =~ "NERD_Tree_")
    setlocal cursorline
  else
    setlocal nocursorline
  endif
endfunction

I want to disable cursorline when leaving the NERD tree window and enable it when entering the window again.

The following setting works fine when using <C-w>w or similar, but not when <CR>. Hitting <CR> opens the file in other window, moves to it, and cursorline remains visible. How can I make it work?

augroup Cursorline
  au!
  au WinEnter * if exists('t:NERDTreeBufName') && bufname("%") == t:NERDTreeBufName | setlocal cursorline | endif
  au WinLeave * setlocal nocursorline
augroup END

Environment:

- vim
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 14 2017 20:07:29)
Included patches: 1-1297
- NERDTree
master (461ea6d2d854100f7954c21453bb3b926ad930e6)
- OS
Linux
- Terminal
mintty on Windows

.vimrc (simplified for testing):

set nocompatible
syntax enable

set runtimepath^=~/git/nerdtree/
    
autocmd! BufEnter * call ToggleCursorLine()

function! ToggleCursorLine()
  if (bufname("%") =~ "NERD_Tree_")
    setlocal cursorline
  else
    setlocal nocursorline
  endif
endfunction

I want to disable cursorline when leaving the NERD tree window and enable it when entering the window again.

The following setting works fine when using <C-w>w or similar, but not when <CR>. Hitting <CR> opens the file in other window, moves to it, and cursorline remains visible. How can I make it work?

augroup Cursorline
  au!
  au WinEnter * if exists('t:NERDTreeBufName') && bufname("%") == t:NERDTreeBufName | setlocal cursorline | endif
  au WinLeave * setlocal nocursorline
augroup END

Environment:

- vim
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 14 2017 20:07:29)
Included patches: 1-1297
- NERDTree
master (461ea6d2d854100f7954c21453bb3b926ad930e6)
- OS
Linux
- Terminal
mintty on Windows
GNU screen
TERM=screen-256color-bce

.vimrc (simplified for testing):

set nocompatible
syntax enable

set runtimepath^=~/git/nerdtree/
    
autocmd! BufEnter * call ToggleCursorLine()

function! ToggleCursorLine()
  if (bufname("%") =~ "NERD_Tree_")
    setlocal cursorline
  else
    setlocal nocursorline
  endif
endfunction
added environment
Source Link

I want to disable cursorline when leaving the NERD tree window and enable it when entering the window again.

The following setting works fine when using <C-w>w or similar, but not when <CR>. Hitting <CR> opens the file in other window, moves to it, and cursorline remains visible. How can I make it work?

augroup Cursorline
  au!
  au WinEnter * if exists('t:NERDTreeBufName') && bufname("%") == t:NERDTreeBufName | setlocal cursorline | endif
  au WinLeave * setlocal nocursorline
augroup END

Environment:

- vim
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 14 2017 20:07:29)
Included patches: 1-1297
- NERDTree
master (461ea6d2d854100f7954c21453bb3b926ad930e6)
- OS
Linux
- Terminal
mintty on Windows

.vimrc (simplified for testing):

set nocompatible
syntax enable

set runtimepath^=~/git/nerdtree/
    
autocmd! BufEnter * call ToggleCursorLine()

function! ToggleCursorLine()
  if (bufname("%") =~ "NERD_Tree_")
    setlocal cursorline
  else
    setlocal nocursorline
  endif
endfunction

I want to disable cursorline when leaving the NERD tree window and enable it when entering the window again.

The following setting works fine when using <C-w>w or similar, but not when <CR>. Hitting <CR> opens the file in other window, moves to it, and cursorline remains visible. How can I make it work?

augroup Cursorline
  au!
  au WinEnter * if exists('t:NERDTreeBufName') && bufname("%") == t:NERDTreeBufName | setlocal cursorline | endif
  au WinLeave * setlocal nocursorline
augroup END

I want to disable cursorline when leaving the NERD tree window and enable it when entering the window again.

The following setting works fine when using <C-w>w or similar, but not when <CR>. Hitting <CR> opens the file in other window, moves to it, and cursorline remains visible. How can I make it work?

augroup Cursorline
  au!
  au WinEnter * if exists('t:NERDTreeBufName') && bufname("%") == t:NERDTreeBufName | setlocal cursorline | endif
  au WinLeave * setlocal nocursorline
augroup END

Environment:

- vim
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 14 2017 20:07:29)
Included patches: 1-1297
- NERDTree
master (461ea6d2d854100f7954c21453bb3b926ad930e6)
- OS
Linux
- Terminal
mintty on Windows

.vimrc (simplified for testing):

set nocompatible
syntax enable

set runtimepath^=~/git/nerdtree/
    
autocmd! BufEnter * call ToggleCursorLine()

function! ToggleCursorLine()
  if (bufname("%") =~ "NERD_Tree_")
    setlocal cursorline
  else
    setlocal nocursorline
  endif
endfunction
Source Link

Disable cursorline when leaving NERD tree window

I want to disable cursorline when leaving the NERD tree window and enable it when entering the window again.

The following setting works fine when using <C-w>w or similar, but not when <CR>. Hitting <CR> opens the file in other window, moves to it, and cursorline remains visible. How can I make it work?

augroup Cursorline
  au!
  au WinEnter * if exists('t:NERDTreeBufName') && bufname("%") == t:NERDTreeBufName | setlocal cursorline | endif
  au WinLeave * setlocal nocursorline
augroup END