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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:23:01+00:00 2026-06-02T23:23:01+00:00

Let say I have this function in menu.vim: function! s:Test() let search = ‘\d\+’

  • 0

Let say I have this function in menu.vim:

  function! s:Test()
   let search = '\d\+'
   let @/ = search
   return "normal n" 
  endfunction

Why doesn’t this highlight the search matches?
Only after I do :set hls in the commandline it does highlighting.
It does also highlighting when I push the n key on my keyboard.
If I put the same line (:set hls) in the function it doesn’t work.
BTW highlighting is enabled in my VIM.
It highlights fine if I use the commandline.

  • 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-02T23:23:03+00:00Added an answer on June 2, 2026 at 11:23 pm

    That behaviour might actually be described in the manual under :help functions-search-undo, but there is no mention of any workaround.

    The last used search pattern and the redo command “.”
    will not be changed by the function. This also implies that the effect of
    :nohlsearch is undone when the function returns.

    The documentation on :nohlsearch also mention this:

    This command doesn’t work in an autocommand, because
    the highlighting state is saved and restored when executing autocommands
    autocmd-searchpat. Same thing for when invoking a user function.

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

Sidebar

Related Questions

Let's say I have this: test = function() { this.init = function() { $(#someElement).html(Hey!).mousedown(function()
Let's say I have this function: function test () { // statements 1 statement_X;
Let's say I have a function like this: function z($zzz){ for($c=0;$c<5;$c++){ $zzz[$c]= 10; //more
Let's say I have this $(document).ready(function() { var array = $.makeArray($('p')); $(array).appendTo(document.body); }); });
Let's say I have this $(.a).animate( {left:100%}, {duration:50000, complete:function(){ $(.a).css(background-color,black); }} ); $(.b).mouseover(function(){ $(.a).stop();
Let's say I have this: <div id=wrapper> <pre class=highlight> $(function(){ // hide all links
Let's say I have a simple function like this: public static string randomthing(string var1)
Let's say I have this function, which is part of some gui toolkit: typedef
Let's say we have this code (forget about prototypes for a moment): function A(){
Let's say I have this code: int function(bool b) { // execution path 1

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.