Xcode indentation key bindings - xcode

Is there a way to get Xcode 4 to indent text so that pressing tab on selected text would indent it, shift + tab would unindent like in many editors?
The default ⌘] and ⌘[ do not seem to work, probably because I have a Finnish keyboard layout. Pressing the key combination for [ (alt + 8) and additionally holding down ⌘ does not indent.
In Xcode preferences I found "Key Bindings" and "Shift Right", "Shift Left", but it does not seem to understand shift + tab. If I try to press shift + tab I get ⇧⌘⇤.

As a workaround if you can't enter shift-tab, you could find the key binding (stored at ~/Library/Developer/Xcode/UserData/KeyBindings and modify it directly. It's XML so you should be able to do this without too much trouble.

Setting the Tab binding for Shift Right did not work for me either even when remapping "Insert Tab" to something else (seems hardcoded/bug). However I did get Alt + Tab and Shift + Alt + Tab binding working (with the Finnish Keyboard layout, didn't test extended or sami). I still had to remap "Insert Tab without Extra Action" from Alt + Tab to Alt + Ctrl + Tab, you could avoid this by using Ctrl instead of Alt for shifting.
Here is the xml file for it.
cd ~/Library/Developer/Xcode/UserData/KeyBindings
vi Default.idekeybindings (probably empty plist, if not extend appropriately)
Paste:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Menu Key Bindings</key>
<dict>
<key>Key Bindings</key>
<array>
<dict>
<key>Action</key>
<string>shiftRight:</string>
<key>Alternate</key>
<string>NO</string>
<key>CommandID</key>
<string>Xcode.IDESourceEditor.CmdDefinition.ShiftRight</string>
<key>Group</key>
<string>Editor Menu for Source Code</string>
<key>GroupID</key>
<string>Xcode.IDESourceEditor.MenuDefinition.Editor</string>
<key>GroupedAlternate</key>
<string>NO</string>
<key>Keyboard Shortcut</key>
<string>~ </string>
<key>Navigation</key>
<string>NO</string>
<key>Parent Title</key>
<string>Structure</string>
<key>Title</key>
<string>Shift Right</string>
</dict>
<dict>
<key>Action</key>
<string>shiftLeft:</string>
<key>Alternate</key>
<string>NO</string>
<key>CommandID</key>
<string>Xcode.IDESourceEditor.CmdDefinition.ShiftLeft</string>
<key>Group</key>
<string>Editor Menu for Source Code</string>
<key>GroupID</key>
<string>Xcode.IDESourceEditor.MenuDefinition.Editor</string>
<key>GroupedAlternate</key>
<string>NO</string>
<key>Keyboard Shortcut</key>
<string>~$</string>
<key>Navigation</key>
<string>NO</string>
<key>Parent Title</key>
<string>Structure</string>
<key>Title</key>
<string>Shift Left</string>
</dict>
</array>
<key>Version</key>
<integer>3</integer>
</dict>
<key>Text Key Bindings</key>
<dict>
<key>Key Bindings</key>
<dict>
<key>^~ </key>
<string>insertTabIgnoringFieldEditor:</string>
</dict>
<key>Version</key>
<integer>3</integer>
</dict>
</dict>
</plist>

Tabbing is included with Xcode, it's just a different key combination. The keyboard short cuts are Command-] for indent and Command-[ for un-indent.
Another handy feature of Visual Studio that is also in Xcode is the block select feature. In Visual Studio if you hold down the Alt key while clicking and dragging you can select a block of text whose start and end columns don’t have to be the beginning and end of the line.
You can also do this in Xcode by holding down the Option key while clicking and dragging.
Found this information here:
http://idevhub.com/xcode-tips-selection-indent-and-block-select/

Related

Is color scheme file cached?

I'm using IDLE color scheme for Sublime 3, but it did not have diff syntax highglight. SO I found one that I could use it. I added it using PackageResourceViewer. After adding additional content into scheme, I noticed diff syntax working. But I did not like that insertion was colored blue and diff header was green.
So I swapped colors between diff header and insertion. But it had no effect. Header was still green and insertion was still blue. It looks like file is cached somewhere, because I could even delete diff highlight declaration and it would still show me highlights.
My current scheme (with swapped colors) is this:
<dict>
<key>name</key>
<string>diff.header</string>
<key>scope</key>
<string>meta.diff, meta.diff.header</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#3333FF</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.deleted</string>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#DD5555</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.inserted</string>
<key>scope</key>
<string>markup.inserted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#009933</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.changed</string>
<key>scope</key>
<string>markup.changed</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#E6DB74</string>
</dict>
</dict>
Note. Even if I close sublime, open with PRV, I can see that in file my changes persist, but actual syntax is still showed from initial copy/paste.
Some packages quite often decide to make tweaks to the color scheme, and thus create a new color scheme so as to not mess with the original - then they set your active color scheme to their tweaked copy. Therefore, although ST doesn't cache the color scheme - it will look as though it does.
To check, you can see the output from view.settings().get('color_scheme') Enter in the ST console (View menu -> Show Console) - most often the packages that do this name their copy of the color scheme as the original with (package name) appended to the end.
Or check the main User preferences file. Just set it back to your color scheme, and the package will probably do the same thing again but at least it should include your changes this time.

Styling escape character in Sublime Text

I want to style escape character and only escape character differently using custom color scheme (I intend to make it faded to make regexp more readable).
Is it possible to do this? Preferably it would work in general, but something limited to Ruby also would be highly useful.
It sure is possible!
<dict>
<key>name</key>
<string>Escape character</string>
<key>scope</key>
<string>constant.character.escape</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#F38630</string>
</dict>
</dict>
Actually this is the scope for the escape character along with the escaped character.
Remember you may always find the corresponding scope by moving the caret to the characters and pressing:
{ "keys": ["ctrl+alt+shift+p"], "command": "show_scope_name" }
(You will see the scope key in the status bar).

Highlight Ruby methods and method parameters in different colors in an editor

Is there any editor with any color scheme in which:
BulkMailer.bulk_email recipient, body
bulk_email is highlighted in one color and the parameters are highlighted in a different color. I use Sublime Text 2 and I tried a lot of color schemes but so far none of them does that.
While this works when defining methods (here bulk_email has a different color):
def bulk_email(recipient, body)
# some logic
end
I would like to have that also in method calls. I find this especially helpful, as Ruby allows for omitting the braces around parameter lists and in long lists it's sometimes a little slow to detect where the actual method call ends. As I mentioned, I don't insist on Sublime, any editor is fine.
SynWrite editor (Windows) can do it.
Activate Ruby lexer, goto lexer properties dialog, create new Parser called ".name" to hilite names after a dot with a new color, and set parser's regex.
Result with hilited method name (with my changes in lexer):
Here you go solution for Sublime Text 2
Ruby.tmLanguage (Add)
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.chained.name.function.ruby</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>variable.chained.parameter.function.ruby</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>comment</string>
</dict>
</dict>
<key>match</key>
<string>^.*\.(\w+)(.*?)(#.*)*?$</string>
<key>name</key>
<string>meta.function.method.with-arguments.ruby</string>
</dict>
In your Theme File (default is Monokai.thTheme) (Add)
<dict>
<key>name</key>
<string>Function name</string>
<key>scope</key>
<string>entity.chained.name.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>PUT A HEX COLOR VALUE HERE</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Function argument</string>
<key>scope</key>
<string>variable.chained.parameter</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>PUT A HEX COLOR VALUE HERE</string>
</dict>
</dict>
this will cause the method name to be one color and the argumetns to be another and inline comments to match as comments.
Huge Caveats
This was fun but I don't really feel like exploring further so here are some caveats that could be overcome with a much more complex regex. Highlights the following additional items that are probably not intended by your question.
1.Final Chain Methods Ending in alpha_numeric characters
2.Inline blocks with a space between called method and block
3.Multiline Block keywords and piped variables

Sublime Text - C++ Highlight

How can i make my class be highlighted as a normal primitive type like the int or double?
See a exemple:
I want that when i declare the Test aloha; Test be highlighted of the same way that int a.
The syntax highlighting is controlled by the tmLanguage file. In ST3 these are held in .cache files.
So follow these steps.
Open Tools -> Command Pallet and using Package Manager install PackageResourceViewer
In the Command Pallet select PackageResourceViewer: Open Resource
In the presented panel choose C++
In the presented panel choose C++.tmLanguage
Now you have the language definition file displayed for you.
Have a look at the form of how the parts of a language are defined.
If we search for class we find the following as one of the matches:
<dict>
<key>match</key>
<string>\b(class|struct)\s+([_A-Za-z][_A-Za-z0-9]*\b);</string>
<key>name</key>
<string>meta.class-struct-block.c++</string>
<key>captures</key>
<dict>
. . .
. . .
</dict>
I chose that one because it involves some regular expresssion (regex) matching and that's the hint to do what you want to do.
Because ST has a lovely open framework any of us who know a little programming can add our own language component definitions to these .tmLanguage files. This flexibility is part of why ST is my choice.
So let's see how to do that.
First thing is to save the C++.tmLanguage file we have open in the editor into our User folder.
We do this both to keep the original as a rollback if things go wrong and because it means that our version in User will not get overwritten each time ST updates. The way ST loads files means that duplicates in the User folder overwrite values in the default location so our User versions take precedence in what is running when we use ST. Cool hey?
So now we have our own version of the C++.tmLanguage file let's play with it.
Find a definition that looks a bit like what we want to do and duplicate it.
I am going to copy this:
<dict>
<key>match</key>
<string>\b(class|wchar_t|nullptr_t)\b</string>
<key>name</key>
<string>storage.type.c++</string>
</dict>
First thing I am going to do is decide what I am going to name my new language component.
I could simply give it the name of an existing language component that has the colouring I want to have. This has the advantage that if that name is already in place in the existing colour schemes I will get the highlighting for free. Feel free to make this choice.
But to explore more of the system I am going to invent my own name and scope it to myself. So I will call it duncan.name.class. You can use any name you like that does not clash with an existing name.
So I will make that change in the duplicate:
<dict>
<key>match</key>
<string>\b(class|wchar_t|nullptr_t)\b</string>
<key>name</key>
<string>duncan.name.class</string>
</dict>
Now I need to write the regex to identify my new language component. This is pretty easy since I am going to assume we are all following the fairly standard practice of naming our classes with leading Caps and not using that for other language components so my regex just needs to find any string that starts with an UPPERCASE alpha, which is easily defined as [A-Z] followed by any alphanumeric character/s. Note that this precludes punctuation (like underscore _) so if you use those in your class names you'll need to expand the regex to include those characters.
So let's change the match condition to use that regex:
<dict>
<key>match</key>
<string>\b([A-Z][a-zA-Z0-9]+)\b</string>
<key>name</key>
<string>duncan.name.class</string>
</dict>
Now I have a new language component I need to tell my theme how to handle it. I am going to work on the Amy theme for this example.
So back to the ever helpful PackageResourceViewer like this:
In the Command Pallet select PackageResourceViewer: Open Resource
In the presented panel choose Color Scheme - Default
In the presented panel choose Amy.tmTheme
Now you have the theme file displayed for you.
Again I want to save my copy into the User folder and then duplicate an existing example. I am going to duplicate String but anything that grabs your fancy is fine.
<dict>
<key>name</key>
<string>String</string>
<key>scope</key>
<string>string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#999999</string>
</dict>
</dict>
Now I'll change the duplicate of String to do colouring for my new language component.
<dict>
<key>name</key>
<string>Class Names :: Duncan</string>
<key>scope</key>
<string>duncan.name.class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#999999</string>
<key>background</key>
<string>#FFFFFF</string>
<key>fontStyle</key>
<string>bold</string>
</dict>
</dict>
I hope you recognise the names I am using from the work we did above?
I have chosen a slightly mad set of syntax highlighting preferences just to show some of the options you have available. Knock yourself out playing with ideas here.
Does all this make sense?
With these ideas in place you can fix any syntax highlighting niggles you have in ST3 to work just exactly as you like. Perhaps my regex above is not too great? I didn't think about it a whole lot so you may find you need to do more work there to get just what you want.
Let me know if some of this doesn't make sense and I'll try and do better.
I would also suggest installing the package Scope Hunter, and then enable Toggle Instant Scoper via Ctrl+Shift+P. This'll show you the scope of the element under the cursor.
With this you can see how ST has parsed the file, and use the name of each scope in a theme definition to color elements of different scope differently.

Sublime Text 2: how to change white space characters color?

The color seems to be linked to the foreground in themes. I assume it's using less alpha. Is there a way to control this?
There's now a Sublime plugin for this.
Install the HighlightWhitespaces plugin
Add the following color settings (tailored to your preference) to your color_scheme file. This file ends in .tmTheme and the path can be found by looking at the value for the key "color_scheme" in your settings file.
<dict>
<key>name</key>
<string>highlight.whitespace</string>
<key>scope</key>
<string>highlight.whitespace</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#020202</string>
<key>foreground</key>
<string>#805050</string>
</dict>
</dict>
Specify that this color should be used by adding the following to the user settings of the HighlightWhitespaces plugin:
{
"highlight_whitespaces_space_highlight_scope_name": "highlight.whitespace",
"highlight_whitespaces_tab_highlight_scope_name": "highlight.whitespace",
"highlight_whitespaces_eol_highlight_scope_name": "highlight.whitespace",
"highlight_whitespaces_mixed_highlight_scope_name": "highlight.whitespace"
}
Relax and enjoy :-)
You may want to try installing PersistentRegexHighlight from Package Control and then use a blank-character regex like [\x20 ] to add a specific color or color scope.
You'd want to combine this with drawWhiteSpace: "all", in Sublime user prefs.
You can change the tab underline alpha by changing the foreground alpha.
To change the color of spaces requires changes to every syntax file.
A few years later, I was struggling with this in Sublime Text 3 build 3083. I hope this helps anyone. In addition to Chris Like's suggestion to install PersistentRegexHighlight and setting "draw_white_space": "all" in the user preferences and the pattern to one or more occurances of tabs and spaces, i.e. [ \t]+ in the PersistentRegexHighlight user settings, i had to also also set "color_scope": "highlight.whitespace" and add the following dict to the theme along with the other ones in the settings array:
<dict>
<key>name</key>
<string>highlight.whitespace</string>
<key>scope</key>
<string>highlight.whitespace</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#020202</string>
<key>foreground</key>
<string>#805050</string>
</dict>
</dict>
which by the way oddly only outlines in red if the background is set to black, i.e #000000
Note that this method does not require editing any syntax files.

Resources