Categories
Other vi / vim

Vim: Auto Complete


Most of you programming freaks, like the Auto Complete idea of an IDE (using Ctrl+Space) to complete the word. And all the GUI IDE lovers think Vi is just another “Notepad”.

Beware, VIM is noway behind the IDEs, It too supports your Auto-Complete.
Ctrl+P (match previous tokens) or Ctrl+N (match tokens ahead/next) is an alternative to Ctrl+Space

Consider you have following file contents.

RewriteCond %{REQUEST_URI} /somefilepath1/.*
RewriteCond %{REQUEST_URI} /somefilepath2/.*

Now if you want to add another RewriteCond, and you have reached till “Rewri”

All you have to do is press Ctrl+P, Vim will automatically add “teCond” to the string “Rewri”

By ruturajv

developer, traveler...

22 replies on “Vim: Auto Complete”

Perhaps you could try a somewhat more civil answer instead of yelling at the guy who can’t spell: This only works in Vim 7. Jake is probably using an older Vim install.

It´s more ‘auto-remember’ than ‘auto-complete’ since it only seems to recall functions previously used in the same file (I use vim 6.3.82)
But thanks for the tip.

there is more to it.

press control plus “x” and release for a sec, then press lowwercase “L”
and it will autocomple the entire line
(Ctrl-key) + (x) & (l)

also if you press control +”e” the carachters in the line above will be
cloned on your current line.

control + “y” will do the same thing for the line below.
and if its kept press it’ll run coping the line until released

am telling you vim is some serious geek shit!

today I fond out you cand export you current buffer with line numbers and all
to html exactly as it looks in vim.

try the following command

:TOhtml

I love this auto complete feature. But in newer versions of Linux distros some option has been turned on because of which a list of matches pops up every time I hit ctrl-p. It is very distracting. How can I disable it ? I want the auto complete feature without the popup.

Thanks,

-Rahul

“it only seems to recall functions previously used in the same file”

Not true, if you open all your files within vim (very easy from command line) and they are always loaded when ever there is an error or warning while compiling with Make.

e.g.
$ vim source/*{cpp,h}

Also, if you use Ctags, this will keep a reference to all relevant tokens.

$ ctags -R .

Done… 🙂

Rahul, you can map Autocomplete to a different key combination.

BTW, did anyone see this?:

http://vim.wikia.com/wiki/Ctrl-p_-_autocomplete
File completion:
Line completion:
Omni completion:

There much more to this than just token completion…. even line completion … and if using ctags,… it give you a description of the function/etc up top in a preview window.

CTRL-z to close preview :).. that’s the next question, I am sure.

The information is most useful. It is sometimes hard to keep track with all the recalls out there. Your site is another good source that I will add and check from now on for updates. Keep up the hard work.

Leave a Reply