20

In python, when using the vim module, it is incredibly simple to get the current window/buffer/tabpage:

current_win = vim.current.window
current_buff = vim.current.buffer
current_tabpage = vim.current.tabpage

My question is, how do you do this in pure VimL / Vimscript and what type of object is returned? I really can't seem to find this anywhere in windows.txt (:h windows).

1
  • :h functions makes more sense for you to find script related info.
    – Kent
    Commented Nov 15, 2015 at 17:12

1 Answer 1

28

Well… it's just as simple in vimscript.

Current window

Python:

current_win = vim.current.window

Vimscript:

let current_win = winnr()

Current buffer

Python:

current_buff = vim.current.buffer

Vimscript:

let current_buff = bufnr("%")

Current tabpage

Python:

current_tabpage = vim.current.tabpage

Vimscript:

let current_tabpage = tabpagenr()

See :help functions.

1
  • 1
    Is there a vimscript function to make a buffer active by its id?
    – St.Antario
    Commented Nov 14, 2019 at 13:16

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.