Sublime Forum

Tab completion weirdness

#1

Hi everyone,
I’m experiencing a weird bug when using tab completion, but only after another tab completion. It’s a bit hard to explain so I recorded a short video of what I’m referring to: smg.photobucket.com/albums/v146/ … etion2.mp4

In the video, you can see that after the first div, I hit return, press “p” and hit tab again. The behavior I’m expecting is that it would give me

, but instead, the cursor jumps to the closing div tag.

Is there a fix to this? Thanks!

0 Likes

#2

viewtopic.php?f=3&t=7224&p=30728&hilit=tabstop#p30728

0 Likes

#3

Thanks, but that didn’t quite work just like that guy said. In my example, I get an actual tab space after where I type “test” instead of the cursor moving in between the two div tags.

0 Likes

#4

Okay. Nevermind. Don’t do that. If you look at the statusbar, it should say field 1/2 . Tabbing to the next field takes precedence, so pressing esc while take you out of the fields. If you want to stay in the fields and let tab go to the next location, use control+space instead for completion. I assumed that you could change it so if tab has an exact match, complete it, otherwise go to next field. I’ll look into it though.

0 Likes

#5

Thanks for the quick response! I’m wondering if there’s a way to say “if Return key pressed, escape out of field”

0 Likes

#6

Ok, I’m getting closer (I think). I added this to my User Key Binding and this command will escape out of the field order, however, I need to hit Enter twice… once to escape, and another time to actually do a Return break

   { "keys": "enter"], "command": "clear_fields", "context":
      
         { "key": "has_next_field", "operator": "equal", "operand": true }
      ]
   },
   { "keys": "enter"], "command": "clear_fields", "context":
      
         { "key": "has_prev_field", "operator": "equal", "operand": true }
      ]
   }
0 Likes

#7

Does anyone know of a way to combine canceling out of the field order and return break in one swoop?

0 Likes

#8

A custom command that does run_command(“command1”) and then run_command(“command2”)?

0 Likes

#9

That sounds like it would work, but unfortunately this might be a little over my head. I’m very new to ST2, and don’t know perl. I’ve read thru the legacy official docs, along with the unofficial docs, and still don’t know where to start. Can someone shed some light on how I would do this?

0 Likes

#10

First of all, Sublime Text uses Python, not perl for its plugins. second, you’ll be better off just making a macro. docs.sublimetext.info/en/latest/ … acros.html

0 Likes

#11

Sorry, I meant to say Python…long day :smiley:

So I finally figured it out. For people interested, here is what I did.

  1. Create new html document
  2. Type out any tag pair that you’re using as a tab completion. For this example, let’s use h1. So type out h1 and hit the tab key
  3. This should result in

    |

    (notice the cursor is between the two tags). You should also see on the bottom left of your window the words “Field 1 of 2”
  4. Click control+q on your keyboard to start recording the marco.
  5. Click ESC on your keyboard to escape out of the field order
  6. Click Return to add a return break
  7. Click control+q to stop recording the macro
  8. Next, we want to save the macro, so select Tools > Save Macro…
  9. Save it under Package/User. For this example, we’ll call it “Enter-Exit-Field.sublime-macro”

Next, we want to bind this macro to the Enter key which will run both keystrokes (esc, and then Enter) in that exact order.

  1. Go to Preferences > Key Bindings - User
  2. Add these lines which will look for the macro that we just saved, and run it
{
    "keys": "enter"],
    "command": "run_macro_file",
    "args": {"file": "Packages/User/Enter-Exit-Field.sublime-macro"}
}
  1. Save
0 Likes

#12

Wow great, now I know about macros, thanks, guys!

Never thought of learning about them, because, hey, I know how to write commands. However, macros do seems to be more lightweight and might have occasional usages. In your opinion, what are those?

0 Likes

#13

One thing I did notice is that this only works for when HTML is selected as a language on the bottom right. Anything else, the Return key fails to do anything. This is what my macro looks like if anyone is interested:

	{
		"args": null,
		"command": "clear_fields"
	},
	{
		"args":
		{
			"action": "insert_formatted_newline",
			"mode": "html"
		},
		"command": "run_zen_action"
	}
]
0 Likes