On 23/03/10 00:32, John Beckett wrote:
Tinou wrote:
nnoremap<silent>  * :call histadd("search",
expand("<cword>"))<bar>  let @/='\<'.expand("<cword>").'\>'
<bar>  set hlsearch<CR>

Hmmm ... now I'm confused about<expr>.

The help example makes sense:
  :inoremap<expr>  . InsertDot()

But is<expr>  ever needed with nnoremap?

I'm wondering because in this tip:
http://vim.wikia.com/wiki/Highlight_all_search_pattern_matches

we have this method to highlight matches without moving:
  :nnoremap<F8>  :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>

However, it has just been demonstrated that the<C-R>= stuff
is superfluous (I had thought it was necessary if not using
<expr>).

Here is Tinou's mapping tweaked for a little simplification:

" Highlight current word without moving cursor; update history.
:nnoremap<silent>  <F8>  :let @/='\<'.expand("<cword>").'\>'<Bar>set hls<Bar>call 
histadd("search",@/)<CR>

I guess I'll put the above in the tip.

John


The {rhs} of this mapping is a :let statement, which evaluates the expression found after the equal sign.

If you want the _whole_ {rhs} to be the result of evaluating an expression when the mapping is run, for example a (boolean?iftrue:iffalse) conditional expression, or the return value of a function call, then you need the <expr> modifier.

If you just want to evaluate an expression when the mapping is _defined_, you wrap the macro definition in an :exe statement and don't use <expr>.


Best regards,
Tony.
--
Conscience is a mother-in-law whose visit never ends.
                -- H. L. Mencken

--
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

Reply via email to