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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:07:08+00:00 2026-06-13T17:07:08+00:00

Is it possible to :map to a function that can detect the mode it

  • 0

Is it possible to :map to a function that can detect the mode it was
called in? This is what I have:

func! s:ShowModeFunction()
    echomsg mode(1)
endfunc

noremap <expr> <Plug>ShowMode <SID>ShowModeFunction()

map \m <Plug>ShowMode

The map \m eventually calls the top function, which echos a string
indicating normal mode, operator-pending mode, or any of the Visual
modes.

This only works with <expr> on the middle map though; any colon
command would render the final mode() call useless, because it would
then always return “normal mode”. Unfortunately, <expr> strictly
requires an expression on the right-hand side, and since the function
doesn’t return anything, the implicit return value 0 is used, which
moves the cursor to the first column.

  • 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-06-13T17:07:09+00:00Added an answer on June 13, 2026 at 5:07 pm

    Just make the function return nothing, this is then a no-op in the expression mapping:

    func! s:ShowModeFunction()
        echomsg mode(1)
        return ''
    endfunc
    

    If there’s any other limitation in map-expr, just set a variable in there, and do the real work (including evaluating the variable) in a “normal” mapping or :call that you can append to your <Plug>ShowMode mapping (or another intermediate one, to keep the customizability).

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

Sidebar

Related Questions

Is it possible to write a Hadoop-ready reduce function that can find the longest
I see that I can map a function over mutable arrays with mapArray, but
Rails make It possible to map resources that are logically children of other resources
Possible Duplicate: remove_if equivalent for std::map I have a set of strings: set <wstring>
I need to run a function that takes two arguments several times. I have
I have a simple question. Is it possible to wrap a SQL function in
I have a function that geo-tags items using Google Maps API based on basic
Hello everybody With EF4, i can map a EDMX function (with update model from
I have a function that checks whether a type is a subtype of another
I have a templated function fct that uses some complex data structure based on

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.