On Thu, Jan 19, 2012 at 10:37:46PM EST, Tim Chase wrote:
> On 01/19/12 21:24, Chris Jones wrote:

I eventually used a mix of Paul and Tim's suggestions and came up with
this:

| " ========================================================================
| " Emulate bash/readline's yank-last-arg on the command-line
| "
| " see ~/.vimrc for mappings:
| "
| " cnoremap  <expr>  <Esc>.  GetArg0()
| " nnoremap  :       :<C-\>eInitIndex0()<CR>
| "
| " ========================================================================
| 
| " list of ‘interesting’ commands
| let g:cmdlist = ['cd',
|       \          'lcd',
|       \          'tabe',
|       \          'vne']
| 
| function! GetArg()
| 
| " wrap to beginning of history
|   if histget("cmd", g:indx) == ""
|     g:indx = histnr("cmd") - 1
|   endif
| 
| " loop until interesting command is found
|   while 1 == 1
|     let g:indx -= 1
|     let g:cmdl  = split(histget("cmd", g:indx))
| 
| " skip commands with no argument
|     if len(g:cmdl) < 2
|       continue
|     endif
| 
| " skip useless commands
|     if match(g:cmdlist, g:cmdl[0]) == -1
|       continue
|     endif
| 
| " now grab argument..
|     let g:arg   = g:cmdl[-1]
| 
| " and return it concatenated to user's current command
|     return ' '.matchstr(getcmdline(), '^\S*').' '.g:arg
|   endwhile
| 
| endfunction
| 
| function! InitIndex()
| 
| " set pointer to most recent entry in the history
|   let g:indx=histnr("cmd") - 1
|   
|   return ""
| 
| endfunction

All nicely commented, in case I forget what this was all about.. :-)

Added a ‘while loop’ to speed up things a bit by skipping irrelevant
commands/arguments so it pretty much behaves along the lines of what
I orginally had in mind.

Thanks to both for help.

CJ

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

Reply via email to