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
    https://ruturajv.wordpress.com/2006/12/21/vim-7-autocomplete/

  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

    :TOhtml

  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.

    Thanks,
    Steve

  13. ruturajv Says:

    Hey Steve,
    Thanks a ton, the http://www.vim.org/scripts/script.php?script_id=1879 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.

    Thanks,

    -Rahul

  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.

    e.g.
    $ 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?:

    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.

  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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: