automatic type along completion as in Notepad++?

7 views
Skip to first unread message

Reckoner

unread,
Jul 9, 2008, 11:26:11 AM7/9/08
to vim_use
Notepad++ has a very useful feature where as you type the words you
are typing are constantly being completed from the rest of the words
in the file. I know you can get a similar behavior by typing Ctrl-N in
VIM, but Notepad++ essentially does the same thing without requiring
tabbing or Ctrl-N keystrokes.

Can VIM be configured for this behavior as in Notepad++?

Thanks in advance.

Andreas Politz

unread,
Jul 10, 2008, 4:10:39 AM7/10/08
to vim...@googlegroups.com
I suppose (since I never tried Notepad++) the editor is offering
some possible completion by inserting it into the buffer and
highlighting it as 'automatic inserted'. Then the user has to
type some key to accept the suggestion.

In principle it should be possible to write a script for this in vim,
though I foresee some problems.
1. Doing it the way described above, would imply actual inserting
of contents into the buffer and would have undesirable sideeffects
( like popping up in the undo tree )
2. Using the popupmenu you'll have to hack around it's internal
state-machine
and peculiar triggering mechanism ( probably per feedkeys() )
3. Other ways to make the suggestion to the user include the commandline
and the statusline. This would cause the least problems, but may be
undesirable.

You can simulate 2. with this code :

augroup foo
au!
au CursorMovedI,InsertEnter * if search('\k\{2,}\%#\k\@!','ncb') |
\ call feedkeys("\<c-n>\<c-p>","t") | endif
augroup END

inoremap <expr><cr> pumvisible()?"\<c-n>\<c-y> ":"\<cr>"

Pressing return-key will accept the first match.
Be ready to exit the editor.

-ap

Reckoner

unread,
Jul 10, 2008, 8:31:08 AM7/10/08
to vim_use
Thanks! This works even better than in Notepad++ since this is able to
complete
from more than the current buffer.

David Fishburn

unread,
Jul 10, 2008, 11:09:43 AM7/10/08
to vim...@googlegroups.com
> Thanks! This works even better than in Notepad++ since this is able to
> complete
> from more than the current buffer.

Very nifty ap.

I created a wrapper around this so you can turn it on or off on a per
buffer basis.

I also created a Vim Tip on the wiki for this:

http://vim.wikia.com/wiki/Automatic_type_along_completion_(typeahead)

Problem is, I can't make the tip format correctly.

John, can you help me fix that up?

Dave

Benjamin Fritz

unread,
Jul 10, 2008, 11:28:24 AM7/10/08
to vim...@googlegroups.com

It was an easy fix. In the future, just use <pre> tags instead of the
<code> tags you tried.

I know <code> is probably the "correct" semantic markup, but to get
the desired look on the wiki, use <pre> instead.

Thanks for the contribution!

David Fishburn

unread,
Jul 10, 2008, 11:44:09 AM7/10/08
to vim...@googlegroups.com
> It was an easy fix. In the future, just use <pre> tags instead of the
> <code> tags you tried.
>
> I know <code> is probably the "correct" semantic markup, but to get
> the desired look on the wiki, use <pre> instead.

Thanks Ben.

I noticed you also used the # instead of the 1., 2.
Good tips.

Dave

Tony Mechelynck

unread,
Jul 10, 2008, 1:50:03 PM7/10/08
to vim...@googlegroups.com

Yes, that's wiki markup, as on the Wikipedia:

HTML markup:
<ol>
<li>Line 1</li>
<li>Line 2</li>
<li>Line 3</li>
</ol>

Wiki markup:
# Line 1
# Line 2
# Line 3

Result in both cases:
1. Line 1
2. Line 2
3. Line 3

Use multiple # for additional sublevels; and similarly, * ** etc. for
bulleted lists (at successive levels of nesting), : :: etc. for
successive indents with neither numbers nor bullets.

The Vim wiki uses the same software as the Wikipedia so if you know the
one you can write up articles for the other.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
59. Your wife says communication is important in a marriage...so you buy
another computer and install a second phone line so the two of you can
chat.

John Beckett

unread,
Jul 10, 2008, 5:59:39 PM7/10/08
to vim...@googlegroups.com
David Fishburn wrote:
> Problem is, I can't make the tip format correctly.

Ben beat me...

But I will take this opportunity to whinge to you and Sightless. When you logged on
at the wiki, did you see an annoying bar at the top which said you had new messages?
I guess we are all trained to NOT "click here to claim your prize", so perhaps
people are ignoring it.

If there is no such "you have new messages" bar, you should be able to find a "my
talk" link next to your log-in name, which is at the top of the screen, on the right
(in the monobook skin that I have chosen in "my preferences").

Anyway, on your talk page is a message. Among other things it suggests that you
create your user page. I'm just telling you all this so I know that you have seen
it. Thanks for the new tip!

John

Andreas Politz

unread,
Jul 10, 2008, 9:38:01 PM7/10/08
to vim...@googlegroups.com

Please don't advertise this as a working solution, because it is not.

-ap

McCaskey, Todd

unread,
Jul 11, 2008, 2:34:51 AM7/11/08
to vim...@googlegroups.com
Why cant this be uses as a "working solution"?

-T

Ben Schmidt

unread,
Jul 11, 2008, 10:52:50 AM7/11/08
to vim...@googlegroups.com
> But I will take this opportunity to whinge to you and Sightless. When you logged on
> at the wiki, did you see an annoying bar at the top which said you had new messages?
> I guess we are all trained to NOT "click here to claim your prize", so perhaps
> people are ignoring it.

I did see it a few weeks ago, and I did read it, and I considered making
a user page, but when I looked at the sort of things to put on it, I
couldn't really think of anything I wanted to put on one of my own, so I
didn't. I did appreciate the message, though. Thanks, John.

Cheers,

Ben.


Reckoner

unread,
Jul 11, 2008, 3:04:39 PM7/11/08
to vim_use


I tried your script, but it does not appear to activate the typealong
toggle as advertised. I am running it on vim 7.1 on winXP.

Thanks for the effort.

Andreas Politz

unread,
Jul 11, 2008, 7:07:02 PM7/11/08
to vim...@googlegroups.com
McCaskey, Todd wrote:
> Why cant this be uses as a "working solution"?
>
> -T
>
>
Ok, it does work. But it loops endlessly, in case it does not find a
completion,
the space is taken fairly arbitrarily to get rid of the popup menu and there
may be other problems.

Someone posted a link (on the wiki) to a script on vim.org, maybe that is
already a good, "working" solution.

-ap

John Beckett

unread,
Jul 11, 2008, 8:35:58 PM7/11/08
to vim...@googlegroups.com
Ben Schmidt wrote:
> I did see it a few weeks ago, and I did read it, and I
> considered making a user page, but when I looked at the sort
> of things to put on it, I couldn't really think of anything I
> wanted to put on one of my own, so I didn't.

Fair enough. I imagine that most people on a list like this are not used to putting
a "look at me" page on the web. However, I would encourage people to think about
making at least a very simple page, something like this:

---begin---
I've been using Vim for years, mostly for C programming.
---end---

The benefit of such a page, despite saying essentially nothing, is that it indicates
that the editor has worked out how to make their user page (and doesn't need help to
do it), and it suggests that the editor will read a message on their talk page (or
at least, the editor would know how to read their talk page!). Such talk is pretty
rare, but it can be useful to contact someone with a comment. You don't need a user
page for that to work, but the poster is filled with doubt regarding whether the
user would even notice such a comment. Also, if we have lots of user pages, other
people may be encouraged to join in.

If an editor gets really helpful and joins in a discussion (e.g. at the New Tips
page), the editor should finish their comment with "~~~~" for a signature consisting
of username/date. The signature contains a link to the user's page, and that link is
red if the page does not exist. Red links are a bit unsettling for the sensitive
among us.

You can browse the following to see active users (this is cached, and can sometimes
fail to show a user who has been active for a few weeks; the list is updated when
the Wikia server gets around to it):
http://vim.wikia.com/wiki/Special:Listusers

John

Reckoner

unread,
Jul 12, 2008, 10:32:39 PM7/12/08
to vim_use
here is the link in question:

http://www.vim.org/scripts/script.php?script_id=1879

Evidently, this has already been solved before. I tried it. Works
great.
Reply all
Reply to author
Forward
0 new messages