XCode - 1st day, duplicate line?

Discussion in 'Mac Programming' started by whitehexagon, May 21, 2009.

  1. whitehexagon macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #1
    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.
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    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.
     
  3. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #3
    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.
     
  4. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #4
    How about command-C "copy" and then command-V "past" as many times as you like? That's what I use.
     
  5. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #5
    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 :)
     
  6. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #6
    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.
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    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
     
  8. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #8
    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!
     
  9. autorelease macrumors regular

    Joined:
    Oct 13, 2008
    Location:
    Achewood, CA
    #9
    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. :)
     
  10. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #10
    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
     
  11. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #11
    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.
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    I'm curious. How often are you doing this? I'm not even sure that kind of coding approach should be encouraged. ;)
     
  13. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #13
    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.
     
  14. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #14
    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!
     
  15. buckyballs macrumors regular

    Joined:
    Dec 22, 2006
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    Look into Code Sense then, Xcode's built-in code completion feature.
     
  17. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #17
    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.
     
  18. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #18
    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.
     
  19. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #19
    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
     
  20. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #20
    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.
     

Share This Page