1

How can I view a list of all of the features that can be checked for using has() in Vim?

I recently came to know the has() function for testing the presence of "features" (see below).

:h features doesn't show a list of features to test for.

How can I see a list of all features that I can test for using has()?

if has('gui_running')
   set background=dark
   colorscheme codedark
else
"   set termguicolors
   set t_Co=256
   set background=dark
   colorscheme codedark
endif
4
  • 1
    :h feature-list and scroll down a bit. It lists the feature that can be tested Jul 15, 2020 at 8:32
  • Very useful! How did you find this help entry? Does vim support something similar to apropos?
    – Shuzheng
    Jul 15, 2020 at 8:40
  • I am just following the links from the help Jul 15, 2020 at 8:57
  • 1
    In fact, a link to the help for feature-list is three lines into the help for has().
    – B Layer
    Jul 15, 2020 at 9:06

4 Answers 4

2

Just for information, not every possible thing that can be checked with has() is listed in :h +feature-list. This mostly documents things that may differ according to different choices done when vim has been compiled, and what systems it targets. IOW: enabled features.

To known whether Vim supports things introduced at different moment in time, like for instance redo on insert mode cursor movement (required for implementing ergonomic bracketing mappings), background compilation (are you still using plain :make?), some precise information in getbufinfo(), we need to check Vim history.

At that point, we

  • either have to dig into the :h version7.0, :h version8.0, :h version9.0... files to find the patch that introduces what we are looking for.
  • or to check git blame on its documentation -- fortunately, most patches document what they do/change/introduce.

(and as I never remember when features I need has been introduced, I collect them in a dedicated file in my plugin library).

2

:help feature-list is the only complete list of features you can test with has("…").

⚠ You want :help feature-list (no +), not :help +feature-list (with +). They are different!


There are also two incomplete lists:

:version lists a subset of possible features and shows which are enabled/present, and which are not. It is ostensibly the list of options enabled when your Vim was compiled.

:help +feature-list (with +) is under the documentation for :version. It ostemsibly lists the possible options you might see under :version

Comparing the three lists for my Vim 9.0, I found:

  • 201 entries in :help feature-list (no +)
  • 160 entries in :help +feature-list (with +)
  • 131 entries in :version

Many entries in :help +feature-list (with +) and :version are written with punctuation that has("…") will not recognize (ex: fork() and python3/dyn). There are also differences in case (ex: GUI_Motif in :help +feature-list versus gui_motif in :help feature-list). Even after normalizing to remove those differences, neither of the lists in the two help pages is a subset of the other.

At any rate, :help feature-list (no +) is the one associated with the has("…") function, and has the entries written in a way that is suitable for that function.

1
  • I say "ostensibly" because the list of features shown by :version is clearly different from the list shown in :help +feature-list (right below :version in the help page). Each has something the other does not have. There seems to be a discrepancy.
    – Alex Quinn
    Feb 25 at 18:15
1

The documentation in :help has() has a pointer to the features it can check for:

The {feature} argument is a string, case is ignored. See feature-list below.

If you then look at :help feature-list, you'll see it mentions the three kinds of features that can be tested using has():

There are three types of features:

  1. Features that are only supported when they have been enabled when Vim was compiled +feature-list.
  2. Features that are only supported when certain conditions have been met.
  3. Beyond a certain version or at a certain version and including a specific patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or later, or it is version 7.4 and patch 248 was included.

Note that has("gui_running") is the canonical example of a feature of kind 2. Other examples of kind 2 would be has("vim_starting"), has("ttyin") and has("ttyout").

That description of the three kinds of features is followed by a thorough list of features matching kinds 1 and 2. (I won't reproduce it here, you can find it from the linked documentation or, better yet, from the :help system in your copy of Vim or NeoVim.)

See also :help +feature-list, which covers compile-time options that become features (those of kind 1) in more detail, with links to what those features actually enable.

0

You can see a list of these features with :version.

This will show you which is available and which is not, as well as your Vim version, compilation method and other information.

2
  • 1
    Is that a complete list of all (standardised) Vim features, or are such features added on a add-hoc basic by different Vim flavors (vim, nvim, macvim, etc.)? How does has() really work? Is it doing a substring search, i.e. has('vim') tries to match 'vim' against all features listed by :version? Also, are (some of) these features generated by Vim at runtime, because has('vim') is true, when starting Macvim in terminal mode, but false when starting it in GUI mode?
    – Shuzheng
    Jul 15, 2020 at 8:33
  • I think you should update your question, I do not have the knowledge to give a more accurate answer.
    – Biggybi
    Jul 15, 2020 at 8:46

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.