Sunday, June 20, 2010

Re: search for output of shell command

Hi,

inline,

> For your particular use-case, I'd use vim's internal strftime() function:
>
>  :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 don't mention what single-digit dates look like in your file (whether
> they are left-justified, or padded with spaces or a leading zero).
This is the matching pattern ^20$

>  So you
> might have to use "%e" (pad with spaces) instead of "%d" (pad with a zero)
> or strip the unwanted stuff:
%d works perfect

>
> :nnoremap <f4> /^<c-r>=substitute(strftime('%d'), '^0*', '',
> '')<cr><bslash>><cr>
>
> :cnoremap <f4><c-r>=substitute(strftime('%d'), '^0*', '', '')<cr>
>
> ==========================
>
> For your more general case, I'd use vim's system() function to call an
> external program or chain and return the output such as:
>
>   system("date | awk '{print $3}'")
>
> however, that returns the trailing newline, so you'd have to clean that out:
>
> substitute(system("date | awk '{print $3}'"), '\D', '', 'g')
>
>
I get: E486: Pattern not found: system

Thanks,
Yosi

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