Loading ...
Sorry, an error occurred while loading the content.
 

Re: 'au InsertEnter * noh' doesn't work

Expand Messages
  • Marcin Szamotulski
    ... I think you want to use au InsertEnter * setl nohl Best, Marcin -- You received this message from the vim_use maillist. Do not top-post! Type your reply
    Message 1 of 7 , Mar 30, 2012
      On 21:56 Fri 30 Mar , Unknown wrote:
      > Hi everyone here, I'm just new to this mailing list.
      > I want to automatically disable search highlight when entering insert
      > mode, so I add the command in ~/.vimrc but it didn't work. Does anyone
      > know what I did was wrong?
      >
      > --
      > You received this message from the "vim_use" maillist.
      > Do not top-post! Type your reply below the text you are replying to.
      > For more information, visit http://www.vim.org/maillist.php

      I think you want to use
      au InsertEnter * setl nohl

      Best,
      Marcin

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Ben Fritz
      ... Normally yes, but hlsearch is a global option, there is no local value. Also note hl is shorthand for highlight not hlsearch as desired (you could
      Message 2 of 7 , Mar 30, 2012
        On Friday, March 30, 2012 10:16:46 AM UTC-5, coot_. wrote:
        >
        > I think you want to use
        > au InsertEnter * setl nohl
        >

        Normally yes, but 'hlsearch' is a global option, there is no local value.

        Also note 'hl' is shorthand for 'highlight' not 'hlsearch' as desired (you could use 'hls' though). This is one reason I always use full option names in scripts and only use shorthand interactively.

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Marcin Szamotulski
        ... Indeed you re right. Thanks, Marcin -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
        Message 3 of 7 , Mar 30, 2012
          On 08:46 Fri 30 Mar , Ben Fritz wrote:
          > On Friday, March 30, 2012 10:16:46 AM UTC-5, coot_. wrote:
          > >
          > > I think you want to use
          > > au InsertEnter * setl nohl
          > >
          >
          > Normally yes, but 'hlsearch' is a global option, there is no local value.
          >
          > Also note 'hl' is shorthand for 'highlight' not 'hlsearch' as desired (you could use 'hls' though). This is one reason I always use full option names in scripts and only use shorthand interactively.
          >
          > --
          > You received this message from the "vim_use" maillist.
          > Do not top-post! Type your reply below the text you are replying to.
          > For more information, visit http://www.vim.org/maillist.php

          Indeed you're right. Thanks,
          Marcin

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Benjamin R. Haskell
          ... As pointed out, :noh[lsearch] doesn t work in autocmds. One common workaround is to do it from a mapping. I have the following in my ~/.vimrc: turn off
          Message 4 of 7 , Mar 30, 2012
            On Fri, 30 Mar 2012, Unknown wrote:

            > Hi everyone here, I'm just new to this mailing list. I want to
            > automatically disable search highlight when entering insert mode, so I
            > add the command in ~/.vimrc but it didn't work. Does anyone know what
            > I did was wrong?

            As pointed out, :noh[lsearch] doesn't work in autocmds. One common
            workaround is to do it from a mapping. I have the following in my
            ~/.vimrc:

            " turn off highlighting when refreshing the screen
            nn <silent> <C-l> :noh<CR><C-l>

            (nn = nnoremap)

            Seems like overkill, but you could use:

            for key in ['i','I','o','O','a','A','gi','gI'] " any key that enters insert mode
            exe 'nn <silent>' key ':noh<CR>'.key
            endfor

            Personally, the <C-l> trick works well for me, because I'm used to
            typing Ctrl+l to refresh Alpine.

            --
            Best,
            Ben H

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • 蓝星灿
            Thanks for every one, Fritz s way just fit my need. 在 2012年3月31日 上午1:12,Benjamin R. Haskell 写道: ... -- You received this
            Message 5 of 7 , Mar 31, 2012
              Thanks for every one, Fritz's way just fit my need.

              在 2012年3月31日 上午1:12,Benjamin R. Haskell <vim@...>写道:
              On Fri, 30 Mar 2012, Unknown wrote:

              Hi everyone here, I'm just new to this mailing list.  I want to automatically disable search highlight when entering insert mode, so I add the command in ~/.vimrc but it didn't work. Does anyone know what I did was wrong?

              As pointed out, :noh[lsearch] doesn't work in autocmds.  One common workaround is to do it from a mapping.  I have the following in my ~/.vimrc:

              " turn off highlighting when refreshing the screen
              nn <silent> <C-l> :noh<CR><C-l>

              (nn = nnoremap)

              Seems like overkill, but you could use:

              for key in ['i','I','o','O','a','A','gi','gI'] " any key that enters insert mode
                     exe 'nn <silent>' key ':noh<CR>'.key
              endfor

              Personally, the <C-l> trick works well for me, because I'm used to typing Ctrl+l to refresh Alpine.

              --
              Best,
              Ben H


              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            Your message has been successfully submitted and would be delivered to recipients shortly.