Improving development flow and editing with XCode. - xcode

XCode is a little weak in the way that it obliges you to format code, and the restrictions it places on you. I'm thinking of things such as select a block of code and use tab to reposition the whole block, which is very useful for cleaning up indenting, amongst other things.
I realise that I can use an external editor (such as Sublime Text 2, which is superb and my daily editor) to edit code, but I'm wondering if there are any plugins or tools which exist out there which integrate into xcode to improve this development experience.
What kind of extensions exist for xcode, or if there aren't any, are there any lesser-known features which assist in improving this?

It's hard to give you an answer, as we don't know what features you use elsewhere that you think are missing in Xcode. For example, you can move a block of code in or out by pressing Cmd-{ or Cmd-}. Or you can "fix" the indenting by using ctrl-i as jrturton pointed out above. All of the emacs keybindings work. In fact, you should look over the key bindings in the prefs to see what other things are possible. Some of my favorites are:
1) Select a word and hit Cmd-E to make it the search term. Then Cmd-G to find the next instance.
2) F6 to step over in the debugger, F7 to step in and F8 to step out
3) As much as I hate command lines, gdb has a number of useful commands for calling methods while stopped at a breakpoint. You can call any function or C++ or Objective-C method using the call command. (Type help call at the gdb prompt to learn more.)
4) If your index is up-to-date, you should be able to Cmd-click on a symbol to go to it's definition, or option-Click to see its documentation.
Are those the sorts of things you're looking for? If not, please give examples of what you want. As far as I know there is no plug-in mechanism in Xcode 4, so no extensions exist.

Though the first answer is a great one (learned a lot from it), I wanted to add a little hint that helps me a lot when pasting codesnippets. A lot of times xCode copies indentation in a way I don't like and then I have to reindent the whole snippet.
What I started to do is jump to the first char in line (ctrl + a | cmd + ArrowLeft) and either paste the code immediatly, or indent by one or two before pasting, dependend if I'm in a function, loop etc.

Related

Is there a way to properly dump the navigation history in Visual Studio?

Very frequently, I will be looking for a specific section of code where something happens, and will reach there by starting at a function at a high level of abstraction and go lower by successively opening the code of called methods. Eventually I will find what I'm looking for, and I would like to save the path that I took to get there - which is pretty much what the call stack would be if I had put a breakpoint in that code and stopped here at runtime, except that I'm just inspecting the code.
I'm aware the little arrow next to the "Back" arrow lets me somewhat get that in the UI and I can then take a screenshot of what I'm shown, but that's not a fantastic solution. The names of the functions are trimmed (leading to cases where it could match several functions), the line number is seldom shown (only if there was no code at that line), and I would much rather have the text format to begin with so I can copy the function names into a search tool rather than type them from the screenshot later.
So I was wondering: is there a way to dump the navigation history in Visual Studio ?
Where I could for ex. ask for the last 50 cursor positions, and get the file, file path, line number & possibly the code at that line in text format or some more intelligent thing, should the IDE support that.
Thanks.
PS: I found this very similar question Is there extension for viewing navigation history in Visual studio? that's >5 years old and didn't have a satisfying answer, so I'm trying my luck again, hoping things have changed since if there was no solution back then.

VS2015: Can I mark down code?

When I'm working at someone else's code, sometimes it happens that I've found something useful that I likely will need to return later to.
Except the chances are that I forget where I've found that part and then I need to find it again. Nowadays I'm mostly using breakpoints to set these down, But I don't need these breakpoints for debugging, so I don't think that's the most efficient method. Something that could work for me is a sort of marker that functions marking down like a breakpoint, but does not affect debugging.
Will all these ways of breakpoints, search functions, finding references, and adding a Watches. I do have a feeling that such feature is present in Visual Studio already. But I havn't found it yet, I've already tried searching it up, but it looks like it hasn't asked before.
So, is there a feature in Visual Studio that let you mark down code like breakpoints, but just for the purpose of marking down?
There is more than one way to do so.
If I finde something interesting I mark it with a Bookmark.
Just STRG + K, STRK + K and it will be places on your current row.
With these Buttons you can switch to your bookmarks or delete them all. They are client based.
Visual Studio also gives you a "To Do List" Function. This one is triggered by comments in the code and seen for everyone with the right options used.
See here how it works in detail.
Yes, it's called a bookmark. This little toolbar is for bookmarks:
You can also use the Edit, Bookmarks... menu item and the View, Other Windows, Bookmark Window which among other things lets you see all of them and give them names.
One caveat: the bookmark binds to the line number, and doesn't move if you add or remove lines. So if you bookmark the first line of a function, then make changes above that, the bookmark won't be on the first line of a function any more.

What is the keyboard shortcut to type fast in Visual Studio?

I am not sure what is the best way to word my question correctly in single line. But basically I have seen quite a few video tutorials now where the coder types really fast using some sort of shortcut to fill in the automatic text(prolly intellisense stuff) It looks very similar to Linux command line tab where you only type half of your text and when you hit tab it either fills in the gap or show you the remaining options.
Hope that makes sense.
Thanks
Pressing Ctrl+Space completes the current variable/class you are typing.
Typing things like ctor and then pressing the Tab key twice tells Visual Studio to insert a constructor for you. (Also works with for for a for loop, cw for a Console.WriteLine();, etc.)
For a full list, please refer to the official reference from MSDN.
I believe its Ctrl-Space, which is pretty common among most IDE's

What's the point of viEmu plugin for Visual Studio?

This may sound a bit provocative but it actually is a real question. Feel free to edit if you don't like the tone.
Now, as much as I understand vi from my short experience with it like 10 years ago, it's a primitive text editor with one editable line at the bottom of the screen created before the scrollbars were invented, with some crazy shortcuts to overcome this limitation.
Can somebody explain me how one can be more productive with it than with, say normal VS.NET editor? Moreover, why would anybody want to use viEmu which supposedly turns your VS.NET into an ancient vi?
I'm willing to give it a try but I need some motivation to overcome the learning curve.
It honestly sounds like you have never seen someone use Vi who is truly proficient in it. When you normally use Visual Studio you frequently will move your hand over to your mouse, click through options, dialogs, classes, etc.
With ViEmu your hand never leaves the keyboard. You are compiling, switching files, highlighting groups of text, fixing indentation, performing complex motions on your code and running regular expression searches in seconds. For people who are fast typists it allows you to achieve a speed for tasks you would not be able to otherwise.
Many people will counter this by saying things like, "Most of my development time is spent thinking. The extra speed I gain from using tools like these is negligible.".
That is a non-argument in my opinion. It is true, for most large programming tasks you spend far more time planning and thinking then you do actually slinging code. But that doesn't mean that being able to express yourself through your IDE 2x faster doesn't have an impact on your productivity as a programmer.
The viEmu page itself has a pretty good article that might help to answer your question: Why, oh WHY, do those #?#! nutheads use vi?
I've spent the last couple months trying to teach myself to use vim "properly" and now I can hardly stand using other editors because they seem underpowered and clunky. For a random example, imagine you have a line of code that looks like this:
$welcomeMessage = "Welcome to SiteName!"; // shows at the top of homepage
In a normal editor, how would you change the string? You'd probably have to reach over and grab your mouse and carefully select it, or you'd move your cursor inside the first quotation mark, and hold down Shift and the right-arrow until you got to the closing quotation mark.
In vim, with my cursor anywhere in-between the quotes, I type ci" and it erases everything inside the quotation marks and puts me into insert-mode so I can type the new value I want. My hands didn't even have to move from my normal typing position.
There are so many things like this, I think you really have to spend a while using the editor to understand how powerful it is. It's very slow and hard to use at first, that's why a lot of people try it for a short time and think "this is dumb, everything is way harder", but after a while you start thinking in terms of the motions, it all starts to become automatic and it's much, much faster than using a "normal" editor. As I said, I can't go back now.
I've also had trouble understanding why people choose vim as their editor, even though I was using it from time to time, until I've finally "got it". I think most explanations of "why?" fails, because they fail to show couple crucial points. To explain those points, first you need to understand that in vim you are manipulating text primarily being in command mode. Ie by default your key presses are commands, and do not usually insert any text, unless those commands (like append, insert, change) switch to insert mode. This lets you navigate and edit your text easily without ever touching your mouse or moving your hands away from "editing pose".
Now the crucial points are:
Vim commands are divided into nouns, verbs and modifiers.
Editing is performed by combining them.
And this is what gives vim the power. To ilustrate the point, here are some most used commands:
Nouns: word, sentence, block, quotes and braces.
Verbs: cchange, insert, visual, delete
Modifiers: inside, around, till
And to ilustrate how you can mix them:
Want to change a word? cw
Same, but cursor in the middle of the word? caw
Change text inside quotes? ci", also change quotes? ca"
Delete function body? di{
Delete up till first comma? dt,
Delete up till second comma? d2t,
Jump to first comma? t,
Select word? viw
Also notice how all commands nicely translate into natural language:
delete word
change inside {
In vim if you learn a new verb, noun or modifier, you can easily mix and match with what you already know. So basically learning just one thing, you learn how to do a lot of different things.
Another great thing is that vim remembers what commands you have used, and you can repeat the sequence just by pressing .. For this post I've had to surround a lot of letters with <kbd> tag. But I've did that only once, and then just went over each letter and pressed ..
And that's basically the thing you "need to get" to understand the power of vim and become advanced user overnight.
P.S. if you don't like vim because it's console based and want a modern text editor, then I suggest looking into Sublime Text editor, which is a great editor and also supports vim mode.
P.S.2. I also recommend to map Esc key to jj and kk, which makes things a lot easier.
You are wrong about "one editable line at the bottom of the screen." All the text in the window is editable. And it does scroll (all versions) and in the case of gvim, has scrollbars.
Maybe you inadvertently put it in "ex mode". This is easily done and can be confusing.
Another answer got me thinking that watching some skilled editing using vim would be pretty revealing so I dug up this video showing basic and more advance motions while coding. This person could get even a bit efficient using some marks, etc but it gives an idea.
http://www.youtube.com/watch?v=FcpQ7koECgk&feature=related
If you need inspiration or want to see someone who really knows what they are doing with Vim, check out Gary Bernhardt's String Calculator Kata In Python, look at him go! http://vimeo.com/8569257
I think they have a long and acceptable answer for your question on the viEmu hompage:
One other even more powerful example: let's take the 'ce' command, which is composed of 'c' and 'e'. The 'c'hange command deletes the range specified by the next motion command, and also enters insert mode. It's the same as 'd', but with the distinction that it enters insert mode, instead of staying in normal mode. The boon is that the text you type in the next (short) input session is also part of the command. So if you do 'ceHello>', what you do is replace from the cursor to the end of the word by 'Hello', and the '.' command afterwards will work exactly like that: replace up to the end of the word with 'Hello'.
From:
http://www.viemu.com/a-why-vi-vim.html
I have viEmu installed ~half year ago. But I have to say (maybe without strong linux experiences) I've never used it. Too alien, too far, too complex.
So IMHO viEmu it's a great technical&historical challenge but no more for the 95% of the developers.
Basically with Vi (or ViM) you get faster because you don't need to touch the mouse and the key-map is improved (this represent learning curve cost but worth the effort) for do any text manipulation in a very easy way once that the fundamentals are learned.
Top 10 things Vi user need to know about Vim
I have not experience with VS.Net but I guess it has the same features that any other IDE has.
I have found that learning the all the key commands of the editor in my IDE was a sufficient replacement for Vi. Things like renaming, indenting, formatting, moving lines and that kind of stuff.
So I guess the major win would be for someone who already know Vi to be productive without having to learn VS.Net.
But then again, Vi has some truly esoteric but powerful features that probably can't be matched by you standard IDE editor.
I think you really should give Vim a try.
If you quickly tried Vi ten years ago, I may understand you didn't appreciate it. It's not really user-friendly at first sight. Actually its real power is revealed when you start feeling comfortable with the movements and start making it your own with customisation.
Once Vim is familiar to you you may understand why it deserves to be learnt.
I actually use VS only for debugging these days. Coding with vim (real vim, not viemu) is just a better experience.
Now, I am not going to claim that using one over another makes any difference in productivity - after all I spend most of my time trying to figure out how to solve a problem - entering the code is the easy part.

What is the most efficient way to cut/paste in Visual Studio?

I find that I am cutting and pasting a LOT when I program. For example, method, variable and class names are things I regularly cut/paste. I do use "ctrl+space" after typing part of a word to autocomplete them or popup intellisense when there's duplicates found.
But just for straight copy/pasting do you guys have any good shortcuts/tricks/tips to use?
I already use these shortcuts as I program but I wonder if I am missing anything?
ctrl+x (with nothing selected)
ctrl+v (with nothing selected)
ctrl+l (with nothing selected)
ctrl+shift+arrowKeys
If I could copy/paste quicker I think I'd be able to write code quite a bit faster.
In Visual Studio has multi-paste.
pressing Ctrl+Shift+V allows you to paste any of the 10 last things you cut/copied.
Install and learn ViEmu.
I have more of a hardware solution. On my MS 4000 keyboard I have the back and forward buttons right under the space bar bound to copy and paste respectively. This actually makes copying and pasting much easier than I thought it would when I first did it.
I use ClipX, which gives you system-wide multi-paste. You can paste any of the last [configurable number] of things in your clipboard. You can also save "favourite" items, which stick on the list forever.
Shift + Page Up/Down to select everything below/above the cursor.
If you're not using ctrl+shift+arrow to select whole words/lines, then that can help a lot.

Resources