Related
Im using VS code with c++ extesion, on my task.json i have a debug task and runwithoutdebug task, this tasks have common arguments and i instead of have to add those arguments in both, i was trying to reference a array, and write those common argument in that array.
Is that possible? is there any alternative
Example: --->task.json
"version": "2.0.0",
"tasks": [
{ ----------------------> TASK 1
"label": "compilewithoutDeb",
"type": "shell",
"command": "g++",
"args": [
"main.cpp",
"header.cpp",
"-o",
"main.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{ ----------------------> TASK 2
"label": "compileDeb",
"type": "shell",
"command": "g++",
"args": [
"-g",
"main.cpp",
"header.cpp",
"-o",
"main.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Has you can see i have on task "compilewithoutDeb" and "compileDeb" this common arguments
"main.cpp",
"header.cpp",
"-o",
"main.exe"
Is there a away that i could do like:
"paramArg":[
"main.cpp",
"header.cpp",
"-o",
"main.exe"
]
"tasks": [
{
"label": "compilewithoutDeb",
"type": "shell",
"command": "g++",
"args": [
"${paramArg}" <-----------------
],
"group": {
"kind": "build",
"isDefault": true
}
}
You can create an input. It would be a promptString with the arguments as the default. For your other task you'd add the "-g" parameter before the input.
"tasks": [
{
"label": "compilewithoutDeb",
"type": "shell",
"command": "g++",
"args": [
"${input:paramArg}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "compileDeb",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${input:paramArg}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
],
"inputs": [
{
"id": "paramArg",
"description": "Just hit the Enter key",
"type": "promptString",
"default": "main.cpp header.cpp -o main.exe"
},
]
Yes, there's an (ugly) way to do this. While tasks.json can only define tasks (that is what is is for) it can reference different kind of variables.
The two options that would be reasonable to use: env (if you want to set it outside of vscode which doesn't seem to be the case here) or config.
To apply it to your sample:
settings.json (either in your user's settings or in the workspace [folder .vscode])
{
"personalSettings.commonArgs": [
"-o",
"main.exe",
"header.cpp",
"main.cpp"
]
}
and then your tasks.json would be
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{ // ----------------------> TASK 1
"label": "compilewithoutDeb",
"type": "shell",
"command": "g++ ${config:personalSettings.commonArgs}",
"group": {
"kind": "build",
"isDefault": true
}
},
{ // ----------------------> TASK 2
"label": "compileDeb",
"type": "shell",
"command": "g++ ${config:personalSettings.commonArgs}",
"args": [
"-g"
],
"group": "build"
}
]
}
(additional changes: only one build task can be the default, used inline comments)
Note: to get the most out of your build tasks I'd suggest to add a problem matcher to your task definition, something like
// use this or similar when cpptools or a similar libre/free extension
// is installed providing an appropriate matcher
// "problemMatcher": "$gcc"
// remark: ms-vscode.cpptools is "gratis", but comes with telemetry + usage-restrictions
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
Note: I'd suggest to not hard-wire the file names, instead use either a "general task" which uses ${file} or change the tool you run to make where you have all the arguments defined clean, can build outside of vscode, too and because of dependency tracking only compile what is actually necessary.
Currently, Sublime 2 displays 8 items under File > Open Recent. I was hoping to double that to 16. I've searched and haven't found anything yet, except for increasing the Open Projects list, and this isn't the correct solution since I don't utilize projects. Can anyone offer any help?
As far as I'm aware, there is no setting that controls this. However by modifying the menu contents you can extend the number of items that are shown there.
To do this, you can follow these steps:
Install PackageResourceViewer if it is not already installed
From the Command Palette, select PackageResourceViewer: Open Resource
Select the Default package
Select the Main.sublime-menu resource
This opens up the file that controls what the menu contains. Near the top you will see something similar to this:
{
"caption": "Open Recent",
"mnemonic": "R",
"children":
[
{ "command": "reopen_last_file", "caption": "Reopen Closed File" },
{ "caption": "-" },
{ "command": "open_recent_file", "args": {"index": 0 } },
{ "command": "open_recent_file", "args": {"index": 1 } },
{ "command": "open_recent_file", "args": {"index": 2 } },
{ "command": "open_recent_file", "args": {"index": 3 } },
{ "command": "open_recent_file", "args": {"index": 4 } },
{ "command": "open_recent_file", "args": {"index": 5 } },
{ "command": "open_recent_file", "args": {"index": 6 } },
{ "command": "open_recent_file", "args": {"index": 7 } },
{ "caption": "-" },
{ "command": "open_recent_folder", "args": {"index": 0 } },
{ "command": "open_recent_folder", "args": {"index": 1 } },
{ "command": "open_recent_folder", "args": {"index": 2 } },
{ "command": "open_recent_folder", "args": {"index": 3 } },
{ "command": "open_recent_folder", "args": {"index": 4 } },
{ "command": "open_recent_folder", "args": {"index": 5 } },
{ "command": "open_recent_folder", "args": {"index": 6 } },
{ "command": "open_recent_folder", "args": {"index": 7 } },
{ "caption": "-" },
{ "command": "clear_recent_files", "caption": "Clear Items" }
]
},
From here you can extend the number of recent files out to 16 by adding additional lines for open_recent_file with indexes from 8 to 15 (since the indexes are 0 based), and then save the file.
As a side note, this will work for both Sublime Text 2 and Sublime Text 3.
In Sublime Text 3 this creates a package override for Default/Main.sublime-menu, which Sublime will use instead of the shipped version of the menu. If a future version of ST3 updates the main menu in any way, you won't be told and may potentially miss other menu changes and features. You can install OverrideAudit, which will warn you if that ever happens.
This is potentially also a worry for Sublime Text 2 (although OverrideAudit is ST3 only and cannot help you here), but it is unlikely that ST2 will be updated any further so this is probably of no real consequence.
I found you don't actually need to override the main menu;
just add your own menu which will appear in the end.
Create this new file (path for me in linux, in Sublime Text 3):
~/.config/sublime-text-3/Packages/User/Main.sublime-menu
In that file put something similar to OdatNurd previous answer;
(and I copy paste the same content into the files:
Context.sublime-menu
Side Bar.sublime-menu
to have the same submenu show up there)
I just made my own submenu from my own initials "elm" and put all stuff I personally use there with various "children" subtrees.
As a bonus, it will automatically show keyboard shortcuts to the same command behind it,
so I also use it as a reminder for actions that I don't use very often and forget the keyboard shortcut of.
Caveat: after posting this I realised I this works for Sublime Text 3, while the question was for Sublime Text 2. Perhaps someone can test if this also works for Sublime Text 2?
My file looks something like this:
(also added some more ideas (beside plenty recent files) for inspiration)
[
{
"caption" : "elm",
"mnemonic": "M",
"children": [
{
"caption": "Open Recent",
"mnemonic": "R",
"children": [
{ "command": "reopen_last_file", "caption": "Reopen Closed File" },
{ "caption": "-" },
{ "command": "open_recent_file", "args": {"index": 0 } },
{ "command": "open_recent_file", "args": {"index": 1 } },
// ... etc.
{ "command": "open_recent_file", "args": {"index": 29 } },
],
},
{
"caption": "Multi Line/Caret editing",
"children": [
{
"caption": "split_selection_into_lines",
"command": "split_selection_into_lines",
},
{
"caption": "Add caret above (select_lines)",
"command": "select_lines",
"args": {"forward": false},
},
{
"caption": "Add caret below (select_lines)",
"command": "select_lines",
"args": {"forward": true},
},
]
},
{
"caption": "Bookmarks",
"children": [
{
"caption": "toggle_bookmark",
"command": "toggle_bookmark",
},
{
"caption": "prev_bookmark",
"command": "prev_bookmark",
},
{
"caption": "next_bookmark",
"command": "next_bookmark",
},
]
},
{
"caption": "paste_from_history",
"command": "paste_from_history",
},
{
"caption": "Jump to matching bracket",
"command": "move_to", "args": {"to": "brackets"},
},
// ... etc. etc.
],
},
]
Bit off topic for just more recent files, but I thought this approach might also improve other usability and maintainability aspects at the same time :)
This is driving me nuts (go nuts!). Build / run file is proper and fmt command is proper. But if I try to combine into one tasks file, it stops working.
These two work fine on their own and behave the way I want:
tasks.json
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "build",
"args": [
"build",
"-o",
"${workspaceRoot}.exe",
"&&",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
}
tasks.json
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "fmt",
"args": [
"fmt",
"${file}"
],
"isBuildCommand": true
}
But combined into one file, it will not work:
tasks.json
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"tasks": [
{
"taskName": "build",
"args": [
"build",
"-o",
"${workspaceRoot}.exe",
"&&",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
},
{
"taskName": "fmt",
"args": [
"fmt",
"${file}"
]
}
]
}
Error given on build:
can't load package: package build: cannot find package "build" in any of:
D:\dev\Go\src\build (from $GOROOT)
D:\dev\Gopher\src\build (from $GOPATH)
can't load package: package -o: cannot find package "-o" in any of:
D:\dev\Go\src\-o (from $GOROOT)
D:\dev\Gopher\src\-o (from $GOPATH)
can't load package: package d:/dev/Gopher/src/myproject.exe: cannot find package "d:/dev/Gopher/src/myproject.exe" in any of:
D:\dev\Go\src\d:\dev\Gopher\src\myproject.exe (from $GOROOT)
D:\dev\Gopher\src\d:\dev\Gopher\src\myproject.exe (from $GOPATH)
I can't seem to understand why it works one way, but not the other. The second method (for combined tasks) is outlined here: Define multiple tasks in VSCode
Answer: The problem lies with adding "build" or "fmt" as an args when it's already listed as a taskname. I did not know that's how taskname worked. Final working product which allows users to develop without worrying about stupid windows firewalls:
tasks.json (final & working thanks to #not-a-golfer)
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"echoCommand": true ,
"tasks": [
{
"taskName": "build",
"args": [
"-o",
"${workspaceRoot}.exe",
"&&",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
},
{
"taskName": "fmt",
"args": [
"${file}"
]
}
]
}
The following seems to be working, but it appears that you can't chain the running with &&:
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"echoCommand": true ,
"tasks": [
{
"taskName": "build",
"args": [
"-x",
"-o",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
},
{
"taskName": "fmt",
"args": [
"${file}"
]
}
]
}
You should add the attribute suppressTaskName.
OPs solution to remove superfluous build parameter obviously works, however, VSCode's documentation covers this very example:
We set suppressTaskName to true as by default the task name is also passed to the command which would result in "echo hello Hello World".
{
"version": "0.1.0",
"command": "echo",
"isShellCommand": true,
"args": [],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "hello",
"args": ["Hello World"]
},
{
"taskName": "bye",
"args": ["Good Bye"]
}
]
}
My favorite build task is:
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"echoCommand": true ,
"options": {
"cwd": "${fileDirname}"
},
"tasks": [
{
"taskName": "build",
"args": [
"build",
"-x"
],
"isBuildCommand": true,
"suppressTaskName": true
}
]
}
I need a fast way to make the cursor jump outside the auto wrap qoutes or other syntax elements. I don't want to have to reach down to my arrow keys each time, and definitely don't want to go to my mouse.
Is there a quick and easy way to solve this for my workflow?
You can use a shortcut (shift+space, or whatever you like) to move the cursor.
In your Key Bindings - User:
{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": true} }
I made a few key bindings out of macros as well.
You must make a macro for these, unless you want to spend more time building them, but it's really easy. Just go to Sublime Text, Tools > Record Macro, or hit ctrl Q. Save the file in Packages/User/ and then hit ⌘ , to open up your User Settings. Paste the settings below in there and boom. ( The | below represents my cursor )
Here are the one's I chose:
Function auto-bracketizer
When the cursour is here:
totallyAwesomeness(|)
Use the option + tilda shortcut.
⌥ ~
This prefills the function with brackets and the text ' # code... ' highlighted. It only works when inside the parenthesis.
Sublime User Settings
{
"keys": ["option+`"], "command": "run_macro_file", "args": {"file": "Packages/User/superBracketizeFunction.sublime-macro"}
},
Download Macro
Auto-End Line With Semicolon
When the cursour is here:
echo 'say what!!??|'
Use the command + semicolon shortcut.
⌘ ;
This adds a closing ; at the end of current line and moves you to the line below it. It actually works wherever you are on the line.
Sublime User Settings
{
"keys": ["super+;"], "command": "run_macro_file", "args": {"file": "Packages/User/superEndLineWiSemiColin.sublime-macro"}
},
Download Macro
Exit Argument & Exit Function
When your cursor is anywhere inside the function it will end up here:
public function totallyAwesomeness()
{
echo 'say what!!??';
} |
echo 'yep... that just happened';
Use the command + enter shortcut.
⌘ Enter
This will let you jump outside the argument and a space to the right as well as anywhere from within the function it will jump you out of it just being the closing bracket.
Sublime User Settings
{
"keys": ["option+enter"], "command": "run_macro_file", "args": {"file": "Packages/User/superExitFunctionArg.sublime-macro"}
},
Download Macro
Just in case you don't know what the path is to your User folder is, it is shown below.
/Users/alexcory/Library/Application Support/Sublime Text 3/Packages/User/
Also the Library folder is usually hidden, so you can download a program called Revealer that will allow you to toggle those hidden files.
If you want to know how I made these just hit me up and I'll show you! :D
Best solution for this is recording a macro on Sublime Text and then assigning it to a keyboard shortcut. Follow these steps:
Create a line such as alert('hello') and leave the cursor right
after letter 'o'.
Then go to Tools > Record a Macro to start recording.
Press Command+→ to go to the end of line.
Press ; and hit Enter
Stop recording the macro by going to Tools > Stop Recording Macro
You can now test your macro by Tools > Playback Macro (optional)
Save your macro by going to Tools > Save Macro (ex: EndOfLine.sublime-macro)
Create a shortcut by adding this between the square brackets in your
in your Preferences > Key Bindings - User file:
{
"keys": ["super+;"], "command": "run_macro_file", "args": {"file": "Packages/User/EndOfLine.sublime-macro"}
}
Now, every time you hit Command+;, it will
magically place the semicolon at the end of current line and move the cursor to the next line.
Happy coding!
A more complete way to make a key binding would be:
{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)\"\\]]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
Assuming you want shift+space as the shortcut. Or you can change it to tab as well
As found in http://www.sublimetext.com/forum/viewtopic.php?f=3&t=5174#p23086
Following Riccardo Marotti's post;
If you would like to bypass the bracket on the next line, you can replace "characters" with "lines" in the args section.
{ "keys": ["shift+space"], "command": "move", "args": {"by": "lines", "forward": true} }
on a Dell XPS, Ctrl Enter does the trick for me
I just have this feature partially implemented with the help of a plugin named run_multiple_commands.py (see below)
(only tested on ST3, but the plugin is earlier than the first version of ST3 and should work on ST2 too).
Shortcut configuration is as below:
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move", "args": {"by": "characters", "forward": true} }
]
},
"context":
[
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[)\\]}'\"]$", "match_all": true},
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move", "args": {"by": "characters", "forward": true} },
]
},
"context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)\\]}'\"]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move_to", "args": {"to": "brackets"} },
]
},
"context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[(\\[{]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move_to", "args": {"to": "brackets"} },
{"command": "move", "args": {"by": "characters", "forward": true} },
]
},
"context":
[
{ "key": "following_text", "operator": "not_regex_contains", "operand": "^[)\\]}'\"]", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[)\\]}'\"]$", "match_all": true},
{ "key": "following_text", "operator": "not_regex_contains", "operand": "^[(\\[{]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
One shortcut (shift+space) for four conditions:
cursor is just after quotes or closing parentheses/bracket:
move one character forward
cursor is just before quotes or closing parentheses/bracket:
move one character forward
cursor is just before opening parentheses/bracket:
move to closing parentheses/bracket
!1 && !2 && !3:
move to closing parentheses/bracket
and move one more character forward
To use this configuration in your ST, you should first add a file named run_multiple_commands.py to your .../Package/User/ directory, and the content of which is the second code piece of This Article
This solution is just fine for everyday use but is not perfect because:
the cursor is unable to jump out of quotes (just step over it when the cursor is directly followed by one).
the cursor is unable to jump out of the nearest parenthesis, quotes, or brackets when the code block is commented.
Ctrl + M is the default one that I have on windows machine.
Just do it
Perhaps the home and the end key are near to your fingers.
I use ctrl+f to move cursor one space forward. Also, on mac, I interchanged caps lock with ctrl. caps lock+f is much easier to reach. It works fairly well for me.
I found another way which lies within sublime keybindings itself. Basically, I just modify the keybindings for auto closing parens, that is, I replace "contents": "($0)" with "contents": "($1)$0". Then just hit Tab to get out of the parenthesis. So I add in my keybindings the following:
{ "keys": ["("], "command": "insert_snippet", "args": {"contents": "($1)$0"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|;|\\}|$)", "match_all": true }
]
},
And similar for square brackets, curly brackets, and single and double quotes.
Ctrl + PgUp Cycle up through tabs
Ctrl + PgDn Cycle down through tabs
This can go to the end of brackets
I'm trying to map keyboard shortcuts for SublimeREPL plugin commands. Looking at SublimeREPL it looks like a menu item command is defined as:
Default.sublime-commands
{
"caption": "SublimeREPL: SBT for opened folder",
"command": "run_existing_window_command", "args":
{
"id": "repl_sbt",
"file": "config/Scala/Main.sublime-menu"
}
}
or in
Main.sublime-menu
{"command": "repl_open",
"caption": "SBT for opened folder",
"id": "repl_sbt",
"mnemonic": "b",
"args": {
"type": "subprocess",
"encoding": "utf8",
"external_id": "scala",
"cmd": {"linux": ["sbt"],
"osx": ["sbt"],
"windows": ["sbt"]},
"soft_quit": "\nexit\n",
"cwd": "$folder",
"cmd_postfix": "\n",
"extend_env": {"osx": {"EMACS": "1", "PATH": "{PATH}:/usr/local/bin"},
"linux": {"EMACS": "1", "PATH": "{PATH}:/usr/local/bin"},
"windows": {"EMACS": "1"}},
"suppress_echo": false,
"syntax": "Packages/Scala/Scala.tmLanguage"
}
}
I've tried making a keybinding in my SublimeREPL.sublime-settings to:
[{ "keys": ["super+shift+k"], "command": "run_existing_window_command", "args":
{
"id": "repl_sbt",
"file": "config/Scala/Main.sublime-menu"
}
}]
But when I try to use it the Sublime console just says:
no command for selector: noop:
Same if I map it to:
[{ "keys": ["super+shift+k"], "command": "repl_open",
"args": {
"type": "subprocess",
"encoding": "utf8",
"external_id": "scala",
"cmd": {"linux": ["sbt"],
"osx": ["sbt"],
"windows": ["sbt"]},
"soft_quit": "\nexit\n",
"cwd": "$folder",
"cmd_postfix": "\n",
"extend_env": {"osx": {"EMACS": "1", "PATH": "{PATH}:/usr/local/bin"},
"linux": {"EMACS": "1", "PATH": "{PATH}:/usr/local/bin"},
"windows": {"EMACS": "1"}},
"suppress_echo": false,
"syntax": "Packages/Scala/Scala.tmLanguage"
}
}]
Your first keybinding is correct and should work as expected. Place is in Preferences -> Key Bindings - User file.
[{ "keys": ["super+shift+k"], "command": "run_existing_window_command", "args":
{
"id": "repl_sbt",
"file": "config/Scala/Main.sublime-menu"
}
}]
based on your description, I suspect that some other command is hijacking super+shift+k.
>>> sublime.log_commands(True)
will let you see what's get called when.