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”


22 Responses to “Vim: Auto Complete”

  1. jake Says:

    your comment does not work i tryied it alretty

  2. ruturajv Says:

    it does work, I use it frequently.

  3. myself Says:

    It does work.

    jake you are WRONG

  4. Joey Hewitt Says:

    Sweet, I was not aware of this trick. It does work! πŸ™‚

  5. nobody Says:

    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.

  6. caike Says:

    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.

  7. ruturajv Says:

    In Vim 7, u can ‘auto-complete’, check

  8. Augustin Says:

    It works fine for me!

  9. Juergen Says:

    I think CTRL+B is not correct in Vim7.1 ist CTRL+N

  10. ruturajv Says:

    thanks for ur comment Juergen, you are right, I’ve updated my post as well.

  11. Kazuyoshi Tlacaelel Says:

    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


  12. Steve Says:

    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.


  13. ruturajv Says:

    Hey Steve,
    Thanks a ton, the script is awesome!!!

  14. Rahul Says:

    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.



  15. razzlegames Says:

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

    $ vim source/*{cpp,h}

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

    $ ctags -R .

    Done… πŸ™‚

  16. razzlegames Says:

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

    BTW, did anyone see this?:
    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.

  17. chrelad Says:

    Cool! πŸ˜€ Works for me

  18. sandrar Says:

    Hi! I was surfing and found your blog post… nice! I love your blog. πŸ™‚ Cheers! Sandra. R.

  19. Audun Says:

    Great tip πŸ˜€

    Thanks! (and it works…)

  20. Shonta Gertel Says:

    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.

  21. Ryan Says:

    woohooo, this is a great tip. Thank you!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: