Multiple-line cursor movements in XCode - xcode

I'd like to map a key to move the cursor in the XCode up by ten lines. Of course, I want another one to move down too. The key mapping would ideally be something like 'Control-Alt-P'.
Is there a way to achieve this in XCode without resorting to Automator?
Ashley has the answer below, the formatting was a little different as the property list is in XML format.
In summary, added an entry in the following format to the 'text' section of *.pbxkeys in ~/Library/Application Support/Xcode/Key Bindings/:
<key>^~p</key>
<array>
<string>moveUp:</string>
<string>moveUp:</string>
</array>

You can use the example given here and use a DefaultKeyBinding.dict file, except use moveUp: and moveDown: as your selectors.
Your particular dictionary entry would look something like this:
{
"^~P" = (
"moveUp:",
"moveUp:",
"moveUp:",
... however many times ...
"moveUp:",
);
}
I have since learned that if you have customized your keybindings through Xcode already you should instead add the same dictionary entry to your .pbxkeys file under the text dictionary section.

Just a reminder for the impatient who didn't read all the way to the end of oldbeamer's question and are also looking to use .pbxkeys instead of .dict:
If you are wanting to add multi-action keybindings to your pbxkeys file, the XML formatting goes like this:
<key>...</key>
<array>
<string>action1:</string>
<string>action2:</string>
<string>etc:</string>
</array>
You can edit the .pbxkeys directly using a text editor to add custom multi-action keybindings this way.

Related

Show specific Quick Action for specific file extension

I am newbie with Applescript and Automator. I am trying to build a Quick Actions which will be able to propose different functions according to the type of file for example.
If the file is test.sh quick action will be a and b
If the file is document.pdf action will be c and d
I succeed in creating my actions but not to make them specific to file type. I don't know where to start as I don't see any possibility to make input conditional like if input = .sh do a and b.
Any help on how to proceed will be really appreciated.
Thank you,
After looking at the image of your QuickAction, it is not at all useful for anything other then a selected PDF document in Finder.
The first action should be a Set Value of Variable action so its contents can be retrieved multiple times using Get Value of Variable with however many Filter Finder Items actions needed to process the different file types, followed by the appropriate actions for each file type.
You would also use Ignore this action's input checkbox under Options for this action to detach it from the previous set of actions.
The image below shows a rough outline example of what I'm referring to:
Quick Actions are meant to be type-specific, so in general the best practice is to write one Quick Action for each file type. These quick actions will only appear in the Finder when files of that type are selected.
In many cases you can specify the file type when you create or edit the Quick Action in Automator. For instance, to create a Quick Action that appears only when PDF files are selected, set the pulldown menus at the top of the workflow to say "Workflow receives current PDF files in Finder":
then complete and save the Quick Action.
If you want more fine-tuned control over what types of files the Quick Action 'sees', you can edit its info.plist file and change its file types. After you've saved the Quick Action, navigate to ~/Library/Services in the Finder (that's the Services folder in the Library folder of your Home folder). Find the package with the name of the Quick Action (e.g., "Open in Preview"), control-click on it to get the contextual menu, choose Show Package Contents, and then open the Contents folder. You'll see the following:
Open that info.plist file in a plain-text text editor — I prefer BBEdit, but TextEdit will work fine if you make sure 'rich text' is turned off — and look for the NSSendFileTypes key. It will look something like the following:
<key>NSSendFileTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
com.adobe.pdf is a Uniform Type Identifier (UTI), and you can add or substitute in any system-recognized UTI. Here is the list of system-declared UTIs, but applications can declare their own UTIs and register them with the system, so this list is not necessarily exhaustive. For instance, if you want your Quick Action to send both PDFs and image files to Preview, you would search on the system-declared UTIs page and find that the base UTI for images is public.image, and then edit the info.plist to read:
<key>NSSendFileTypes</key>
<array>
<string>com.adobe.pdf</string>
<string>public.image</string>
</array>
Save this, and the Quick Action will now appear whenever you selected PDFs or images. Note that if you manually edit the info.plist file it might get overwritten if you edit and save the Quick Action in Automator.
Only the first two relevant Quick Actions will appear in the Finder window; any extras will be collapsed under the more button. To change the ordering so that the Quick Actions you use most are up first, open System Preferences, click the Extensions item, open the Finder section, and drag the items in the right-hand list into the order you prefer.

Sublime Text 2 loading all shell scripts as plain text [duplicate]

I'd like Sublime 2 editor to treat *.sbt files (to highlight syntax) as Scala language, same as *.scala, but I can't find where to set this up. Do you happen to know?
In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:
View -> Syntax -> Open all with current extension as ...
I've found the answer (by further examining the Sublime 2 config files structure):
I was to open
~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage
And edit it to add sbt (the extension of files I want to be opened as Scala code files) to the array after the fileTypes key:
<dict>
<key>bundleUUID</key>
<string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
<key>fileTypes</key>
<array>
<string>scala</string>
<string>sbt</string>
<array>
...
PS: May there be a better way, something like a right place to put my customizations (insted of modifying packages themselves), I'd still like to know.
I put my customized changes in the User package:
*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage
Which also means it's in JSON format:
{
"extensions":
[
"sbt"
]
}
This is the same place the
View -> Syntax -> Open all with current extension as ...
menu item adds it (creating the file if it doesn't exist).
For ST3
$language = "language u wish"
If exists, open ~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
else just create it.
And set
{
"extensions":
[
"*yourextension*"
]
}
This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )
There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.
There is a quick method to set the syntax:
Ctrl+Shift+P,then type in the input box
ss + (which type you want set)
eg: ss html +Enter
and ss means "set syntax"
it is really quicker than check in the menu's checkbox.
I know this topic is old now, but let me state a new approach, some people might find this easy to understand and do.
Open Sublime Text(make sure you have Package Control installed and ready in your Sublime Text):
Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
Type "PRV"(Package Resource Viewer), select the one ending with :Open Resource
Type "SCALA"/"scala" and press Enter
Type Scala.sublime-syntax and press Enter and press Esc to close the
open list
Now in Scala.sublime-syntax goto the section file_extensions: and add your file extension sbt(like - sbt) in the end of that section
Save and close the file and restart Sublime Text, you'll now have
Scala syntax highlighting for your custom .sbt extension. Same steps can be done with any file type like XML, PHP, HTML, JS etc.
Pretty easy to follow, right ?

Use one language definition inside another?

I'm writing a language definition for sublime text for the Kinetic Rule Language. In KRL, there are some places where you can write HTML or Javascript, so I want to let the Javascript and HTML language definitions take over for these blocks.
I thought it would be as simple as just specifying text.html or source.js for the scope name, but that doesn't seem to work. Can anyone shed some light on the proper way to do this?
If you define the regions in which HTML or javascript will be defined, you can define a start and end regular expressions, and include the language. It's described a little more in Sublime Text 2: Different language highlighting based on context? (a la Webstorm).
If instead you want to include it globally (for instance if you were simply extending the language), you can add the following as an entry under "patterns".
<dict>
<key>include</key>
<string>source.js</string>
</dict>
<dict>
<key>include</key>
<string>text.html</string>
</dict>

Assign code snippet to keyboard shortcut in Visual Studio

Anyone knows how to assign key shortcut to specific code snippet?
I would like to assign for instance CTRL+K,CTRL+J to a #region snippet.
Therefore by able to:
select text,
press CTRL+K,CTRL+J =>
selected text would be surrounded with #region .. #endregion.
I hate when I have to take my hands out of keyboard for more time than necessary:).
EDIT: For more understanding, I am asking how to bind key shortcut directly to SPECIFIC snippet. Opening snippet selector wont work for me. If I have to search through all my snippets to get to a the #region one, its worse then writting all its code by myself.
Thx for any suggestions.
Type a < and then type your snippet shorcut(your XML file Name) and then press tab.
you can get more info from this link
https://learn.microsoft.com/en-us/visualstudio/xml-tools/how-to-use-xml-snippets?view=vs-2017
for example i have a code snippet which i've set xml file name and its shortcut to flog
when i want to use it directly to my code i do like this:
<flog and press tab it Works.
The closest solution I've found for this is to copy the intended snippet to your local snippets directory.
e.g. For VS-2015:
%Userprofile%\Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets
Then open it in a text editor and change the shortcut to something quick and simple such as '1'.
Now to use it, all you need to do is press Ctrl+K+S > Enter > 1 > Enter
Additionally, you can make it even quicker by changing the hotkey for the surround-with command.
(Tools > Options > Keyboard > Edit.SurroundWith)
I think you may want to try adding a <Shortcut> tag inside your MySnippet.snippet file
<Header>
<Title>Square Root</Title>
<Author>Myself</Author>
<Description>Calculates the square root of 16.</Description>
<Shortcut>sqrt</Shortcut>
</Header>
For details check out : https://learn.microsoft.com/en-us/visualstudio/ide/walkthrough-creating-a-code-snippet?view=vs-2019#description-and-shortcut-fields
To add a shortcut, add a Shortcut element within the Header element
For me the fastest solution was to Import a Folder named "1", then Add the snippet (my name was "block") and mark it in the 1-Folder.
Then i can insert the snippet by
<Ctrl+K,X> + <Enter> + <Enter>
First Enter chooses 1 (the Folder with MY snippets) and the second Enter chooses my most used snippet (must be alphabetically first)

How to customise file type to syntax associations in Sublime Text?

I'd like Sublime 2 editor to treat *.sbt files (to highlight syntax) as Scala language, same as *.scala, but I can't find where to set this up. Do you happen to know?
In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:
View -> Syntax -> Open all with current extension as ...
I've found the answer (by further examining the Sublime 2 config files structure):
I was to open
~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage
And edit it to add sbt (the extension of files I want to be opened as Scala code files) to the array after the fileTypes key:
<dict>
<key>bundleUUID</key>
<string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
<key>fileTypes</key>
<array>
<string>scala</string>
<string>sbt</string>
<array>
...
PS: May there be a better way, something like a right place to put my customizations (insted of modifying packages themselves), I'd still like to know.
I put my customized changes in the User package:
*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage
Which also means it's in JSON format:
{
"extensions":
[
"sbt"
]
}
This is the same place the
View -> Syntax -> Open all with current extension as ...
menu item adds it (creating the file if it doesn't exist).
For ST3
$language = "language u wish"
If exists, open ~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
else just create it.
And set
{
"extensions":
[
"*yourextension*"
]
}
This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )
There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.
There is a quick method to set the syntax:
Ctrl+Shift+P,then type in the input box
ss + (which type you want set)
eg: ss html +Enter
and ss means "set syntax"
it is really quicker than check in the menu's checkbox.
I know this topic is old now, but let me state a new approach, some people might find this easy to understand and do.
Open Sublime Text(make sure you have Package Control installed and ready in your Sublime Text):
Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
Type "PRV"(Package Resource Viewer), select the one ending with :Open Resource
Type "SCALA"/"scala" and press Enter
Type Scala.sublime-syntax and press Enter and press Esc to close the
open list
Now in Scala.sublime-syntax goto the section file_extensions: and add your file extension sbt(like - sbt) in the end of that section
Save and close the file and restart Sublime Text, you'll now have
Scala syntax highlighting for your custom .sbt extension. Same steps can be done with any file type like XML, PHP, HTML, JS etc.
Pretty easy to follow, right ?

Resources