comparison runtime/doc/tips.txt @ 674:4b8583e82cb8 v7.0201

updated for version 7.0201
author vimboss
date Sat, 18 Feb 2006 22:14:51 +0000
parents 83a006f81bac
children 2af8de31a3a8
comparison
equal deleted inserted replaced
673:513866ffe6af 674:4b8583e82cb8
1 *tips.txt* For Vim version 7.0aa. Last change: 2006 Feb 16 1 *tips.txt* For Vim version 7.0aa. Last change: 2006 Feb 18
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
448 Highlighting matching parens *match-parens* 448 Highlighting matching parens *match-parens*
449 449
450 This example shows the use of a few advanced tricks: 450 This example shows the use of a few advanced tricks:
451 - using the |CursorMoved| autocommand event 451 - using the |CursorMoved| autocommand event
452 - using |searchpairpos()| to find a matching paren 452 - using |searchpairpos()| to find a matching paren
453 - using |synID()| to detect whether the cursor is in a string or comment
453 - using |:match| to highlight something 454 - using |:match| to highlight something
454 - using a |pattern| to match a specific position in the file. 455 - using a |pattern| to match a specific position in the file.
455 456
456 This should be put in a Vim script file, since it uses script-local variables. 457 This should be put in a Vim script file, since it uses script-local variables.
457 Note that it doesn't recognize strings or comments in the text. 458 It skips matches in strings or comments, unless the cursor started in string
459 or comment. This requires syntax highlighting.
458 > 460 >
459 let s:paren_hl_on = 0 461 let s:paren_hl_on = 0
460 function s:Highlight_Matching_Paren() 462 function s:Highlight_Matching_Paren()
461 if s:paren_hl_on 463 if s:paren_hl_on
462 match none 464 match none
482 endif 484 endif
483 if c == '[' 485 if c == '['
484 let c = '\[' 486 let c = '\['
485 let c2 = '\]' 487 let c2 = '\]'
486 endif 488 endif
487 489 let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' .
488 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags) 490 \ '=~? "string\\|comment"'
491 execute 'if' s_skip '| let s_skip = 0 | endif'
492
493 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip)
489 494
490 if m_lnum > 0 && m_lnum >= line('w0') && m_lnum <= line('w$') 495 if m_lnum > 0 && m_lnum >= line('w0') && m_lnum <= line('w$')
491 exe 'match Search /\(\%' . c_lnum . 'l\%' . c_col . 496 exe 'match Search /\(\%' . c_lnum . 'l\%' . c_col .
492 \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/' 497 \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
493 let s:paren_hl_on = 1 498 let s:paren_hl_on = 1