359

Is there a simple way of finding out the current value of a specified Vim setting? If I want to know the current value of, say tabstop, I can run:

:set tabstop

without passing an argument, and Vim will tell me the current value. This is fine for many settings, but it is no good for those that are either true or false. For example, if I want to find out the current value of expandtab, running:

:set expandtab

will actually enable expandtab. I just want to find out if it is enabled or not.

This sort of does what I want:

:echo &l:expandtab

but it seems quite verbose. Is there a quicker way?

6 Answers 6

499

Add a ? mark after the setting name and it will show the value

:set expandtab?
4
  • 20
    Note that the set <...>? syntax will work for "settings" that are options, but not for "settings" that are variables. So for example, to find out what the current syntax highlighting mode is (encoded in a variable, not an option), you need to do echo b:current_syntax.
    – Maxy-B
    Oct 12, 2014 at 22:24
  • 23
    If you want to also see where the option was set from, use verbose. For this example, :verbose set expandtab.
    – mkobit
    Mar 19, 2016 at 19:08
  • 1
    How do see the current value of settings such as behave? I have tried behave? and set behave?. Unfortunately, they do not work.
    – jdhao
    Jan 15, 2019 at 6:30
  • 4
    @mkobit I had to use :verbose set expandtab? for it to work Sep 1, 2021 at 11:24
56

Alternatively, the & symbol can be used to mean "option" - e.g.

let x = &expandtab
echo &expandtab
2
  • Is there also an option to get the value of a list element? (e.g. space of listchars)
    – 816-8055
    Jul 14, 2016 at 18:41
  • I believe listchars is an ordinary string, not a List, though I guess you could do something like split(&listchars, ',')
    – cdyson37
    Jul 15, 2016 at 6:59
23

If you don't remember what setting you want to check, you can view all settings:

:set all

or show each setting, one setting per line:

:set! all
5

There are also additional vim settings that can be displayed as well, such as:

:highlight

For the full list, see: http://vim.wikia.com/wiki/Displaying_the_current_Vim_environment

Edit: There is some misunderstanding of my answer. This does not work for any command. But it does work for all the commands listed in the URL above.

3
  • 1
    This does not work. I wanted to check whether autowrite is on. :set autowrite? does the job.
    – Atcold
    Mar 31, 2016 at 18:17
  • @Atcold: this does work for some settings, for which only this type of query will work. May 11, 2018 at 13:02
  • @gmarmstrong: I see the answer have been edited with such remark.
    – Atcold
    May 11, 2018 at 14:54
0

If you're using Neovim, use Lua:

:lua print(vim.o.<option>)

For example:

:lua print(vim.o.foldmethod)
expr
0

Use:

:verbose set tabstop? expandtab? 

It will also tell you from which config file are the settings coming.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

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