View Full Version : XCode - 1st day, duplicate line?
whitehexagon
May 21, 2009, 11:18 AM
I've finally given up on Java on OSX! So today I'm getting started with XCode :)
I've typed two lines from an example and already I'm struggling for keyboard shortcuts. Is there a cheat sheet somewhere?
Specifically I'm looking for key combination to duplicate a line downwards.
kpua
May 21, 2009, 11:48 AM
All of Xcode's key bindings are configurable in the preferences. I didn't see any text key bindings for copying a line, but you could easily make a script for that, I think, and define your own key binding for it.
whitehexagon
May 21, 2009, 12:09 PM
you'll have to go a bit slower for me :)
I found the bindings and can duplicate the set, and change bindings. I can find where to add a new binding. From system preference it's only adds new bindings for existing menu items. How would I add such a script that you mentioned.
ChrisA
May 21, 2009, 12:22 PM
...I'm looking for key combination to duplicate a line downwards.
How about command-C "copy" and then command-V "past" as many times as you like? That's what I use.
whitehexagon
May 21, 2009, 12:35 PM
I'm coming from an eclipse background, and it's just something I've really gotten used to. It's not just cmd-c cmd-v, but also: move to start of line, select to end of line, copy, right arrow, return, paste.
delete line is the next challange. If I can add some more shortcuts via scripts or macros then that would be perfect :)
kpua
May 21, 2009, 01:44 PM
Don't look in System Preferences. Look in Xcode's preferences. (Under the Xcode menu, not the Apple menu.)
To create your own script, open Xcode's menu that looks like an unfurled scroll and choose Edit User Scripts. In there you can use just about any shell script you want. There are special variables that are set, but I'm not super familiar with it. Search for "user scripts" in the Xcode help to get more info.
lee1210
May 21, 2009, 02:08 PM
I know saying "write some code to help you write code" isn't that helpful, but i wrote some things to deal w/ XCode and posted them here:
http://forums.macrumors.com/showthread.php?t=558113
It's more involved than you need, but there's a link to a helpful page in there.
-Lee
whitehexagon
May 21, 2009, 02:52 PM
well the above tips eventually led me to the following site
http://flexgraphix.com/blog/?p=62
Which uses a key binding file. I think I need to reboot before it will pick it up, but it looks like a simple way of adding any number of my missing keys simply.
Thanks All!
autorelease
May 21, 2009, 05:10 PM
I'm coming from an eclipse background, and it's just something I've really gotten used to. It's not just cmd-c cmd-v, but also: move to start of line, select to end of line, copy, right arrow, return, paste.
delete line is the next challange. If I can add some more shortcuts via scripts or macros then that would be perfect :)
Control-A moves cursor to start of line
Shift-Down Arrow selects entire line
Command-C to copy
Down Arrow
Command-V
Not as fast as yyp in vim, but I've gotten used to it. :)
whitehexagon
May 21, 2009, 05:13 PM
well i tried a reboot and that didn't pick up the key bindings, gonna have to try again tomorrow, I hate having to reboot these days, oh the joy of being a switcher :)
sure I can do this manually, but when you are used to a single key cobination it's really hard to go back. Actually I'm suprised at a few things like this that seem to be missing in XCode that most others editors I use have. Maybe I just need to explore it a LOT more yet
HiRez
May 21, 2009, 06:04 PM
Yeah, explore a little more, but if it turns out you just hate Xcode as an editor, you can designate any other app (I think including command-line ones) as an external editor for text (code) files, and still use Xcode to organize and compile your project. Normally rebooting isn't required on OS X unless you're installing or modifying a kernel extension, or installing an OS upgrade, obviously.
dejo
May 21, 2009, 06:10 PM
Specifically I'm looking for key combination to duplicate a line downwards.
I'm curious. How often are you doing this? I'm not even sure that kind of coding approach should be encouraged. ;)
whitehexagon
May 22, 2009, 04:08 AM
I haven't got as far as the chapter on loops ;)
Well I've tried a couple of combinations to get this working, but no luck so far. I had some system prefs custom key bindings which I've now restored to default. But PBKeyBinding.dict and DefaultKeyBinding.dict just seem to be ignored.
I'll post back if I find a working solution.
whitehexagon
May 22, 2009, 04:47 AM
ah, finally it's working!
http://www.nullstream.com/archives/000624.html
This is good because it's only affecting XCode.
Next job code completion, and custom macro expansion on code complete... yes I am missing eclipse a little!
buckyballs
May 22, 2009, 06:02 AM
http://www.1729.us/xcode/Xcode%20Shortcuts.png
Googling "Xcode cheat sheet" works wonders
dejo
May 22, 2009, 11:00 AM
Next job code completion...
Look into Code Sense then, Xcode's built-in code completion feature.
iSee
May 22, 2009, 01:02 PM
General (Unsolicited, sorry :)) Advice:
Don't try to turn your current IDE/editor/tool into your last IDE/editor/tool.
Work with your new IDE and develop a workflow that takes advantage of the features it has rather than trying to impose the workflow from your old IDE on to it. (After all, that's probably how you developed your old Eclipse workflow, right? -- By getting to know Eclipse and working with what it gives you?)
If you focus on what xcode lacks that eclipse has, you'll miss what xcode has that eclipse doesn't.
As you get used to xcode, including its quirks and deficiencies, the things that seem almost unbearable about it now will not seem like such a big deal after a while. Some things you may even come to appreciate.
Confession :D: despite what I just said, the one thing I cannot stand and cannot get used to about xcode is the way the editor jumps half a page when you cursor past the first or last displayed line in the editor.
whitehexagon
May 23, 2009, 01:35 PM
Generally I agree, but things like kill line, move line, scroll, and duplicate line are such basic features of text editors , it really feels like a step backwards.
Code sense is looking very promising though, and I like the Research assistant already. And SVN was a lot quicker setting up than the mess involved with eclipse.
lee1210
May 23, 2009, 02:29 PM
I know this is sort of off-topic, but i contributed an on-topic comment earlier, even if it ended up not being super-helpful.
This thread is the reason I advocate vi(m). Code completion is great, and is the only reason i'd ever use an IDE, but with vim it's easy to move from language to language, and not have to change editors. All of these features are there and many more.
Kill line: dd (Places line in buffer, in case you want to put it elsewhere)
Kill many lines: #dd (where # is the number of lines you want to delete)
Move line: dd #G p (where # is the line you want to move it to, you can manually navigate there, too)
Scroll: how much? =)
ctrl+f page forward
ctrl+b page back
ctrl+d half page forward
ctrl+u half page back
j one line down
k one line up
#j or #k move # lines up or down
I'm not saying it's the right choice in this scenario, but I'm always more comfortable in vim than Eclipse/XCode/Netbeans/VS/etc. when it comes to the actual editing of text.
-Lee
whitehexagon
May 24, 2009, 03:10 AM
After many years as a plain editor hard core user, the feature that really convinced me to adopt an IDE was code completion. Then I really got hooked on being able to see at edit time any compilation errors, another great productivity enhancer! I know real programmers don't needs hints from an IDE, but I don't have the brain capacity or patience to memorise these huge API's that come bundled with most languages these days :)
So overall I'm convinced IDE's are worth the learning curve, because the longer term productivity gains more than cover the initial pain. That's why I'm not trying to use eclipse to write objective-c but instead using the tool that is designed for the job. But I'll reserve my final judgement on XCode for a few weeks. Or maybe Apple will release a decent update to Java at wwdc and I'll be back on eclipse :)
Thanks All.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.