How to make xCode "act" as the most normal editors? - xcode

I wonder, why doesn't xCode "act" as a normal editor? For example, when I press Ctrl+X, I'd like the current line to be copied-cut. When I press Shift+Tab I'd like the current selection to be shifted to the left, etc. That's the stuff most editors do by default.
How to make it do that?

Take a look at Preferences -> Key Bindings. Here you get a list of actions and their keyboard shortcuts - and you can change those keyboard shortcuts!
It's quite amazing how many actions there are, including a great number of familiar Emacs actions such as mark and yank. Many of them have no corresponding menu item; many of them have no keyboard shortcut by default. Some of them may be the things you are looking for, and all you need to do is change the shortcut if you don't like it. It is very possible that you'll find at least some bindings that you can use to make Xcode behave in a more familiar way.

Related

Keyboard shortcut to select editor tab by number in XCode

Is there a way to select a tab by ordinal number - like in browsers? In particular something like Control-1/Control-2 or Alt-1/Alt-2 to select one of the two tabs presently displayed.
Note that even the command-{ and command-} are not working for me.
Therefore even the less preferable approach of cycling through the tabs - as shown in a couple of questions such as this one https://apple.stackexchange.com/questions/85461/programmer-new-to-apple-how-to-efficiently-switch-between-files-in-xcode - do not work. So presently there is no way to switch tabs except by physically clicking on them.
A quite acceptable alternative would be a keyboard driven quick-list like Command-E in JetBrains IDE's (intellij, pycharm, AppCode, etc)
This is not an answer to your real question, which is a great idea — the answer is no, there isn't. (File an enhancement with Apple...!)
However: The keyboard shortcut for toggling to the next tab is Control-Tab, which I find quite easy to remember.
Also note that all keyboard shortcuts are user-configurable.

Is there a way to jump to the target/scheme selection menu in Xcode?

I know the keyboard shortcuts for most things I often do in Xcode, but there is one thing I still haven't figured out:
How do I switch the active target/scheme without using my mouse?
I can switch from the previous and next scheme by using CTRL+COMMAND+[, but I would really like to expand the menu and type the scheme I want, similarly to how I can expand the methods navigator with CTRL+6.
Ctrl+0 will show a list of schemes. Then all you need to do is type a name of a scheme and hit enter.

how to come back when you are reading code in Xcode?

I have been developing in zend studio and there is a feature I miss a lot in Xcode. When you are reading code in a main function and you want to go in a specific function to read something, you can click in the left area of your current line of code were your are, and a flag-mark appears in that line of code, so you can go anywere else in the code and it will be very easy to come back to that line of code you were before because there is a flag and you only have to click on it and you automatically go back. Does Anybody know a similar way to do this in Xcode?
Unfortunately, this feature was present in earlier versions of Xcode (up to Xcode3 IIRC) and was called "Bookmarks", but it was removed since then.
You can use breakpoints (and disable them) as a workaround, even if it's not perfect. I personally prefer using other tricks, like "Open Quickly" and named tabs.
Alternate trick 1 : "Open Quickly"
One trick is to use Command+Shift+O (or "File" menu > "Open Quickly") to quickly open a file. In the field that appears, you can type:
The name or parts of the name of a file.
Typing "MainViewController" will propose to jump to the MainViewController.h or MainViewController.m file.
Typing "MainVC" will work too, as well as "MainViewCtrl", as long as the order of the letters you type is the same as the full name.
Very handy to just type "ContTVCell" to open the ContactsTableViewCell.h file that is hidden deep in subgroups of my project for example
Similarly, you may also type the name or parts of the name of a symbol, especially a method name.
For example, typing tvcellforrow will list you all the definitions of -tableView:cellForRowAtIndexPath: it could find in your project and let to jump to the one you want
When typing (parts of) the name of a file, adding : followed by a number at the end will allow you to directly jump at the corresponding line
For example, typing mvc:50 will propose you to jump to line 50 of MainViewController.h or MainViewController.m
Another trick : using (named) tabs
Don't forget that you can open tabs in Xcode, which can be very handy in this kind of situation.
When you are editing a file at some interesting position, you can create a new tab to browse elsewhere and go at any other place… and then go back to your first tab to find the code where you left it at the time you switched to the other tab.
Don't forget that you can name your tabs (simply double-click on their title) to give them a more explicit title. You may then quite think of them as "named bookmarks" somehow
Likewise, don't forget that you can detach tabs in separate windows too, if you prefer (for example to keep them around and visible on your secondary screen while you edit another part of your code)
You can even combine this with the "Open Quickly" trick presented above: once you made the "Open Quickly" field appear and typed something into it, instead of just validating using the enter key:
use Alt+Shift+enter to let Xcode present you a small widget that let you choose where you want the file to open (in the current tab, in another tab, in the assistant editor, in a dedicated window…)
use Alt+enter to open the file using the alternate navigation defined in Xcode preferences (Xcode > Preferences > Navigation > Optional Navigation). By default, the behavior when opening a file while using the Alt key is to open the file in the Assistant Editor. Personally I changed that in my Xcode preferences as I prefer to make Xcode open the file in a separate tab instead, which makes Alt+clic much more useful.
Sure, all those tricks with "Open Quickly…" and "Tabs" do not replace the bookmarks feature that you are missing. But they are still nice alternate ways to jump quickly to any position in your code, even any specific line of any specific file in your project, wherever you are in Xcode (even without having to have the Project Navigator visible on the left part of your window), and let you have multiple editors in different tabs to go quickly back to a part of interest in your code
its on top of your editor i have added two pics just check them.
When you navigate to another place in Xcode, say, open a different file, or Command-click and jump to definition, you can go forward and back by swiping right or left on the trackpad with two fingers.
You can also use keyboard shortcuts: Ctrl+⌘+→ to go forward, or Ctrl+⌘+← to go back.
Finally, you can click triangular buttons at the top left in your edit area.
There is a go back button at the top left of the editor!
If that is not good enough, whar I do is misuse breakpoints to set flags in my code. The breakpoint navigator thus becomes a table of flags. It isn't much but there you are.

Is there a way to make alt-f and alt-b jump word forward and backward instead of printing ƒ and ∫ on Mac?

I understand that Mac has some Emacs keybindings enabled by default (e.g. Ctrl+A move to beginning of line etc.). If I open TextEdit for example I can navigate like in Emacs.
But when I try Alt+F or Alt+b for move to next word or last word it does not work. It prints out ƒ and ∫ instead.
Is there a way to jump words instead?
I think that I did not tinker with the keybindings and I use the US layout on a german keyboard.
If you want to re-enable them for the terminal
Terminal -> Preferences -> Keyboard
Check 'Use Option as Meta key'
my iTerm2 version is 3.1.6, profile -> keys -> set Esc+
Maybe one of these helps? (I don't use OSX myself, so I can't test anything).
http://blog.sensible.io/2012/10/19/mac-os-x-emacs-style-keybindings-everywhere.html
http://aufflick.com/blog/2006/01/10/emacs-keybindings-everywhere
Summary from first URL:
Create file ~/Library/Keybindings/DefaultKeyBinding.dict with the following content and restart all apps.
{
"~d" = "deleteWordForward:";
"^w" = "deleteWordBackward:";
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
}
I'm a little confused if you're talking about the keys (within different apps on OS X) or specifically Emacs. On OS X the standard keys you would use to jump between words is:
option/alt + Left Arrow or Right Arrow
If it's specific to Emacs for OS X:
For Terminal.app, starting from Snow Leopard: Go to Preferences > Settings > Keyboard > Use option as meta key.
For iTerm: Go to Manage Profiles > Keyboard profiles > (your profile) > Option Key as…
If you want to use Option key for both international characters and
Meta key in Emacs, see info below for iTerm 0.10.x patch and/or binary.
Alt-b and Alt-f for navigating by word also works for your shell now.
UPDATE: The link the original website providing the patch is no longer online, however I was able to retrieve the cached information from the archive.org:
OSX + terminal + Meta key + national characters
Quite a mix, right? If you’re user of one of those keyboard layouts that have hidden some non-ISO1 characters under Option-key shortcuts and you use command line – read on, I might have a treat for you.
As it stands today, if you’re OSX user, and would like to use your Option (Alt) keys for both national characters and Meta-* shortcuts, you’re in for an unpleasant surprise – you can’t. It’s one or the other: both iTerm and Terminal.app allow you to flip between Option keys role, but neither of them allows you to use Option for both. Under Linux, it’s customary to use left Alt for Meta-* and right Alt for any national characters you might require. Same goes for Windows. Of course you can just train yourself in using ESC key in a prefix manner, but that’s avoiding the real problem.
Getting annoyed by this state of things, and faced with some Emacs usage, I decided to take advantage of the fact that iTerm is opensource software, and see if I can make a tiny change, to cater for my needs. Surely enough, after ~25 minutes I got a trivial patch: just changed the mask that iTerm uses for detecting that Option key is pressed down. It took few hours and 5 chapters of Cocoa book, to turn that into fully-fledged option in Keyboard Profiles section of iTerm. This was my first foray into lands of Objective C; while I came back victorious, I don’t see myself writing anything bigger in Objective C in nearest future.
Here’s the meat: ( https://sourceforge.net/p/iterm/patches/44/ )
“right Option is Normal” patch;
full patch allows you to pick which keys should be treated as Meta (both, only left, only right);
The patches were made against 0.10.x branch, at revision
1871.
Once you have the binary, launch it and go to Bookmarks > Manage profiles > Keyboard profiles. If you select a keyboard profile, you should see a new dropdown at the bottom of the keybindings list.
The options should be pretty much self-explanatory. The configuration shown above is the one I’m using — this way I get all Meta-* shortcuts with my left Option key, and all Polish characters with right Option key. Which is the way it Should Be™ :)
I haven’t heard from iTerm authors yet, so I have no idea whether this patch is going to merged upstream or not. I’ve been using my patched version for almost week and a half now, and nothing major exploded. Yes, iTerm is slower to redraw the screen on larger terminals (say, 130×80), but there are certain features (like 256 colors support) that make up for that.
more info: http://www.emacswiki.org/emacs/EmacsForMacOS
On iTerm2 3.0.15, go to:
Preferences -> Default -> Keys tab ->"Left option() key acts as:"
and change the value to:
+Esc
Solved this at the OS level as follows,
⟶ System preferences
⟶ Keyboard
⟶ Input Sources Tab
⟶ + at bottom left
⟶ Others in the left panel
⟶ add and select Unicode Hex Input from right panel
 ✓  Mac no longer prints anything on alt+letter|number
 ✓  enter unicode characters via alt+[code]
 ✅ the OS does not grab alt key shortcuts!
You should use KeyRemap4MacBook. In the Emacs Mode section, you will find numerous options to use the Option key as Meta including Option+BF to Option+Left/Right.
However, if you're a hardcore Dvorak user like myself who wants to use key bindings such as M-b and M-f using the original Dvorak layout, there's a problem. You can only "move backward/forward one word" in QWERTY layout. I use version 8.4.0 so I don't know about the latest version for Mavericks.
I use BetterTouchTool. Works like this:
Basically remaps Option-F and Option-B to Option-Right and Option Left, and I turned this on for any apps that I want the shortcut in, e.g., Firefox, Obsidian, Slack. Works great!
For Hyper you can fix the option key by setting the following configuration to your ~/.hyper.js file:
module.exports = {
config: {
modifierKeys: { altIsMeta: true }
}
}
source

XCode 4 -> Quick way to jump (or switch) to super class

If we press ctrl+command+up arrow we switch between file code and header code. (.m to .h)
If we press ctrl+command+j or command + mouse click we jump to definition of variable. But it not work for super.
So, there are a fast way to do it?
I'm a little late to the party, but here's a good method for seeing both superclasses and subclasses. Click on the related files icon. It looks like this: and you'll find it in the upper left of the edit window. You'll get a menu of many kinds of related files among which will be the superclass and subclass lists.
You can also open that menu using Ctrl+1, if you happen to be a keyboard person.
Try Command + Shift + D. Jump to definition. Does that work?
Also check out the link bellow. It lists a bunch of Xcode keyboard shortcuts.
http://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/xcode_help-command_shortcuts/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40010560-CH1-SW1

Resources