Hello Paul, Sorry for delay.. I didn't have the time to look into this further.
On Wed, Jan 18, 2012 at 03:12:18AM EST, Paul Isambert wrote: > Chris Jones <[email protected]> a écrit: > > At the bash prompt, I often use the [Alt+.] keyboard action to > > retrieve the argument of a prior command from the bash history list. [..] > > Is there any way I could do this in Vim's ex-mode? > > This might be an overkill, and perhaps dangerous, but it seems to > work: > > let s:CmdHistory = [] > let s:CmdCount = -1 > function! ResetCmd() > let s:CmdCount = len(s:CmdHistory) - 1 > return "" > endfunction > > function! StoreCmd() > let cmd = matchstr(getcmdline(), '\s.\+') > call add(s:CmdHistory, cmd) > let s:CmdCount = len(s:CmdHistory) - 1 > return getcmdline() > endfunction > > function! GetCmd() > if s:CmdCount >= 0 > let cmd = matchstr(getcmdline(), '^\S*') . s:CmdHistory[s:CmdCount] > let s:CmdCount = s:CmdCount - 1 > return cmd > else > return getcmdline() > endif > endfunction > > cnoremap <buffer> <CR> <C-\>eStoreCmd()<CR><CR> > cnoremap <buffer> <Esc> <C-\>eResetCmd()<CR><Esc> > cnoremap <buffer> <A-.> <C-\>eGetCmd()<CR> That's _very_ useful, especially the mappings. I was not even aware of the existence of ‘<C-\>e’ function mappings and it would have taken me ages to find that. Thank you very much for going to all that trouble...! I tried to simplify a bit and make the behavior as bash-alike as I could. I came up with this: | let g:indx=histnr("cmd") | | function! GetArg() | let g:indx -= 1 | let s:cmdl = split(histget("cmd", g:indx)) | let g:arg = s:cmdl[len(s:cmdl)-1] | return g:arg | endfunction | | function! InitIndex() | let g:indx=histnr("cmd") | return "" | endfunction | cnoremap <M-.> <C-E><C-\>eGetArg()<CR> | nnoremap : :<C-\>eInitIndex()<CR> The main difference with your solution is that I directly access the Vim command history via histnr() & histget() rather than maintaining my own list of commands. My effort basically works, except that when I hit ‘Alt+.’, whatever I started to type on the Ex command-line gets overwritten instead of being echoed at the current cursor position: | :cd [Alt+.] should for instance give me: | :cd /home/user/.vim but it gives me (e.g.): | :/home/user/.vim I first have to verify that this is not caused by something in my Vim setup. 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
