Vim 7.2 Scripting

Written By
Web Webster
Web Webster
May 3, 2010

[ Thanks to Janice
Sequeira
for this link. ]

“Scripting tips

“In this section, we will look at a few extra tips that can be
handy when you create scripts for Vim. Some are simple code pieces
you can add directly in your script, while others are good-to-know
tips. Gvim or Vim?

“Some scripts have extra features when used in the GUI version
of Vim (Gvim). This could be adding menus, toolbars, or other
things that only work if you are using Gvim. So what do you do to
check if the user runs the script in a console Vim or in Gvim? Vim
has already prepared the information for you. You simply have to
check if the feature gui_running is enabled. To do so, you use a
function called has(), which returns 1 (true) if a given feature is
supported / enabled and 0 (false), otherwise.

“An example could be:

if has("gui_running")
"execute gui-only commands here.
endif

“This is all you need to do to check if a user has used Gvim or
not. Note that it is not enough to check if the feature “gui”
exists, because this will return true if your Vim is just compiled
with GUI support—even if it is not using it.”

Complete
Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.