> more inline
Just FYI, that's the expectation on the list, so no need to note it.
>>>> :nnoremap<f4> /^<c-r>=strftime('%d')<cr><bslash>><cr>
>>>> :cnoremap<f4> <c-r>=strftime('%d')<cr>
>>>
>>> This works well. Can you please kindly explain why the 2nd line?
>>
>> You can see that it's just a subset of the previous command, the part that
>> inserts the current day-of-the-month into the current search or the
>> command-line.
>
> I can see that. I don't understand what it's good for.
It's good in case you need to pull the current day into an
existing search or command-line. So if you wanted to write to a
file named "xyz<today>.txt", you could type
:w xyz<f4>.txt
which (today) would insert "20", making the command
:w xyz20.txt
Same for searches:
/Today is the <f4>
would make your search text
/Today is the 20
(since it doesn't front-load another <cr>, you're able to
continue editing, such as adding "th day of June" to make the
final search "Today is the 20th day of June"). This is useful if
you occasionally need to insert the day-of-month into your search
or a command, but you're lazy like me and don't want to look it
up. :)
> Sorry for not giving a clear explanation. for 1-9 I need to search for ^1 to ^9.
Then you'd likely want the variant I sent in the original email:
nnoremap <f4> /^<c-r>=substitute(strftime('%d'), '^0*', '',
'')<cr><bslash>><cr>
Which strips off the leading-zeros.
> Given that, I take it I need to change that %d in your maps to %e. right?
The "%e" would search for "^ 8" (with an extra space).
>>> I get: E486: Pattern not found: system
>>
>> These are expressions, and as such need to be entered with the "control+R
>> followed by =" expression register:
>>
>> :help @=
>
> got you. so now I tried:
> let @/ = substitute(system("date | awk '{print $3}'"), '\D', '', 'g')
> and n it searches for plain 20. how can I make it search for
> ^20\>. What is the string. concatenation operator?
I usually use "." as the string-concatenation operator (I think
in many contexts, you can just abut them without an operator, but
I prefer to be explicit about it) You can either return the
string from the expression with
:let @/ = '^' . substitute(...) . '\>'
(you may have to escape the "\" before the ">" with an extra
"\"...YMMV). Alternatively, you can use the mapping to just
insert the date, and so you'd search for
/^<f4>\>
typing the "^" and the "\>" portions around the stuff you bring
in from the expression-register.
> And BTW, why doesn't VIM use python as scripting language :-)
Well, it's available as an add-on build option. Check your output of
:version
to see if it was built with "+python".
:help +python
:help if_pyth.txt
Even as a python developer for my core programming job and active
on comp.lang.python, I tend to stick with Vim-script for vim
automation because I know it should run on just about all
versions of Vim. The mental impedance caused by jumping between
vim-script and python tends to be more than I want to think
about, so I keep them pretty separate. But it's available if you
want it :)
> I need something like:
> let @/ = '^' + substitute(system("date | awk '{print $3}'"), '\D', '',
> 'g') + '\>'
Try "." as your concat operator (optionally escaping the "\"...I
hate trying to sift out the various times escaping is/isn't needed).
> Thank you for all your help so far!
Glad to help -- the list is a pretty friendly place
-tim
--
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
No comments:
Post a Comment