On Wed, Jul 29, 2009 at 3:20 AM, Maxim Kim wrote:
>
>
> On 29 июл, 09:02, Daniel Tripp wrote:
>> Hello all. I have a situation that I can't figure out.
>>
>> Say that I have set a variable like this:
>>
>> :let desiredcolumn=42
>> ...
>> But instead of a constant like 42, I want to take the value from my
>> 'desiredcolumn' variable. Something like this:
>>
>> :map <F2> desiredcolumn<bar>
>>
>> But of course that doesn't work.
>>
>> Any suggestions?
>
> Use cursor() function instead:
>
> :let g:desiredcolumn = 42
> :map <F2> :call cursor(line('.'), g:desiredcolumn)<CR>
Or use an expr map, which lets you build up an expression whose return
is dynamically evaluated whenever you press the LHS of the map to get
the RHS of the map.
:let desiredcolumn=42
:nnoremap <expr> <F2> desiredcolumn . '<bar>'
If you press <F2> the cursor will move to column 42. If you then
change the value of the desiredcolumn variable, it will change the
column that the keypress moves to. Of course, if you don't want that
to happen, you'll want to use
:exe 'nnoremap <F1> ' . desiredcolumn . '<bar>'
~Matt
~Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---