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”
22 replies on “Vim: Auto Complete”
your comment does not work i tryied it alretty
it does work, I use it frequently.
It does work.
jake you are WRONG
Sweet, I was not aware of this trick. It does work! 🙂
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.
Actually, in VIM 7, it is an auto-complete.
In Vim 7, u can ‘auto-complete’, check
https://ruturajv.wordpress.com/2006/12/21/vim-7-autocomplete/
It works fine for me!
I think CTRL+B is not correct in Vim7.1 ist CTRL+N
thanks for ur comment Juergen, you are right, I’ve updated my post as well.
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
Thanks for the menu color setting, that pink has been driving me crazy! I use the autocomplpop.vim to automatically pop up the omni complete options, seems to work well.
Thanks,
Steve
Hey Steve,
Thanks a ton, the http://www.vim.org/scripts/script.php?script_id=1879 script is awesome!!!
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.
Cool! 😀 Works for me
Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.
Great tip 😀
Thanks! (and it works…)
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.
woohooo, this is a great tip. Thank you!!