|
|
| Line 1: |
Line 1: |
| − |
|
|
| |
{{TipImported |
|
{{TipImported |
| |
|id=895 |
|
|id=895 |
| |
|previous=894 |
|
|previous=894 |
| |
|next=896 |
|
|next=896 |
| − |
|created=March 14, 2005 |
+ |
|created=2005 |
| |
|complexity=advanced |
|
|complexity=advanced |
| |
|author=Charles E. Campbell, Jr. |
|
|author=Charles E. Campbell, Jr. |
| Line 44: |
Line 43: |
| |
</pre> |
|
</pre> |
| |
|
|
|
| − |
<tt>\aa</tt> : Using a map to call TestOne(). When no count (ie. 5\aa) is provided, the only thing interesting is that firstline and lastline are equal to the current line. |
+ |
<code>\aa</code> : Using a map to call TestOne(). When no count (ie. 5\aa) is provided, the only thing interesting is that firstline and lastline are equal to the current line. |
| |
|
|
|
| − |
<tt>5\aa</tt> : Like <tt>\aa</tt>, but this time <tt>lastline= firstline+5-1</tt>. Thus one can pass a repetition count of sorts to the map. However, one will get an "Invalid range" error within four lines of the end-of-file. |
+ |
<code>5\aa</code> : Like <code>\aa</code>, but this time <code>lastline= firstline+5-1</code>. Thus one can pass a repetition count of sorts to the map. However, one will get an "Invalid range" error within four lines of the end-of-file. |
| |
|
|
|
| − |
<tt>\bb</tt> : How to pass the optional "!" to a function. Useful for having an alternate behavior associated with a function. |
+ |
<code>\bb</code> : How to pass the optional "!" to a function. Useful for having an alternate behavior associated with a function. |
| |
|
|
|
| − |
<tt>\cc</tt> : Illustrates the use of <reg> -- note that the first argument |
+ |
<code>\cc</code> : Illustrates the use of <reg> -- note that the first argument |
| |
|
|
|
| − |
<tt>\dd</tt> : is made available by the <reg>, and is elided from the arguments. The |
+ |
<code>\dd</code> : is made available by the <reg>, and is elided from the arguments. The |
| |
|
|
|
| − |
<tt>\ee</tt> : <tt>\ee</tt> map shows how arguments are still available. |
+ |
<code>\ee</code> : <code>\ee</code> map shows how arguments are still available. |
| |
|
|
|
| − |
<tt>\ff</tt> : Shows how to pass a fixed range to a function. Here the <tt><line1>,<line2></tt> construct is being illustrated |
+ |
<code>\ff</code> : Shows how to pass a fixed range to a function. Here the <code><line1>,<line2></code> construct is being illustrated |
| |
|
|
|
| − |
<tt>\gg</tt> : Illustrates the use of <count>. |
+ |
<code>\gg</code> : Illustrates the use of <count>. |
| |
|
|
|
| |
==Comments== |
|
==Comments== |
This tip concerns the interplay between commands, maps, and functions. Please consider the following test script...
To run the script, you'll need Decho.vim and cecutil.vim
This tip is aimed for those who wish to write scripts in vimL
fun! TestOne(reg,bang,args) range
call Dfunc("TestOne(reg<".a:reg.">,bang=".a:bang." q-args=".a:args.") firstline=".a:firstline." lastline=".a:lastline)
call Dret("TestOne")
endfun
fun! TestTwo(reg,bang,qty,args)
call Dfunc("TestTwo(reg<".a:reg.">,bang=".a:bang." qty=".a:qty." q-args=".a:args.")")
call Dret("TestTwo")
endfun
" this is a test range
" this is a test range
" this is a test range
" this is a test range
com! -range -register -bang TestOne <line1>,<line2>call TestOne("<reg>",<bang>0,<q-args>)
com! -count=1 -register -bang TestTwo call TestTwo("<reg>",<bang>0,<count>,<q-args>)
nnoremap \aa :TestOne<CR>
nnoremap \bb :TestOne!<CR>
nnoremap \cc :TestOne a<CR>
nnoremap \dd :TestOne! a<CR>
nnoremap \ee :TestOne! a "abc" "def"<CR>
nnoremap \ff :10,13TestOne<CR>
nnoremap \gg :TestTwo 3<CR>
\aa : Using a map to call TestOne(). When no count (ie. 5\aa) is provided, the only thing interesting is that firstline and lastline are equal to the current line.
5\aa : Like \aa, but this time lastline= firstline+5-1. Thus one can pass a repetition count of sorts to the map. However, one will get an "Invalid range" error within four lines of the end-of-file.
\bb : How to pass the optional "!" to a function. Useful for having an alternate behavior associated with a function.
\cc : Illustrates the use of <reg> -- note that the first argument
\dd : is made available by the <reg>, and is elided from the arguments. The
\ee : \ee map shows how arguments are still available.
\ff : Shows how to pass a fixed range to a function. Here the <line1>,<line2> construct is being illustrated
\gg : Illustrates the use of <count>.