> On Mon, Jan 23, 2012 at 04:24:52PM EST, Tim Chase wrote:
>> On 01/23/12 14:57, Chris Jones wrote:
>>> On Wed, Jan 18, 2012 at 08:42:51PM EST, Tim Chase wrote:
>
>>>> =================================================
>>>> let item = histget(getcmdtype(), -1)
>>>> =================================================
>
>>> Unless I missed something, I don't think this is going to work,
>>> because you need a variable to keep track of where you are in the
>>> history across Alt+period keyboard actions.. (?)
>
>> I think the answer to your question is the "-1" in the histget() call
>
>> :help history-indexing
>> :help list-index
>
> Ah, yes.. The thing is, I tried your script 'as is' and it did not work
> as I expected.. so I probably jumped to conclusions..
>
> What you are saying makes excellent sense.
>
> On the other hand, I find that managing my own index variable gives me
> more flexiblity/clarity than relying on a side-effect of the histget()
> function.
It's a well documented use of histget()'s second parameter (and
if you come from Python programming, it's downright natural to
use negative indexing). To attempt a whitelist version, you can
give this a whirl:
=============================
function! PreviousTail()
let l:hist=getcmdtype()
let l:max = histnr(l:hist)
let l:idx = 1
let l:of_interest = join([
\'cd',
\'chd\%[ir]',
\'lcd',
\'lcd\%[ir]',
\'tabe\%[dit]',
\'tabnew',
\'sp\%[lit]',
\'e\%[dit]',
\], '\|')
while l:idx < l:max
let l:check = histget(l:hist, -(l:idx))
let l:pairs = matchlist(l:check,
\ '^\s*\(\w\+\)!\=\s\+\(.\+\)'
\ )
if len(l:pairs)
if len(l:pairs[2]) && l:pairs[1] =~ l:of_interest
return l:pairs[2]
endif
endif
let l:idx+=1
endwhile
return ''
endfunction
cnoremap <expr> <m-.> PreviousTail()
===========================
It should handle whatever commands you put in the
"l:of_interest", and since they're regexps, you can use the
\%[...] operator to allow for abbreviated versions and full
versions with minimal fuss.
:help /\%[
-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