In a js file, I can type comm and autocomplete will kick in prompting me for comment blocks. This functionality doesn't work in CSS files.
I thought this would be the answer for me but it is not.
"auto_complete_selector": "source, text"
This post also looked promising, but it was not either.
Sublime Text 2 code snippet not working in proper scope
Anyone know of a way to add it or to turn it on for CSS?
You need to add a snippet that whos scope has CSS files included. Example:
<snippet>
<content><![CDATA[
/* ----------------------------------------------------------------------------
* ${1:CSS Section}
* ------------------------------------------------------------------------- */
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>comm</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.css</scope>
</snippet>
Save this file with the .sublime-snippet extension in your User packages folder (Sublime Text -> Preferences -> Browse Packages) and you will be good to go.
In a CSS file, you would then type "comm" and hit tab.
NOTE: The folder location I mention above is for Mac users FYI
Related
I'm looking into creating something like a macro for localization of strings. Until now, I have only find that (maybe) a custom Code Action might be what I need.
After I select some code, let's call it selection, I want the to:
Ask me for a name
Write to another file: name = selection
Write in current file: (some_fixed_code)name(some_other_fixed_code)
Is there any way to create that macro, for it lo launch with a left click option or a keyboard shortcut?
Thanks in advance!
I'm having an issue with the auto comments in my .scss files. By auto comments I mean 'CTRL + /' to comment out the selected code. When I'm in my scss file and I do this, it adds the JS comments '//'. So the output looks like this:
body {
font-size: 1rem;
line-height: 1.4;
// overflow-x: hidden;
}
When it should be:
body {
font-size: 1rem;
line-height: 1.4;
/* overflow-x: hidden; */
}
If I rename the .scss file to .css then the auto comments work correctly. I'm guessing this has to do with a setting inside of VSCode, either user or workspace setting?
I believe this is working as expected, as SCSS supports both ways to comment, and I do not think there are any settings in Visual Studio Code you can change to change how the comment style works.
Ctrl + / is "Toggle Line Comment", which is the // way. If you want to comment using the multi-line comment format, you can instead highlight what it is you want to comment, and perform Shift + Alt + A.
However, there is another way to change how the Line Comments work:
Find where Visual Studio Code is installed on your system, and go to resources → app → extensions → scss
In the scss folder should be a "language-configurations.json" file. Open it.
Change the lineComment property to be either a blank string, or delete it outright.
"lineComment": ""
Save the file, and restart Visual Studio Code. Now when you perform Ctrl + /, it should comment using the style you prefer.
Please see the comments to #Timothy's answer. I have previously written an extension to deal with these issues, Custom Language Properties, that allows you to easily change things like line or block comments for many languages.
But setting lineComment to the OP's desired ["/*","*/"] did not work. In looking at the scss language configuration file, an array of values is not allowed for line comment values. But it works to delete the lineComment key or setting it to the empty string "".
However, although probably rare, any language configuration file can be overwritten whenever vscode updates and you would have to go back and change the file again. Hence the extension.
With this setting:
"custom-language-properties": {
"scss.comments.lineComment": ""
}
this accomplishes the same thing as editing the underlying language-configuration file. And fortunately, at least in this case, apparently vscode will apply the blockComment value when the lineComment value is missing or inappropriate. And fortunately that blockCcomment style is what the OP wanted.
That is valid comment syntax for SCSS, and it's probably the correct default.
Single-line comments (which start with //) are always removed from the compiled output, which is usually what you want.
Multi-line comments (/* comment */) are only removed in compressed mode.
Source: Sass: Comments
Is there any path-autocompletion extension for Markdown in VSCode?
I tried Path Intellisense but this seems to be effective only when using (double) quotation.
I want to use autocompletion when insert images stored in local directory, e.g.:
![](./img/local-img-file.png)
Yes, you can make that happen by using this extension on VS Code.
Relative Path extension
Juste type ctrl (or cmd on mac) + shift + H and type your file name.
It should be built-in to vscode soon, hopefully v1.64.
New setting: markdown.suggest.paths.enabled default is true
from Commit: Add basic markdown link completions
Only normal links for now. Will add reference links later. Should
support the forms:
[](dir/file.md)
[](./dir/file.md)
[](/root-dir/file.md)
[](#header)
[](./dir/file.md#header)
The paths suggestions work similarly to path IntelliSense in CSS and
HTML files. Paths starting with / are resolved relative to the current
workspace, while paths staring with ./ or without any prefix are
resolved relative to the current file. Path suggestions are
automatically shown when you type / or can be manually invoked by
using kb(editor.action.triggerSuggest).
Path IntelliSense can also help you link to headers within the current
file or within another Markdown file. Start the path with # to see
completions for all the headers in the file (depending on your
settings, you may need to use kb(editor.action.triggerSuggest) to see
these)
-from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_64.md#markdown-path-intellisense
For anyone else stumbling upon this answer, the Markdown All in One extension is able to perform this sort of autocomplete.
With sublime text 3, the autocomplete when typing "for" and hitting tab gives you:
for x in xrange(1,10):
pass
However, this is not a valid statement for python 3. I've tried creating a new build system using the following:
{
"cmd": ["c:/Python37/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
the auto-complete for for still gives the wrong syntax. any advice?
The short version is that the sublime-build and sublime-snippet files that ship with Sublime in support of Python target Python version 2 and not Python version 3. I don't know if that's just due to that being what was used initially or if it's being done on purpose, though.
In Sublime, resources are generally related to a particular language based on the scope provided by the syntax definition. So for example snippets for Python are associated with source.python, your example build file uses that scope to know that it applies to Python files, and so on. As such, no matter what build you happen to be using, that has no effect on the snippets that are being offered.
By way of example, if you use the View Package File command from the command palette and enter the text python for snippet, the list of package resources will filter to Python/Snippets/for.sublime-snippet; pressing Enter to view that resource shows this:
<snippet>
<tabTrigger>for</tabTrigger>
<scope>source.python</scope>
<description>For Loop</description>
<content><![CDATA[
for ${1:x} in ${2:xrange(1,10)}:
${0:pass}
]]></content>
</snippet>
Here the tabTrigger specifies how the snippet inserts, scope controls where it inserts and content controls what it is inserts. Thus, in order to change it to support Python 3, you need to either create your own snippet or modify the existing one.
An issue with creating your own snippet is that it will be added to the list of snippets including the offending one, which allows it to possibly still trigger when you don't expect it to. There is also no general purposes "easy" way to disable individual snippets.
As such, generally the best course of action would be to use the PackageResourceViewer package. Install it, select PackageResourceViewer: Open Resource from the command palette, then select the same file as outlined above and modify the content of the snippet (e.g. replace xrange with range) and save the file.
That will get Sublime to replace the existing snippet with your edited version, so that it takes the place of the existing one and works the way you want.
When you press Ctrl+p Sublime will open popup when you can easily find the file. Sublime auto detect the file location in both situation when you press / or space between file path parts.
In Zend Framework all classes has name within follow template: Namespace_Module_Other_Part_Of_Class_Location, how can I make Sublime understand the _ as a path separator when I press Ctrl+p and copy past the class name there?
So the above class should be recognized on location: Project/Namespace/Module/Other/Part/Of/Class/Location.php
I'm still looking for the solution of it. Even if the file search is hard-coded in Sublime 3, and you have a workaround to make it works, maybe to write some plugin? you are welcome.
Thank you.
You can do this with a simple plugin and key binding. Select Tools -> New Plugin... and replace the contents with the following:
import sublime
import sublime_plugin
class UnderscoreToSpaceCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('copy')
clipboard = sublime.get_clipboard()
clipboard = clipboard.replace('_', ' ')
sublime.set_clipboard(clipboard)
Save the file as Packages/User/underscore_to_space.py where Packages is the folder opened when clicking on Preferences -> Browse Packages....
Next, create a custom key binding for the command. Select Preferences -> Key Bindings-User and add the following:
{ "keys": ["ctrl+shift+c"], "command": "underscore_to_space" }
If the file is empty when you open it, surround the above line with square brackets [ ]. Save the file (it will automatically save to the correct location), and you're all set.
Now, all you need to do is select the text you want to convert, and hit CtrlShiftC. This will copy the text to the clipboard, replace the underscores with spaces, and put the modified text back in the clipboard. You can now hit CtrlP to open Goto Anything... and paste in the modified text with CtrlV.
If you prefer to have the underscores replaces with forward slashes /, just change the clipboard.replace() arguments from ('_', ' ') to ('_', '/').
To get to the class definition you are looking for there exist several plugins doing "code intelligence". The plugins are language specific.
The most popular is SublimeCodeIntel which provides Jump to symbol definition functionality. SublimeCodeIntel claims to do this for PHP too. However, who to setup this for your project should be another question.
Some more options for possible source code static analysis in Sublime Text 2 in this blog post: