Home Download Buy Blog Forum Support

Autocomplete words/symbols

Autocomplete words/symbols

Postby indiver on Mon Mar 07, 2011 3:25 am

Hi

I have used a bit of TextMate in the past. And one of the things that that I really liked in it in the past (and something that I've missed in other editors) is autocompletion of symbols.

Say for example, I have a piece of Rails code:

Code: Select all
class CommentsController < ApplicationController

  def create
    @post = Post.find(params[:post_id])
    # The exclamation raises an error rather than returning false
    @comment = @post.comments.new(params[:comment])
   
    @comment
   
    if @comment.save
      redirect_to @post
    else
      #render :partial => "/posts/comment_failed", :object => @comment
      flash[:error] = "Unable to add your comments... Make sure you fill in your name, email and some comment."
      redirect_to @post
    end
   
   
  end

end


So, if I wanted to use the @comment symbol, I could simple type @c and press ESC key to cycle through all symbols/words that start with @c in file.

Does Sublime have similar functionality? I know finding words through (Command-p-#) and use autocompletion (ctrl-spacebar/option-ESC) for snippets is possible.

Is there a way for me to emulate the Textmate functionality of typing in the first few letters of a symbol/word, and then hitting a particular key repeatedly to autocomplete the word?

Thanks
indiver
 
Posts: 30
Joined: Fri Mar 04, 2011 5:40 am
Location: Auckland, New Zealand

Re: Autocomplete words/symbols

Postby jps on Mon Mar 07, 2011 3:38 am

Ctrl+Space will complete using words from the current buffer.

If you enabled the tab_completion setting in your user preferences, then tab will complete using words from the current buffer too. I personally find this hugely helpful, but it can be annoying for some people, depending on where you need to insert indentation, so it's off by default.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Autocomplete words/symbols

Postby indiver on Mon Mar 07, 2011 6:03 am

Thanks. That's quite useful. Even though I had enabled, I didn't know I could use it that way.

It works really well.

However I have another question, related to the earlier one.

Suppose, I have two or more symbols in my code that have the same first few letters, e.g., @comment and @commentsUser.

If I type in @co and press tab, it autocompletes to @comment.

However, is there a way to cycle through to the next option? Press tab again will obviously insert a tab after it has autocompleted with @comment.

Also, let me take this opportunity to say that it's been really nice working with Sublime Text. Doesn't happen often that one comes across such a wonderful piece of software. I blogged about it over on my site as well!
indiver
 
Posts: 30
Joined: Fri Mar 04, 2011 5:40 am
Location: Auckland, New Zealand

Re: Autocomplete words/symbols

Postby jps on Mon Mar 07, 2011 8:40 am

There's no way to get to the next option, unless you're use Ctrl+Space to show a menu.

As an option, because tab does use fuzzy matching, you can type in cU and it'll expand it to commentsUser in your example. As an aside, in this specific example you could type in co, and hit tab twice, and you should end up with commentsUser (as comment will complete to commentsUser).

Long term, I'm planning to add a preview of what would happen before pressing tab, but it won't be happening soon.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Autocomplete words/symbols

Postby indiver on Mon Mar 07, 2011 11:00 am

Thanks for that Jon.

Multiple tabs does exactly what I want. It is funny that I had tried that before writing my earlier message and at time I got an autocompletion followed by an actual tab.

But I tried right now, and it worked like a charm.
indiver
 
Posts: 30
Joined: Fri Mar 04, 2011 5:40 am
Location: Auckland, New Zealand


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], subhaze, Yahoo [Bot] and 14 guests