On 2016-02-15, David Woodfall wrote:
Consider the following piece of latex:


ONE: &      Some text here...

TWO: &      Some more text...

THREE: &    More bla bla bla...


I would like to limit the autocomplete word list to contain only the
words on the left of the `&'.

How could this be done?

I don't mind if I have to actually specify the words rather than vim
finding them automatically.

I find the easiest way to use completion is to use "custom" and just
create a function that returns a newline-separated string of
candidate strings.  The MyComplete() function below uses
getbufline() to put all the lines in the current buffer into a list,
then uses map() and matchstr() to replace each line by the word
preceding the '&'.  Any non-matching lines are replaced by empty
lines.  Finally, filter() gets rid of the empty lines and join()
joins the remaining lines into a string, with the lines separated by
newlines.

   function! MyComplete(ArgLead, CmdLine, CursorPos)
       return join(filter(map(getbufline("%", 1, "$"), "matchstr(v:val, '^\\k\\+:\\ze\\s*&')"), 
"v:val!=''"), "\n")
   endfunction
   command! -nargs=1 -complete=custom,MyComplete MyCmd echo "<args>"

Typing ":MyCmd " followed by a <Tab> then results in the following:

   :MyCmd
   ONE:    TWO:    THREE:
   :MyCmd

Modify to suit.

HTH,
Gary

Great, thanks.

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

--- You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to