When using VSCode, most of my files are set to be indented using spaces. However I sometimes wish to insert a literal tab. When I was using vim I'd use <Ctrl>+v <Tab> but that doesn't work with VSCode.
I've been searching and searching and cannot find anything. Please help!
Quick-and-dirty solution: Find a tab somewhere else, then copy-paste.
Chances are that you already have a tab character in the file you are editing, but if not you can generate one in another application or text editor.
You can also generate a tab programmatically in a bash shell with the following command (the brackets are optional):
echo -e [\\t]
For your more immediate needs, I have inserted a tab character below...
There is a tab character between these brackets: [	]
Another approach is to change the tab mode temporarily, as shown here.
I'm not sure if there is a generic solution, but you can setup a keybinding for this:
{
"key": "ctrl+v tab",
"command": "type",
"args": { "text": "\t" },
"when": "editorTextFocus"
}
This keybinding will insert an tab character even when the current mode is spaces.
<Alt> <Numpad: 0 0 9>
Still works great!
Strange, Visual Studio Code gives you a clue, but you have to hunt for it.
Turn off "Editor: Detect Indentation" which is ON by default.
After which, it will not assume that a tab is 4 spaces.
Of course, all you have to do is select your spaces, and then you will see "ghost dots" in your selection. If you delete those spaces and then type tab, you will now see 1 "ghost right arrow" when you select it which means now you really have a tab character.
When working on Makefiles, I use Find/Replace using regexes.
Replace ^ (4 spaces - change as appropriate) with \t.
You can turn off editor.insertSpaces.
Related
In Sublime Text, I have installed Emmet so that I can do zen coding. Now, the problem is that when I'm typing, and get an autocomplete suggestion, as soon as I accept that autocomplete suggestion (either by entering tab, enter, or even pressing space bar), the suggested tag is expanded; this causes me not to be able to continue the zen coding.
To give you an example, say I want to insert a <select> with 6 <option> child elements. If I enter select>opt, then autocomplete suggests option, but as soon as I accept option, that expands to select<option></option>.
What I want is to accept option, but that it won't expand to <option></option>.
Is there anyway to accomplish this?
Actually, the answer is very simple. In your example, when you get the autocomplete suggestions for option, you will get 2 of them. One is the tag, the other is text. Use Ctrl+Space to go through all the suggestions, and select the text version of option and not the tag version.
In Sublime Text completions consists of a 2-tuple containing the showed string and the inserted characters/snippet. I don't think know whether it is possible to just insert the showed string. However if you search for any way, there is a way to establish: modify the source code of the html tag completion file.
Install PackageResourceViewer, then press ctrl+shift+p write PackageResourceViewer: Open Resource. Select HTML >>> html_completions.py.
If you save the file it will shadow (not overwrite) the original completions file. Hence just remove it to get the original behavior.
In this file:
in line 15 replace return (tag + '\tTag', tag + '>$0</' + tag) by return (tag + '\tTag', tag).
in line 245 replace completion_list = [(pair[0], '<' + pair[1]) for pair in completion_list] by completion_list = [(pair[0], pair[1]) for pair in completion_list]
Now it should insert the tag names instead of the whole tags.
What is the equivalent Atom Indent Guides like the one Bracket has showing vertical lines connecting matching beginning/opening and ending/closing brackets or keywords?
Atom supports "Indent Guides" and even names it the same, you can access the configuration by choosing Settings View: Open from the Command Palette
or by pressing Ctrl-, (Control + Comma). Scroll about two-thirds of the way down and there is a checkbox to toggle the Indent Guide on or off:
When enabled they look like this in the editor:
Also found an "improved" package in Atom if Atom's indent-guide isn't cutting it.
https://atom.io/packages/indent-guide-improved
Repo seems to be updated.
UPDATE: show indent guide option is now under Editor tab, in settings.
Screenshot:
Haha. I encountered this issue today too. If I understand your question correctly, you want to know how to enable this feature?
Go to preferences/settings and then scroll down and check 'show indent guide'.
Example
Sublime 2, how to auto close HTML tags and place cursor inside the tag
I'm trying to figure out how to get Sublime 2 to create the following behavior:
Type
<strong
then, upon typing >
Sublime will then immediately print
<strong></strong>
And then your cursor will be placed inside of the tag.
I'm trying to do what's quoted above in Sublime Text 3. A similar question was also asked here but an answer was lacking. Given the time past, I'm asking again. Basically I want to emulate how tags are completed on Codecademy, automatically, i.e. without shortcuts (NO TAB).
Codeacademy example.gif
This works for me. It closes on a backslash, ie your close tag.
For example, you have <div>my div< and upon typing /, you will get <div>my div</div>.
To enable, add the following object to the array in the key binding file (Sublime Text > Preferences > Key Bindings).
{
"keys": ["/"],
"command": "close_tag",
"args": { "insert_slash": true },
"context": [
{
"key": "selector",
"operator": "equal",
"operand": "(text.html, text.xml, meta.jsx.js) - string - comment",
"match_all": true
},
{
"key": "preceding_text",
"operator": "regex_match",
"operand": ".*<$",
"match_all": true
},
{ "key": "setting.auto_close_tags" }
]
}
Not really the answer you want but if you type </ ST3 will auto complete the closest unclosed tag. Otherwise the auto complete answer by Nick is your best bet.
I had the same issue in windows and may people in several forums suggested me to remove and reinstall Sublime 3. But issue not resolved. I don't know the cause of issue. it seems some problem occurred with the packages installed or settings configured. I got resolved the issue in this way by removing installed packages and settings.
In Windows 10
go to C:\Users\ YOUR_USER_NAME \AppData\Roaming\Sublime Text 3
Remove folders and contents from that folder it will resolve this issue.
In Linux
Please reverse the process described in https://packagecontrol.io/installation
There is some issue coursing with this is that all the installed
packages will get removed. You need to reinstall needful packages
again.
So please make sure to note down and reinstall all the plugins needed.
Ok, the best work around for Sublime 3 that I have found is to go ahead and install the SublimeCodeIntel package. I'm not sure if it's an issue with generating popups because the keybindings as given within the package are not working, but what is definitely working is multi lang auto suggest after typing <_ (where _ is whitespace) as well as when you use the auto-suggest the closing tag auto generates.
There's a plugin that will auto-close tags like you describe called Auto Close. It works for both Sublime 2 and 3.
Just be aware that it doesn’t work for JSX, and the package doesn’t appear to be maintained, but it does the job for me so hopefully it might help.
You can install it via Package Control by searching for "Auto Close".
On Sublime Text 3 save any file as .html file.
Then typing something like:
followed by TAB key automatically expand to:
with complete tags of title , body and head.
Heres the official documentation
https://www.sublimetext.com/docs/3/auto_complete.html
Its the same in most IDE's. Aslong as you have the settings enabled (as shown in the document)
it is then: CTRL+Space - to show suggestions
Enter to apply suggestion. (you can change that in the settings)
On Sublime Text 3 save blank new file as .html file.
Then typing something like:
<strong>
followed by TAB key automatically expand to:
<strong> </strong>
with active cursor inside the tag
See the H2 tags? How can I change them all to p tags without manually going from line to line. cmd+d is not viable because of the varying lengths of the inner content.
I found something called Emmet Plugin which I installed but can't get it to work. (Followed steps and confused by docs http://docs.emmet.io/actions/go-to-pair/).
Thanks for the help.
--UPDATE--
Not using a regex. Just to clarify I want something that will automatically update the closing tag if I change the open tag.
You need “Rename Tag” action:
https://github.com/sergeche/emmet-sublime#available-actions
Alt + F3 works for me. I'm using the Emmet plugin, though.
I use Emmet and CTRL+SHIFT+' does not work for me.
I changed the key shortcut of the command.
Preferences -> Key Bindings -> User
Content:
[
{ "keys": ["ctrl+shift+;"], "command": "rename_tag" }
]
Here are some solutions which does not require any plugins.
All solutions works on sublime2, sublime3 and atom
Using Multiple Cursors (press shift-alt and down arrow)
Using Ctrl-D (if you want to restrict the update to some elements only)
Using ALT-F3 (to update all instances of h2 -> p)
PS: For those who does not have the tags in same line, of they do have then all the contents are of different number of lines method 1 will not work both other methods will still work
If you have emmet installed: Cmd+Shift+K on mac, Ctrl+Shift+ on windows
Just use regexp. They are supported by Sublime Text 2 (in the CTRL + H).
I am using MonoDevelop on Mac to write MonoTouch apps. Automatica code indenting/formatting works great while I am typing.
The problem is that when I copy and paste code snippets, in many cases I lose the formatting and lines are combined together, indenting is lost, and it is a huge pain to implement the tabs, spacing, and line breaks manually. Is there anyway I can use a command in monoDevelop to automatically indent and apply the formatting to existing code.
I thought maybe Edit|Format|Format Document/Selection would work, but these commands don't have any affect on the code at all.
Any help?
To format the entire document in one keystroke: control-I
To format a selection: Edit->Format->Format Selection
To customize the formatting: MonoDevelop->Preferences->Source Code->Code Formatting
You actually need to select all your text, and then go to Edit->Format->Format Document. It doesn't seem to work otherwise.
For me on macOS, the shortcut for "auto-format" is CTRL + i.
You can change the shortcut if you want. To change it, go to Preferences -> Key Bindings, then type "format" in the search box and edit the "Format Document" shortcut/key binding.