Vim Tips Wiki
m (Auto highlight word under cursor (when reading new code) moved to Auto highlight current word when idle: Page moved by JohnBot to improve title)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=572
 
|id=572
  +
|previous=571
|title=auto highlight word under cursor (when reading new code)
 
  +
|next=573
|created=September 30, 2003 20:32
+
|created=September 30, 2003
 
|complexity=basic
 
|complexity=basic
|author=mosh--AT--cs.albany.edu
+
|author=mosh
 
|version=6.0
 
|version=6.0
 
|rating=23/10
 
|rating=23/10
|text=
 
 
}}
 
}}
 
<pre>
 
<pre>
" Highlight all instances of word under cursor, when idle.
+
" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
+
" Useful when studying strange source code.
" Turn on/off with z/ (or key of your choice)
+
" Turn on/off with z/ (or key of your choice)
 
map z/ :call Auto_Highlight_Toggle()&lt;CR&gt;
   
  +
function! Auto_Highlight_Cword()
:map z/ :call Mosh_Auto_Highlight_Toggle()&lt;CR&gt;
 
 
exe "let @/='\\&lt;".expand("&lt;cword&gt;")."\\&gt;'"
 
endfunction
   
:function! Mosh_Auto_Highlight_Cword()
+
function! Auto_Highlight_Toggle()
 
if exists("#CursorHold#*")
:exe "let @/='\\&lt;".expand("&lt;cword&gt;")."\\&gt;'"
 
 
au! CursorHold *
:endfunction
 
 
let @/=''
 
  +
else
function! Mosh_Auto_Highlight_Toggle()
 
 
set hlsearch
:if exists("&#35;CursorHold&#35;*")
 
 
set updatetime=500
: au! CursorHold *
 
 
au! CursorHold * nested call Auto_Highlight_Cword()
: let @/=''
 
  +
endif
:else
 
 
endfunction
: set hlsearch
 
: set updatetime=500
 
: au! CursorHold * nested call Mosh_Auto_Highlight_Cword()
 
:endif
 
endfunction
 
 
 
" There is cold meat i' the cave; we'll browse on that,
 
" -- GUIDERIUS, in Cymbeline by Shakespeare.
 
 
</pre>
 
</pre>
   
 
==Comments==
No occupation; all men idle, all;
 
 
I would suggest placing the CursorHold event inside an autocommand group (augroup); the way this is right now would clobber my other CursorHold autocommands.
-- GONZALO, Tempest by ShakesPear.
 
 
http://www.cs.albany.edu/~mosh - Mohsin.
 
 
== Comments ==
 
I would suggest placing the CursorHold event inside an autocommand group (augroup); the way this is right now would clobber my other CursorHold autocommands. . .
 
 
Salman Halim
 
, October 1, 2003 6:42
 
<!-- parsed by vimtips.py in 0.477204 seconds-->
 
   
  +
----
 
[[Category:Syntax]]
 
[[Category:Syntax]]

Revision as of 07:29, 4 November 2007

Tip 572 Printable Monobook Previous Next

created September 30, 2003 · complexity basic · author mosh · version 6.0


" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
" Turn on/off with z/ (or key of your choice)
map z/ :call Auto_Highlight_Toggle()<CR>

function! Auto_Highlight_Cword()
  exe "let @/='\\<".expand("<cword>")."\\>'"
endfunction

function! Auto_Highlight_Toggle()
  if exists("#CursorHold#*")
    au! CursorHold *
    let @/=''
  else
    set hlsearch
    set updatetime=500
    au! CursorHold * nested call Auto_Highlight_Cword()
  endif
endfunction

Comments

I would suggest placing the CursorHold event inside an autocommand group (augroup); the way this is right now would clobber my other CursorHold autocommands.