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 6081747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:12:38+00:00 2026-05-23T11:12:38+00:00

I created a lot of functions in menu.vim. I noted that in many functions

  • 0

I created a lot of functions in menu.vim.

I noted that in many functions the same code is used that’s why I decided to clean up my file with the use of
subfunctions.

p.e this is code what often returns in my functions:

let zoek = @/    
if a:type == "'<,'>"    
 let r = substitute(zoek, '\\%V', '', 'g')    
elseif a:type == "%"    
 let r = zoek    
endif    

let a = substitute(r, '\', '', 'g')      

if matchstr(d, '>') == '>' || matchstr(d, '<') == '<'     
 let e = substitute(d, '\zs>\(\d\+\)%<\ze', '\1-', 'g')     
endif

How can I create a subfunction from it? How can I invoke it?
Does Vim have subfunctions?

  • 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-23T11:12:38+00:00Added an answer on May 23, 2026 at 11:12 am

    You can have «local» functions by defining them in the dictionary: in the following code

    function MyFunc()
        let d={}
        function d.function()
            echo "Foo"
        endfunction
        call d.function()
    endfunction
    

    function d.function is accessible only inside s:MyFunc and is destroyed after s:MyFunc exits. I put «local» in quotes because d.function is really global function named 42 (or another number, it does not matter). It cannot be called without a reference to it and the only way to create a reference is to use function dict.key() (references may be copied after creation, but you can’t create a reference using call to function(), though it is possible for MyFunc: function("MyFunc")). Note that number (in this case 42) is incremented each time you create a function and I know neither what is the maximum number nor what will happen when it will be reached. I personally use dictionary functions because they have two other advantages:

    1. Dictionary function defined inside a script-local dictionary cannot be reached without a debugger or explicit passing the function reference (possibly as a part of its container) somewhere.
    2. If more then one function is defined inside a dictionary in order to purge them all you need is to unlet this dictionary. Useful for reloading plugins.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a header file containing a lot of small inline functions. Most of
I have a query that uses a lot of aggregate functions to build data
I am updating some code that was created by another developer and am noticing
I have created a lot of java script functions to encapsulate crud operations for
I've created shared library (will be used like plugin). There are a lot of
I have created a JavaScript application that has a lot of array manipulations (sorting,
I'm developing a WinForms c# 3.0 application. Our designer created quite a lot of
I created an android app to display a lot of images some of them
A lot of JavaScript libraries have user interface widgets. Usually they are created after
I’m having a lot of trouble understanding how to create a module that will

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.