I want to set some options on a particular window number. What I've been doing is go to the window by {winnr} wincmd w, set some options and do some work then come back. But this creates a UI flash (you can see you changed window for a short amount of time).

Is there any way to modify window options without going there programmatically?

1 Answer 1


The function setwinvar can change options using the & syntax:

call setwinvar(1, "&list", 0)

You can execute any code in the context of another window using win_execute (vim only):

call win_execute(winid, 'set syntax=python')

In neovim there is also nvim_win_set_option

call nvim_win_set_option(win, 'list', 0)
  • Thanks. I don't see a win_execute help? I'm using nvim 0.5.0.
    – Rui Liu
    Commented Mar 22, 2020 at 14:51
  • Also is it possible to create a window without go to it?
    – Rui Liu
    Commented Mar 22, 2020 at 14:51
  • win_execute is vim only, not in neovim. And I don't know of a way to create a window without changing cursor to the window.
    – Mass
    Commented Mar 22, 2020 at 15:06
  • Alright I see. Missing win_execute is quite inconvenient... Another similar question: Is there a way to clear the buffer with given buffer number without going to the buffer? I was using 1,$ delete but that deletes what's in the current buffer. I'm looking for something akin to setbufline?
    – Rui Liu
    Commented Mar 22, 2020 at 15:32
  • deletebufline(), but consider asking a new question
    – Mass
    Commented Mar 22, 2020 at 15:51

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.