Get current value of a setting in Vim

Vim

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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

:set expandtab?

Solution 2 - Vim

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

let x = &expandtab
echo &expandtab

Solution 3 - Vim

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

Solution 4 - Vim

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnelstromView Question on Stackoverflow
Solution 1 - VimJaredParView Answer on Stackoverflow
Solution 2 - Vimcdyson37View Answer on Stackoverflow
Solution 3 - Vim徐新晨View Answer on Stackoverflow
Solution 4 - VimwisbuckyView Answer on Stackoverflow