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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:31:19+00:00 2026-05-18T20:31:19+00:00

I know that when you define a function in vim, you can use the

  • 0

I know that when you define a function in vim, you can use the range keyword so that users can say:

:-5,+5call MyFunction()

And then your function gets a:firstline and a:lastline.

What I want is something similar, but more like the traditional vi way of combining a command with a movement, so that ‘d ‘ deletes a space, ‘dw’ deletes a word, ‘d2w’ deletes two words, ‘d2j’ deletes three lines, etc. Assuming my function gets mapped to some input-mode character sequence, is there any way to make it accept similar variable-length inputs, and then modify that text?

Just to be a little more clear, suppose I want to define a function to wrap <b> tags around existing text. We’ll say that function is mapped to ;b. I want users to be able to say ‘;bw’ to bold one word, or ‘;bf.’ to bold everything to the end of the sentence, or whatever, with all the flexibility that vim provides to built-in commands.

  • 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-18T20:31:20+00:00Added an answer on May 18, 2026 at 8:31 pm

    If I understand what you’re asking, then all you do is include the char argument in your mapping. For example:

    map d :call MyFunction('d')<cr>
    map dw :call MyFunction('dw')<cr>
    map d2w :call MyFunction('d2w')<cr>
    " Of course these would be terrible mappings because they 
    " are already mapped to important Vim functions
    

    The way mappings work is that if you “overspecify” a char like ‘d’ above so that it is usable either by itself or as a prefix for longer command, Vim will wait briefly (for timeoutlen)after you press ‘d’ to see if you’re going to press another character. (This depends on thetimeout option being set to true, which is the default.) If you don’t press another character, Vim will execute the ‘d’ mapping. If you do it will call the more complex mapping. See :h map-commands generally and :h map-typing for more.

    Note: After your clarification I think what you want is to create a custom ‘operator’ function that you can use to operate on buffer areas defined by Vim motions. See :h map-operator for info on how to do this.

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

Sidebar

Related Questions

I know that when you define a function in vim, you can use the
I would like to know that if we #define a particular function like this
I know that automatic properties must define a get and set accessor method, I
I started using SuperTab recently, but I want to use Ctrl-space instead of Tab.
#ifndef __TEST__ #define __TEST__ namespace std { template<typename T> class list; } template<typename T>
hi i am new to java....moved from objective c (iphone background) all we know
I have a third-party function which gives me a filtered queryset (e.g. records with
I've just got confused how to implement something in a generic way in C++.
I am currently a asp.net guy, but have to do some jsp work now.

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.