Sublime Forum

Completion in html

#1

I’m seeing an annoying problem with completion in html files. I guess I’m doing something wrong.

Suppose I want an unordered list. I type ul TAB and I get the open and closing html tags and my cursor is between them. That’s great. Now I type li TAB and instead of expanding it simply moves my cursor to after the closing ul. If I now move the cursor back and type TAB it expands the li as I expect.

This is on 2.0.1 build 2217 on Ubuntu.

There must be a better way. Can some Sublime ninja help me out?

Thanks
gb

0 Likes

#2

When you are between

    |
you are at tab-position-one of two, so pressing Tab will jump after the closing ul.

The simplest solution is to press Escape to cancel the tab fields; then Tab (after typing li) will invoke this completion. You will no longer be able to Tab out-of the ul, though.

Alterrnatively, after typing li, press Ctrl-Space to invoke the completions list and use Enter to select the li-completion.

Or you could try tweaking the setting auto_complete_with_fields, and related settings.

Personally, I include the following in my user-settings, which allows me to use Ctrl-Alt-Right (Windows) to use “a completion within a completion”. I can then use Tab to continue with the fields of the first completion. I can also use Ctrl-Alt-Left if I’ve gone past the completion I actually need (when pressing Ctrl-Alt-Right).

[code] { “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “”, “exact”: true} },
{ “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “”, “exact”: false},
“context”:

		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+right"], "command": "replace_completion_with_next_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+left"], "command": "replace_completion_with_prev_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
}[/code]

Alternatively, look into the plugin **ZenCoding ** to use abbreviations.

0 Likes

#3

Another more drastic solution is to ignore completions :smiley: and use **Alt-Dot **(Period .) to close the current tag :laughing:

0 Likes

#4

ZenCoding also adds improved indentation. In this case it allows you to press ul [tab] and then [enter] to create this:

<ul>
	|
</ul>

You can then press li [tab] and it will expand properly. (Of course, once you’re in <li>|</li> you have more or less the same problem as the OP described. ESC is handy here.)

0 Likes