Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated commands that insert white space at from of line doesn't work #612

Open
hunterSThompson opened this issue Aug 15, 2016 · 9 comments · Fixed by #1663 or #1757
Open

Repeated commands that insert white space at from of line doesn't work #612

hunterSThompson opened this issue Aug 15, 2016 · 9 comments · Fixed by #1663 or #1757

Comments

@hunterSThompson
Copy link

hunterSThompson commented Aug 15, 2016

Run: I\t\t<esc>...

It successfully inserts tabs in the first part (the I\t\t<esc> block), but repeating the command with ... does not successfully append 2 tabs to the front of the line.

@hunterSThompson
Copy link
Author

As a note, running Iblab bla bla<esc>... does work, it seems to only be a problem with whitespace.

This is probably VS trying to automatically adjust the whitespace something.

@johnfn
Copy link
Member

johnfn commented Aug 15, 2016

Even easier than that, I think. :) I'm pretty sure this is because never
registered the tab key in package.json at all. Should be a very simple
change to add it in (and create a corresponding action to insert a tab, but
only in insert mode).

The trick is that you only want to register the tab key when the
autocomplete window is not open, because otherwise we will eat up the
"trigger autocomplete" action. (This actually happened in the past, as I
recall, which is probably why we didn't do it...)

On Mon, Aug 15, 2016 at 5:07 PM, Hunt Graham [email protected]
wrote:

As a note, running Iblab bla bla... does work, it seems to only be a
problem with whitespace.

This is probably VS trying to automatically adjust the whitespace
something.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#612 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAKPQZ-i8XpYmrRvIrAlfGhFbzfnMlDUks5qgJzggaJpZM4JkkTi
.

Grant

@hunterSThompson
Copy link
Author

Aww, so the \t chars aren't being recorded at all!

That explains why Ibla\tbla\tbla<esc>j.j.j. adds "blablabla" not "bla\tbla\tbla" on the 3 lower lines.

Didn't consider the autocomplete thing either...

I assume the "keybindings" section of package.json is where there the binding should go?

@johnfn
Copy link
Member

johnfn commented Aug 16, 2016

Yep, that's correct. :)

@rebornix
Copy link
Member

my 2 cents: I tried to see if I can handle the tab thing with document content change but it didn't work perfectly. Then I take a second look into Vim's behavior. It turns out to be that Vim is handling tab like a specific command, similar to ctrl-a, so that's why documentContentChange can't handle it perfectly.

Hijacking tab from Code in Insert Mode is likely the most correct way to fix this issue but injecting tab into the editor relies on two configs: tabSize and insertAsSpaces, we should be careful with them. Downgrade it to difficulty easy as it's only complex but not difficult, new contributors can handle this with a little bit coaching.

@Chillee
Copy link
Member

Chillee commented May 26, 2017

Unluckily, the fix I added breaks tab completion. I'll need to think about this issue some more.

Chillee added a commit to Chillee/Vim that referenced this issue May 26, 2017
Chillee added a commit to Chillee/Vim that referenced this issue May 26, 2017
Chillee added a commit that referenced this issue May 26, 2017
@Chillee Chillee reopened this May 26, 2017
@Chillee
Copy link
Member

Chillee commented May 26, 2017

This issue is such a pain. VSCode has overloaded tab to do so many things, and the conditions in the keybindings.json file are very complex. Here's a sample:

You have this:

{ "key": "tab",                   "command": "tab",
                                     "when": "editorTextFocus && !editorReadonly && !editorTabMovesFocus" },

for regular tab,
this:

{ "key": "tab",                   "command": "editor.emmet.action.expandAbbreviation",
                                     "when": "config.emmet.triggerExpansionOnTab && editorTextFocus && !config.emmet.suggestExpandedAbbreviation && !editorHasMultipleSelections && !editorHasSelection && !editorReadonly && !editorTabMovesFocus" },

for "emmet" tab completion. Note that this also inserts a tab if it can't find an emmet thing to complete.

And finally:

{ "key": "tab",                   "command": "insertSnippet",
                                     "when": "config.editor.tabCompletion && editorTextFocus && hasSnippetCompletions && !editorTabMovesFocus && !inSnippetMode" },

I'm not sure how to handle all of these from within vscodevim. In addition, I'm not sure how to handle it so we play nice with other extensions / future overloading of the tab key.

@rlc4
Copy link

rlc4 commented Mar 16, 2020

For others that find this issue as I did, hoping that it would be an easy fix (which it appears it's not).

Use spaces at the start of the line instead. This work-around does not work with files that have to have a tab at the start of a line to process properly (I'm looking at you Makefile).

@ndjhartman
Copy link

Using spaces is not quite as good, as if you want to align things on a tab boundary, you don't know how many spaces are required

foo, bar
zoo, bar
to, bar

To

foo,        bar
zoo,        bar
to,         bar

There's no way to align these with a macro using spaces, as far as I know. Hence the desire for tab support.

Comes up fairly often in my work, would be really nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants