Integrate the Supertab Plugin for Efficient Tab Completion in Vim
Learn how to integrate the Supertab plugin into Vim in order to allow for tab based autocompletion of commonly used words in a file.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this guide I'm gonna continue talking about some various plug-ins that I find helpful with Vim, and in this one it's called supertab. Now, supertab is another kind of similar to having a auto-complete feature, but not auto-complete in terms of understanding the language. So in other words, supertab's not going to be able to do something like type in a array, and then it's not going to show you all of the various array commands or array methods in Ruby.

Instead what it's going to do is, it's simply going to allow you to auto-complete other items that you have in the file. So if you defined a method, you don't have to type in the full method name. You can simply type out the first few characters, and then you can hit tab and it will auto-complete that for you. That is a type of auto-complete I like inside of Vim. It's nice, lightweight, kind of like we did with Endwise. It's simply another way of being able to make you more efficient.

And I also want to install this slightly differently, 'cause not all of these type of plug-ins give you a really nice, clear set of instructions for how to install them, so I wanted to show you how you could install something manually. So here if you come to supertab, which I'll have in your show notes, if you come here you may notice something kind of interesting, and that is that we don't actually have a true set of instructions.

large

You remember how some of these other ones had instructions like put this in your bundle file, and then clone this. The supertab one doesn't quite give us that, but it's perfectly fine 'cause I want to show you how you can do this manually. If you click on clone or download here, and click on copy to clipboard, now navigate to your .vim/bundle file. You can see if you type in ls that we don't have supertab here yet, and now you can just type in get clone, and paste this in.

git clone https://github.com/ervandew/supertab.git

large

So now that we have that, now we can open up our Vim rc file and navigating all the way down I already have included this, so I have vim/bundle/supertab. So I don't really think you want to watch me copy and paste it over again. Each one of these, if you notice, is completely identical. And so I'm gonna show you in one of the next guides how we can streamline this and not have to have all of this nearly identical code here.

large

So just make sure you have bundle/supertab there included, and now let's open up one of our files. So I'm gonna type in vim and this one's gonna be, let me just create a new one. So this one is going to be new_ruby.rb. I'm gonna create a method, so I'm gonna say def something, we have our nice Endwise end coming up right there. And now we can say hi there.

Now if I navigate to the end, and I'm in insert mode, if I start typing in just the first few characters and type tab, you can see that that completed for me. And it says there below, keyword completion, the only match.

large

So if there would have been multiple items, so if I would have had something and then something else that was something underscore, then that would have given me a few options, and let's actually see what happens if I do that. So I'm gonna say something, and we'll say something method, and it doesn't really matter what we put here. Now let's come down below and I'll start typing in something, just like before. Now if I hit tab, you can see that it gives me a couple different options.

large

So here, I can use the arrow keys and go down or up and pick out which one I want, and if I hit tab then it will give me that completion. So tab and then tab to actually perform the completion. Let's test it out one more time, I'm gonna say if something gives me the same set of options I can use the arrow keys to go up or down, and with this one I want something method. Make sure you hit tab, and then that is going to give you that something method.

large

So that is how you can have some basic auto-complete. Once again, this is not IntelliSense. IntelliSense is a kind of thing that you have in Xcode, or in Visual Studio that will look up the entire library of the programming language and return back the full list of arguments for a specific data type. That is not what's happening right here.

All that's happening is Vim is looking at the specific file we're in, and it's showing the method that is the sets of methods or variables that are available to us and it's simply giving you a little shortcut by being able to hit tab and have auto-complete that way. Like I mentioned before, this is the type of auto-complete I really like; it gives us the ability to create some efficiencies without overloading our system and having too heavy of a IDE.

Resources

-Vim Supertab plugin