Sometimes when I load several buffers at once into multiple windows I might get confused with the position of the cursor, I get lost when I change from buffer to buffer. Therefore I'd like to trigger the ex command :set cursorline to be able to easily see the cursor position.

How can I trigger the command when I load two or more buffers into multiple windows but remove it when there's just one window left?

One window: enter image description here

Several windows: enter image description here

1 Answer 1


Maybe you could try the following autocmd:

augroup cursorline
    autocmd WinEnter * exe winnr('$')>1 ? "set cursorline" : "set nocursorline"
augroup END

Whenever you enter a window (WinEnter event), it executes the following command:

exe winnr('$')>1 ? "set cursorline" : "set nocursorline"

The latter tests if there are several windows (winnr('$')>1). If that's the case, it enables 'cursorline', otherwise it disables it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.