On 01/19/12 21:24, Chris Jones wrote:
On Wed, Jan 18, 2012 at 08:42:51PM EST, Tim Chase wrote:
let item = histget(getcmdtype(), -1)
Incidentally, I rather like the ‘cnoremap<expr>...’ syntax and I need
to evaluate it against the ‘cnoremap ....<C-\>eMyFunc()<CR>’ form. In
my case they do the same -- including the fact that the value passed
back by the function overwrites the entire line including what I had
already typed (cf. my earlier reply to Paul) :-(
I'm not sure I follow the "overwriting" bit...it should insert
the text as if you typed it, rather than overwrite anything.
I think my use case is pretty much limited to handling paths (navigating
the file system) and file names (loading& saving buffers), so I think
I'll stick with the basic functionality I initially had in mind.
If this is the case, and you don't have spaces in your filename,
that last regexp ('^.* \(.*\)') could be moved to higher
precidence and it should pull out the last content after a space,
so if you type
:w /path/to/wherever
and then issue
:sp <m-.>
it *should* insert the last thing in the previous command,
leaving you with
:sp /path/to/wherever
But I'll analyze your PreviousTail() function nonetheless, if
only to understand how it works -- especially the fact that
you do no have an initialization routine, which suggests that
you let Vim keep track of where it is pointing in the
history.
the first line, assigning to "item" is where that magic happens.
The histget() allows for negative indexing in the specified
history to get the most recent item:
:help :history-indexing
:help histget()
:help getcmdtype()
For the history name, it exploits the fact that histget() accepts
the value returned from getcmdtype() which tells you which
command-line you're in (forward-search, reverse-search, or
colon-command-line).
The rest of the code is merely attempts to figure out what you
mean by "the last thing" that you want to insert by checking
"item" against the list of patterns and then pulling out the last
non-blank result tagged in that pattern with \(...\) if that
pattern matched.
-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