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

  • SEARCH
  • Home
  • 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 6826087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:06:23+00:00 2026-05-26T22:06:23+00:00

I guess this question could be taken in two ways… (Generic) – is there

  • 0

I guess this question could be taken in two ways…

  1. (Generic) – is there a way to specify settings ‘local’ to a function (setlocal changes seem to persist after the function call)…

  2. (Specific) – I have a function which gets called from an imap mapping (which takes a user input to pass into the function. The function works perfectly if I run set paste or set noai | set nosi either just before running my shortcut, or added into the function itself. The problem is, whichever way I do it, those setting changes persist after my function call.

Essentially, my workflow is:

  1. In insert mode, type //// at which point I get prompted for input text, which I enter and press enter.
  2. The function is called with my input. I need the function to disable indenting, return my string and then re-enable the previous settings. The string would just be a PHP-block comment like this:

    /**
     * Blah {INPUT TEXT}
     */
    

Any suggestions appreciated. My script currently looks like this:

function CommentInjector(txt)
  return "\/**" ."\<CR>"
  \    . " * foo " . a:txt . " bar " . "\<CR>"
  \    . " */"
endfunction
imap <silent> //// <C-R>=CommentInjector(input("Enter some text:"))<CR>

UPDATE

Managed to figure it out at least how to dump a comment in… Would appreciate knowing how to get/restore settings though…

function! CommentInjector(txt)
  set paste

  exe "normal! i/**\<CR>"
  \          . " * fooo " . a:txt . " bar\<CR>"
  \          . " */\<Esc>"

  set nopaste
endfunction

map <C-C><C-C><C-C> :call CommentInjector(input("Enter some text:"))<CR>

Using this you can just pres Ctrl+C 3 time, enter text when prompted and you get a nice comment written in. It assumes you had “set paste” disabled before running though…

  • 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-26T22:06:23+00:00Added an answer on May 26, 2026 at 10:06 pm

    Since you’ve posted an update and are really just looking at how to save/restore settings, I’ll give a general solution.

    • At the start of your function save the initial value of the setting: let save_paste = &paste
    • Make any changes to paste that you’d like to make
    • Restore it at the end: let &paste = save_paste

    An example of this can be found in the documentation with :help use-cpo-save where they talk about saving and restoring the value of cpoptions.

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

Sidebar

Related Questions

Okay guess this question looks a lot like: What is the best way to
I'm working in AS3, but I guess this could be a general question, so
I guess this question will sound familiar, but I am yet another programmer baffled
I have a HashMap (although I guess this question applies to other collections) of
My guess is that this question will fall under the category of duh, but,
I guess this is a simple question. I need to do something like this:
I guess this is kind of an odd question but I have tried setting
I guess this is a continuation of the last question I asked: bulk insert
This question is about Unity Container but I guess it is applicable to any
Warning: This question has been heavily edited. I tried my best to guess the

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.