sublime text : open containing folder - editor

I'm working on some file in my sublime text 2 editor, and I want to open a folder in which that file resides.
I know there is a 2 step procedure to do this already
step 1: right click and reveal in sidebar (ctrl+shift+r)
step 2: right click on the same file in sidebar and click open containing folder.
I would like to know if there is only one shortcut key to do the same. This is something that I use quite often.

You can add the line below to your Default (Windows).sublime-keymap:
{ "keys": ["ctrl+alt+e"], "command": "open_dir",
"args": {"dir": "$file_path", "file": "$file_name"} }

By default the editor has this item in context menu. If you need this feature on tabs you have to create a file with name "Tab Context.sublime-menu" in "\Data\Packages\User\" (if does not exist yet) and add this code:
[
{
"caption": "-"
},
{
"command": "open_dir",
"args": {"dir": "$file_path", "file": "$file_name"},
"caption": "Open Containing Folder…"
}
]
Do not forget formatting lines as a JSON file! If you do not need a separator before this menu item you need to delete first block with caption "-"! You can add any other menu in this file. For example:
{
"command": "copy_path",
"caption": "Copy File Path"
},

Install Open project path by shortcut. Then setup keybindings in your User keymap file
{
"keys": ["f10"],
"command": "open_project_folder"
},
{
"keys": ["ctrl+f10"],
"command": "open_file_folder"
}
Initiate the key bindings on a open file (f10 to open the directory you have set as the project folder, ctrl+f10 to open the folder of the current file.)

This worked for me: assuming you have opened the file whose enclosing folder you want to open, use the Menu > Project > Add Folder To Project command.
A new window should open with the enclosing folder. Just click 'Open' and you're done!

I found this plugin: https://github.com/kallepersson/Sublime-Finder
The instructions are pretty simple and straightforward. Now I just use CMD+SHIFT+P and type "finder" and press enter and it opens a finder window.
I think this might only work on macs though.

In sublimetext3 there is a package to sync current open file with the sidebar explorer.
SyncedSidebar

Related

Dart_LoadScriptFromKernel: The binary program does not contain 'main'

I just run this code in VsCode and show this problem
Dart_LoadScriptFromKernel: The binary program does not contain 'main'.
Dart version:2.3.2
void main() {
print("hello");
}
is there any wrong with configuration?
try saving it in your folder it works 100% and name it main
In Visual Studio Code, this error happens when you are trying to run your main.dart file, but you have another window (or tab) open with a class file for example. Make sure when you run your code you have the main (main.dart) tab open with your main function in it.
Disable the extension.
2.Then, click on Reload Required.
https://i.stack.imgur.com/XTHc6.png
Enable extension.
On Visual Studio Click on "View"
Then click on Run
Then on the left top corner see run drop-down menu
select add configuration.
Then a JSON file appears.
Now delete everything and paste the below:
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart: Attach to Process",
"type": "dart",
"request": "attach"
},
{
"name": "Dart",
"type": "dart",
"request": "launch",
"program": "bin/main.dart"
},
{
"name": "Dart: Run all Tests",
"type": "dart",
"request": "launch",
"program": "./test/"
},
{
"name": "Dart: Attach to Process",
"type": "dart",
"request": "attach"
},
{
"name": "Dart",
"program": "bin/main.dart",
"request": "launch",
"type": "dart"
}
] }
Now again go to let hand side top and see beside run there is a play
type button.
Just press it and allow permission
Now run the code in the terminal.
It will work.
I also faced the same problem. Then I found that I did not save the file (code). Then I save it (ctrl+s or File > Save). Finally I run the command
dart hello.dart
and get the expected output.
VScode always requires a main.dart file in the project directory with at least the minimum contents:
void main() {}
With that file present, you can then name any other file you're working on, and execute it directly from the VScode console using eg. dart hello_world.dart (with example contents):
void main() {
print("Hello World");
}
and the main.dart file does not need to be open when this is done.
you have to do is just save the file ctrl+s
ctrl + s please. you don't save this file

Add custom page/field to NSIS setup created with electron-builder

I have created an Electron app which is packaged into an NSIS installer with electron-builder.
Now I would like to add a custom text field to the installer, where the user can input a value (the value should be saved to disk/registry, it needs to be available in the app later).
I saw there is a customWelcomePage macro defined in the installer, which could probably be (mis)used for this purpose? But how would I create a macro which creates a complete page? NSIS is completely new to me, and the examples on the NSIS page seem to be for standalone installers, not for hooking into an existing installer. Or is there another, better approach?
I've been working on the same thing recently. Here's what I did:
First, use the include option to point to a .nsh file (I'm doing this in package.json):
{
"build": {
"appId": "...",
"nsis": {
"include": "build/installer.nsh"
}
}
}
Then you can put your custom NSIS code inside that .nsh file:
!include nsDialogs.nsh
XPStyle on
Var Dialog
Page custom myCustomPage
Function myCustomPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
...
nsDialogs::Show
FunctionEnd
Section
SectionEnd
I adapted code from Mevia's question when I was creating my custom page. This will make a page that appears before the actual installation (Mevia's problem), so you should be careful where you save the input data.
I believe that using include instead of a script is what allows you to write code for a single page, rather than having to write the entire installer script yourself.

How to configure for inserting spaces instead of tabs on Visual Studio Code for Mac

I begin to use Visual Studio Code. Current version is 0.3.0.
By default, Indent is inserted for tabs.
But I want to insert 4 spaces instead tabs.
I can't find the configure out the item in Preferences.
Please tell me, how to configure insert tab or space.
Approximately since version 0.9.0 this configuration is easily reachable by modifying the following parameters in the settings.json file:
// Controls the rendering size of tabs in characters. Accepted values: "auto", 2, 4, 6, etc. If set to "auto", the value will be guessed when a file is opened.
"editor.tabSize": 4,
// Controls if the editor will insert spaces for tabs. Accepted values: "auto", true, false. If set to "auto", the value will be guessed when a file is opened.
"editor.insertSpaces": true
For others settings and information visit the VS Code help section.
What you are looking for is in keybindings.json. From the menu Code -> Preferences -> Keyboard Shortcuts
On the right hand pane you can place your key bindings, for example:
{"key": "ctrl+t", "when": "editorTextFocus", "command": "editor.action.tab"}
though you would probably prefer something like:
{"key": "ctrl+t", "when": "editorTextFocus", "command": " "}
The problem is that it does not work as the documentation says it should!
See: Customization of Visual Studio Code
Microsoft has been notified of the behavior and tab handling preferences have also been requested.

How to add custom code snippets in VSCode?

Is it possible to add custom code snippets in Visual Studio Code? And if so, how? VSCode is based on Atom, so it should be possible.
Hit > shift + command + p and type snippets
Select Preferences: Configure User Snippets
Choose the language type for which you want to add the custom snippet in the vscode inputbox
vscode has comments to explain on how to add a snippet, as described on :> vsdoc or you can follow the next link with a short guide:
Lets say, we want to open custom snippets for the language GO. Then we can do:
Hit > command + p
Type: go.json + enter And you land on the custom snippet page
Snippets are defined in a JSON format and stored in a per-user (languageId).json file. For example, Markdown snippets go in a markdown.json file.
Using tools:
Snippet Generator extension (recommended)
Online snippet generator
Option 1 - Use the Snippet Generator extension.
It supports code to JSON conversion with optional scope support and space to \t conversion.
Demo:
Option 2 - Another extension is snippet-creator (deprecated).
After installing it, all you have to do is to :
Select the code that you want to make a snippet.
Right-click on it and select "Command Palette"(or Ctrl+Shift+P).
Write "Create Snippet".
Choose the type of files needed to be watched to trigger your snippet shortcut.
Choose a snippet shortcut.
Choose a snippet name.
Option 3 - check this website. you can generate snippets for vs code, sublime text, and atom.
Once snippet being generated on this site. Go to the respective IDE's snippet file and paste the same. For example for a JS snippet in VS code go to File->preference->user snippet then it opens javascript.json file then paste the snippet code from an above site inside this and we are good to go.
As of version 0.10.6 you can add custom snippets. Read the documentation on Creating your Own Snippets.
You can find/create custom snippets by placing the json file in C:\Users\<yourUserName>\AppData\Roaming\Code\User\snippets.
For example, a custom javascript snippets would be in a \snippets\javascript.json
You can also publish you snippets which is a really neat feature as well. John Papa created a nice angular + typescript snippet you can download as an extension in the marketplace.
Here is an example snippet taken for the documentation on a javascript for loop:
"For Loop": {
"prefix": "for",
"body": [
"for (var ${index} = 0; ${index} < ${array}.length; ${index}++) {",
"\tvar ${element} = ${array}[${index}];",
"\t$0",
"}"
],
"description": "For Loop"
},
Where
For Loop is the snippet name
prefix defines a prefix used in the IntelliSense drop down. In this case for.
body is the snippet content.
Possible variables are:
$1, $2 for tab stops
${id} and ${id:label} and ${1:label} for variables
Variables with the same id are connected.
description is the description used in the
IntelliSense drop down
You can check out this video for a quick short tutorial
https://youtu.be/g1ouTcFxQSU
Go to File --> Preferences --> User Snippets. Select your preferred language.
Now type the following code to make a for loop snippet:
"Create for loop":{
"prefix": "for",
"body":[
"for(int i = 0; i < 10; i++)",
"{",
" //code goes here",
"}"
],
"description": "Creates a for loop"
}
You are done.
Type "for" in the editor and use the first prediction.
SHORTCUT
install snippet-creator extension (now deprecated).
Highlight the code that you need to make snippet.
press ctrl+shift+P and type "Create snippet" on the command palette and
press ENTER.
select language for which you want to create snippet(eg:-CPP), then type
snippet name, type snippet shortcut and then type snippet description.
You are now good to go.
Type the snippet shortcut in the editor that you entered in step 4, and select the prediction (if no prediction comes press ctrl+space) that comes first.
Hope this helps :)
Note: goto File->Preferences->User Snippets. Then select the language in which youcreated the snippet. You will find the snippet there.
You can add custom scripts, go to File --> Preferences --> User Snippets. Select your preferred language.
If you choose Javascript you can see default custom script for console.log(' '); like this:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
},
There's a VSCode Plugin called: snippet-creator (now deprecated).
After installing it , all you have to do is to:
Select the code that you want to make it a snippet.
Right click on it and select "Command Palette"(or Ctrl+Shift+P).
Write "Create Snippet".
Choose type of files needed to be watched to trigger your snippet shortcut.
Choose a snippet shortcut.
Choose a snippet name.
That's All.
Note : if you want to edit your snippets , you will find them in [fileType].json
Example : Ctrl+P , then select "javascript.json"
I tried by adding snippets in javascriptreact.json but it didn't worked for me.
I tried adding snippets into global scope, and it's working like charm.
FILE --> Preferences --> User snippets
here select New Global Snippets File, give name javascriptreact.code-snippets.
For other languages you can name like [your_longuage].code-snippets
This is an undocumented feature as of now but is coming soon. There is a folder you can add them to and they will appear, but it may change (its undocumented for a reason).
Best advice is to add this to the uservoice site and wait til its final. But it is coming.
On MacOS:
Open the VSCode
Code -> Preferences -> User Snippets
Search for "python" (or any language)
Write your snippet like this:
{
"Write pdb": {
"prefix": "pdb",
"body": [
"import pdb; pdb.set_trace()",
"$2"
],
"description": "Write pdb.set_trace() to debug Python scripts"
}
}
Save the file with command + S.
VSCode introduce this in version 0.5, see here.
Snippet syntax follows the TextMate snippet syntax and can write in User Preferences.
If you'd rather not deal with writing your snippets in JSON, check out Snipster. It lets you write snippets as you would write the code itself - not having to wrap each line in quotes, escape characters, add meta information, etc.
It also lets you write once, publish anywhere. So you can use your snippet in VS Code, Atom, and Sublime, plus more editors in the future.
This may not be a real answer (as some have answered above), but if you're interested in creating custom code snippets for other people, you can create extensions using yeoman and npm (which by default comes along with NodeJS) . NOTE: This is only for creating snippets for other's systems. But it also works for you too! Except you need JS code for whole thing.
You can add custom scripts, go to File --> Preferences --> User Snippets. Select your preferred language.
Like mine code is go, I do it as below:
"channel code": {
"prefix": "make_",
"body": [
"${1:variable} := make(chan ${2:type}, ${3:channel_length})",
"$4"
]
}
explanation: $1 will take your tabs & to give hints what are those tabs values, we make it like ${1:some_variable} which could give us hints what are those
I hope, it helps!

Is there a "correct" folder where to place test resources in dart?

I have a simple dart class I am trying to test.
To test it I need to open a txt file, feed the content to an instance of the class and check that the output is correct.
Where do I place this txt file? The txt file is useless outside of testing.
Also, related, how do I acess its directory consistently? I tried placing it in the test folder, but the problem is that:
System.currentDirectory
Returns a different directory if I am running the test on its own or the script calling all the other test dart files on at a time
I check if System.currentDirectory is the directory containing the pubspec.yaml file, if not I move the current directory upwards until I found the directory containing the pubpsec.yaml file and then continue with the test code.
Looks like package https://pub.dev/packages/resource is also suitable for this now.
I have still not found a definitive answer to this question. I've been looking for something similar to the testdata directory in Go and the src/test/resources directory in Java.
I'm using Android studio and have settled on using a test_data.dart file at the top of my test directory. In there I define my test data (mostly JSON) and then import it into my individual tests. This doesn't help if you need to deal with binary files but it has been useful for my JSON data. I'll also inject the JSON language with //language=json so I can open the fragment in a separate window to format.
//language=json
const consolidatedWeatherJson = '''{
"consolidated_weather": [
{
"id": 4907479830888448,
"weather_state_name": "Showers",
"weather_state_abbr": "s",
"wind_direction_compass": "SW",
"created": "2020-10-26T00:20:01.840132Z",
"applicable_date": "2020-10-26",
"min_temp": 7.9399999999999995,
"max_temp": 13.239999999999998,
"the_temp": 12.825,
"wind_speed": 7.876886316914553,
"wind_direction": 246.17046093256732,
"air_pressure": 997.0,
"humidity": 73,
"visibility": 11.037727173307882,
"predictability": 73
}
]
}
''';
Using the Alt + Enter key combination will bring up the Edit JSON Fragment option. Selecting that open the fragment in a new editor and any changes made there (formatting for example) will be updated in the fragment.
Not perfect but it solves my issues.

Resources