Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6070315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:55:09+00:00 2026-05-23T09:55:09+00:00

In a vim plugin, how can I tell if a user has already set

  • 0

In a vim plugin, how can I tell if a user has already set a variable in their .vimrc file?

For instance, I have in .vimrc:

set shiftwidth=2

Then I load a plugin that has

set shiftwidth=3

So I think to modify the plugin like so:

if !exists("shiftwidth")
  set shiftwidth=3
endif

But when I load up a new vim window with the revised plugin loaded, my tabs are still set to 3 and not 2.

How can I make it so that it only sets shiftwidth=3 unless otherwise specified in .vimrc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:55:10+00:00Added an answer on May 23, 2026 at 9:55 am

    These commands should show where shiftwidth was set:

    :set verbose=15
    :set shiftwidth
    :set verbose=0
    

    If you want to programmatically do something with that info you’d need to redirect the verbose output and parse it for what you want:

    :redir => myvariable
    :set verbose=15
    :set shiftwidth
    :set verbose=0
    :redir END
    

    myvariable will now have text that would otherwise have been printed to screen.

    REVISED ANSWER
    Here is a way I think you could do what you clarify in your comments.

    Add a last line to user’s vimrc to save the current value of shiftwidth to a global variable. The value will be saved before any plugins are loaded, unless plugins are explicitly sourced in the vimrc before the last line. You can then reset shiftwidth to this value in your own plugin.

    [everything in vimrc comes before this line]
    :let g:vimrc_shiftwidth = &shiftwidth
    

    You can programmatically add this line with something like the write >> [file] command. Presumably you would include a comment indicating what plugin had added this command to the vimrc. Also, I don’t think this would capture the correct value, e.g., in case where user uses exrc option and sets shiftwidth in a different vimrc. All in all, still not recommended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started using the NERDTree vim plugin for my project. I can't find
I'm looking for a Vim plugin that can do these kind of thing. Let's
I have a vim plugin that defines a bunch of key mappings. I'm trying
I've installed Syntastic plugin in vim. I can't get it to work. I've tried
I found this plugin: http://vim.wikia.com/wiki/Find_files_in_subdirectories to be really useful to find a file(s) using
Can you give me plugin or something like that for vim to move the
I am using vim 7.3 and the NERDTree 4.1 plugin. I have been trying
I am trying to set some tab indent configurations in Vim. Unfortunately I can't
I copied clang_complete.vim to plugin, but when I typed . after some variable, it
I have deleted my old .vimrc and .vim to configure vim from scratch. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.