views:

4612

answers:

60

Please read the full question before posting. It's not that long.

As Jeff Atwood noted, we are typists first, programmers second. Fast typing and editing may not be essential to be a good programmer, but it certainly helps. I noticed that I consciously and subconsciously use various tricks to get my intent across to the computer as fast as possible.

What tricks can be used to type and edit code faster?

I'm hoping to collect a nice list here that we can all learn from, so that we can be ever so slightly more productive. One trick per answer please!

This is not about typing speed in general. There are other questions about that. It's also not about general answers like "learn your editor's shortcut keys". Think of this topic as micro-optimizations for specific cases. See my own answers for examples of what I mean.

(Are you coming here from TDPE2? you want to go here)

+40  A: 

When pasting with the mouse, work backwards through the line.

Suppose you have a line like this:

foo(x, y, z);

and you want it to look like this:

foo(bar.x, bar.y, bar.z);

If you paste the bar. with the mouse (either middle-click on *nix, or click and Ctrl+V), it's faster to start at the back. That way, the next location where you want to paste does not move, so you can go there faster.

Thomas
This was accidentally edited to be identical to a different answer; I rolled it back. Don't know which answer the upvoters saw...
Thomas
This is a great trick for applying edits to *any* sort of work from hardcopy. Work backwards and your line numbers / column positions (for soft wrap) won't change!
Matt B.
After pasting, the cursor would be after the dot in "bar.", which means you'd need to move your cursor more spaces to the left to paste the next "bar."
AngryWhenHungry
is it in poor taste to add vim alternatives to these? from the start of the line: "f x i bar. [escape] f y . f z ." find x insert 'bar.', find y do the last thing again, find z do the last thing again
Andrew Khosravian
+7  A: 

When pasting with the keyboard, work forwards through the line.

Suppose you have a line like this:

foo(x, y, z);

and you want it to look like this:

foo(bar.x, bar.y, bar.z);

If you paste the bar. with the keyboard, then navigate with the arrow keys to the next location, it's faster to start at the front. For example:

foo(bar.x, y, z);
foo(bar.x, bar.y, z);  // and so forth

Otherwise, you have the newly pasted bar. to navigate over..

Thomas
Meta link discussing duplicate creation: http://meta.stackoverflow.com/questions/49355/edited-so-community-wiki-answer-yet-new-answer-created
Michael Petrotta
Yeah, it was me. The two answers looked so much alike (of course, I failed to read the titles) I thought I was crazy.
dboarman
+10  A: 

When one hand is on the mouse, use Enter on the numpad.

When my left hand is on the left side of the keyboard, and my right hand is on the mouse, I sometimes hit numpad Enter with the thumb of my right hand. This only works if you use the mouse with your right hand and have a relatively low keyboard (mine's a Logitech UltraX).

Thomas
I don't really see the potential. As a typist first, this doesn't seem ideal - unless I'm not using my mouse the correct way.
dboarman
@dboarman: What do you do with your thumb when you're using the mouse? Not much. You can very easily hammer on the numpad-enter with it.
Rubys
I do my work on laptops mostly. This doesn't work well. ;)
JUST MY correct OPINION
@dboarman: Sometimes the mouse *is* the fastest way to get your cursor to a remote spot in your code. Actually, this one is so ingrained that I know that I use it, but I don't know when. I'll keep an eye out for it :)
Thomas
@Thomas:...unless you use Vim :). There's always a few strokes combo which gets your cursor where you want it.
slacker
@slacker: Stop rubbing it in, dammit! Now I've closed my trusty old Kate editor and launched a terminal with vim! I managed to learn dvorak, so how hard can an editor be?
Thomas
I use a trackball not a mouse, and I keep my trackball positioned so I can do this. Not as useful with a mouse I would think.
drawnonward
How much time are you saving?
kirk.burleson
+23  A: 

Keep line endings in mind while cutting and pasting.

Treat newlines as normal characters when cutting and pasting. When cutting and pasting one or more full lines, include the final newline, so you don't have to remove it in one place and re-add it in another.

Thomas
So many programmers ignore this one. I have always done it, and I can't seem to figure out why it's not more common.
MJB
For me, pasting several lines onto the end of an existing line just seems wrong, I always like to insert a new line to paste code onto.
MiffTheFox
Also, I want to add that you should also look out for tabs, unless you're using an editor like Visual Studio that reformats code on pasting.
MiffTheFox
If you're using vim you can type `dd` to take out entire lines, including the newline. Or you can use `V` to enter "Visual Line" mode which lets you select only entire lines.
Martinho Fernandes
The one good thing about most MS software is that you can click in the margin and select the whole line, including the line ending. I've yet to find an editor on Linux that does this, so I end up selecting backwards to get the newline before.
DisgruntledGoat
@DisgruntledGoat: `Shift+V` in vim goes to visual line mode. Although for single lines, you'd normally use `dd` or `yy` to cut or copy the line, respectively. (Yay, I'm learning vim!)
Thomas
@Thomas: oh, and vim lets you select a line with a single mouse click? Thought not. Sure, in any editor you can come up with a combination of keys to select a line. Holding Shift then pressing End and the right arrow will do the same thing. If I'm not mistaken, the question is about saving time.
DisgruntledGoat
+1. I cringe when I see people mess up code indentation for not moving the caret to the beginning of the line before cutting/pasting multiple lines.
Daniel Liuzzi
+10  A: 

Use Das Keyboard Ultimate.

It will help you look more at your screen and less at your keyboard.

Keyboard with blank keys

robsn
I haven't looked at my keyboard in ages. Getting an unlabelled one just seems a bit ... quirky.
JUST MY correct OPINION
After getting one I realized I had looked more on it than I thouht I had. Especially when it came to special chars or shortcuts. But true. If you're already an advanced typer you probably don't profit too much except for the great look and feel.
robsn
That is a horrible classic-keys keyboard.
Lo'oris
Or, just peel the stickers off your current keyboard.
DisgruntledGoat
Mine got unlabeled on the sweet spots by heavy use....still a few years left to unlabel the rest of it.
Marek
This is the keyboard equivalent of training wheels on a bike. Just ride the damn thing.
rjh
This is the greatest keyboard in the world. If you do not have one you will not understand. That is all.
Sam Pearson
I don't really look at my keyboard anyway - why would I pay 100 dollars for something that removes functionality? Sometimes I don't remember which / or * key is which on the numpad. A quick look is worth it then.
Andrei Krotkov
I don't think it was meant to be serious. Funny though :)
PP
It's also great fun to simply exchange the locations of keys.
Christian
Also worth to mention that, on the occasions you do need to look at the keyboard, you're hosed. Perhaps your wife needs to type a quick letter? Perhaps we don't have multiple machines lying around the house? Perhaps you can't type from memory a long password?
Adriano Varoli Piazza
How many people have to count the function keys to find the correct one?
kirk.burleson
A: 

Learn the hotkeys and shortcuts, all of them -- even the ones you're sure you'll never need to use...

...you will someday, and you'll be prepared.

Andrew Heath
No you won't. The ones you never use, you will have forgotten by the time you want them.
Conrad Albrecht
This is pointless. These things work on muscle memory. If you'll never use them, you won't remember them.
Rubys
It is much more important that you take the time to learn the shortcuts you will be required to use *often*. You will be wasting *any* time you take trying to learn shortcuts you don't think you'll ever use.
dboarman
If you have to fetch a keyboard shortcut from the depths of your memory, you would be better not memorizing it and just using the mouse. Like Rubys said, keyboard shortcuts are only "shortcuts" if they work on muscle memory.
Martinho Fernandes
I think perhaps this should be rephrased - you should be aware of the existence of all of the shortcuts, even if you don't use them, since one day you might have to do something repeatedly and if you know there's a shortcut for it, you can look it up.
Daniel I-S
I agree with Daniel I-S that it's good to know a lot of the capabilities of the tools. For example, I printed out :h index.txt of vim, about 18 pages I think, and went through that list putting a tick in the margin if the feature sounded good and then incorporated some of those in my daily editing, just a couple at a time.
Heikki Naski
+12  A: 

Using IntelliSense or the equivalent always helps speed up coding.

ing0
It's a good thing the use of Intellisense is default *(we hope)*.
dboarman
Maybe he means features like Snippets, which not everyone uses.
Mathias
I mean more along the lines to speed up coding. For example in VS when you write "Cons" if you press Alt + Right it will complete to "Console" or if you write "Console.Wri" then Intellisense will pop up and you can press space to complete with what it thinks you want to write. If you get used to this you can write lots of code pretty fast.
ing0
ctrl+space is easier to hit I think than alt+right
BlueRaja - Danny Pflughoeft
I think it's just what I'm used to! I develop both .NET and iPhone so sometimes it's Alt + Right and sometimes it's just tab! :)
ing0
+6  A: 

Set up keyboard macros for your commonly used patterns.

In Visual Studio I use Ctrl + ALT as a base.

Ctrl + ALT + i - if () {} else {}
Ctrl + ALT + f - for (;;) {}

I omitted the line breaks above.

EvilTeach
Or just type `for` then press `TAB` twice.
Callum Rogers
Nice Edit Peter.
EvilTeach
Unless I'm reading something wrong, I feel like this would actually waste time for me. The time I'd spend navigating to between the parentheses and brackets would pretty much equal the amount of time it takes me to type `if () {} else {}` around whatever code goes in there.Of course, that might just be me.
Maulrus
+39  A: 

For all bracketed constructs -- (), [], {}, "", /**/, etc -- type the bracketing first and then fill it in. In particular, for /**/, type this on the number pad.

This also helps avoid confusing compilation errors from forgetting the end bracket.

Conrad Albrecht
My editor does this by default.
JUST MY correct OPINION
`/* */` on the numpad... why didn't I think of that? That's exactly the kind of thing that I was hoping for :)
Thomas
I'm not sure whether typing the brackets first is actually *faster* -- you have to move your hand off the home row and to the left arrow key to fill them in. However, the time savings of not forgetting brackets are probably worth it.
Thomas
@thomas: use neo <http://neo-layout.org>, so you do not have to move your hands off the homerow neither for brackets nor navigation
knittl
A: 

Depending on you IDE, you might have custom keyboard templates. which I find very productive.

For example, Delphi has live templates and Visual Studio has code snippets. Both also have third party products that add even more functionality, such as Castalia, ModelMaker Code Explorer for Delphi and CodeRush (outstanding!) for Visual Studio. The only downside to these third party tools is trying to use a copy of the IDE that doesn't have them installed.

Bruce McGee
+2  A: 

If you have 4th & 5th mouse programmable buttons (and depending on programming software), set macros to your mouse buttons:

  1. Enter
  2. Cut
  3. Paste
  4. Build
  5. New Class macro
  6. New Getter/Setter macro

This could save a lot of time. Think WoW, except really useful.

dboarman
But why use the mouse at all? As a programmer, I mainly type, and rarely ever design graphics. My mouse is usually buried somewhere under books and papers.
sbi
dboarman
I use the extra buttons for page up page down. That still helps a bit in coding, especially when your method is 2 pages long.
Jason
I use mostly vim but I also enjoy using just the mouse sometimes. I added some context menu options for right click, like "Find the word under cursor", the same with a backwards search, "Open taglist"(methods and classes) and "Go to tag" so I can browse the code easily using only the mouse.
Heikki Naski
+66  A: 

Single most useful (and potentially obvious, but who know?) tip that must have saved me hundred of hours over my programing time:

Use whole word caret movement shortcuts (control-left arrow/control-right arrow) to rapidly go the line location you are seeking. Use them in conjunction with shift for quick selecting of a couple of words.

Corollary: use beginning of line/end of line shortcuts.

Example: let's say you have the following line of code

ClassA toto = new ClassA("A nice string", 10, -300, MAX_VALUE );

Your caret is on the keyword 'new' and you want to change -300 to -299. What is the fastest way, assuming both hands are on the keyboard?

  • Moving hand from keyboard to mouse and go to location, move back to keyboard then edit? No.
  • Press the right arrow ~30 times? No, not even close
  • Press control-right 7 times, control-backspace once then type 299? I wouldn't fault anyone for doing that, it is the right idea
  • Press end, control-left twice, control-delete then type 299. Bingo

Anyone knows faster shortcuts even? I'd like to know if there was.

ADB
In Vim: `f-1<ctrl-A>`. `f-` goes to the next "-" character. `1<Ctrl-A>` increments the number under the cursor by one. That is four keystrokes.
Dave Kirby
Great answer. I use this all the time myself. So annoying that many Windows applications still don't grok Ctrl+Backspace.
Thomas
My personal variant for such a case: works on my usual editor gedit: Ctrl-F, 3, 0, 0, Enter, 2, 9, 9. In this exact case you get me by one key press, but mine also work if the cursor is a few lines before, or current line is longer.
kriss
press `f` `-` `Ctrl+a`. Three strokes. This is in Vim.
slacker
Correction - in Vim you can do it in three keystrokes, since <ctrl-A> defaults to incrementing by one - `f-<ctrl-A>`.
Dave Kirby
@Thomas:It's even more annoying that many applications still don't grok Vi-style editing!
slacker
@slacker: The power of Vim keeps surprising me. Maybe I should learn it beyond `:qa!`... ;)
Thomas
I 'm in the `:qa!` camp as well regarding Vim. I think that all this "Vim does this in N keystrokes" stuff is not relevant. All kinds of software does all kinds of things, e.g. with ReSharper I can safely rename a class that's referenced in 1000 files with (3 + as many edits I make) keystrokes. What does that say?It would be better to just provide advice that can be used by everyone regardless of their specific choice of IDE or editor.
Jon
Vim shortcuts are so unintuitive. Whatever fraction of time you gain by pressing fewer keys is massively wasted by remembering the shortcut (sure, f=find, but s=search and f could be other things), deciding that the quickest way to get to where you want is to do a find for the `-` character, then finding and typing the keys on the keyboard. In the meantime, I've used the Ctrl key at the far corner of the keyboard and the arrow keys that are in their own block, to press twice as many keys without even looking at the keyboard in a quarter of the time. /rant
DisgruntledGoat
I agree with Jon here, program-specific shortcuts are not relevant here.
Arsenal
This can be done even faster in Visual Studio. Press Ctrl+I for incremental search and press 3 :)
Marek
Of course, how many keystrokes something takes in vim is irrelevant, since vim is a text editor, not an IDE - it contains lexical abilities (regex), but no parser, so it cannot even do something as simple as (safely) renaming a variable...
BlueRaja - Danny Pflughoeft
@DisgruntedGoat: Vim commands are a language. There's more than one way to express yourself; it takes time to learn and perfect; but once mastered, you can become very eloquent and express things in a fraction of the words that a less skilled speaker would use. Your use of Ctrl/arrow keys is a language in itself - one that you've become very familiar with - so it's no surprise that you'd have trouble learning another one.
rjh
@BlueRaja: coming from a UNIX background I believe a program should specialise in what it is good at and try not to do everything. I'd be quite happy to type (productively) with vim and refactor using a separate tool. It's asking too much for vim to implement refactoring and deep code understanding for every language, or for your typical IDE (Visual Studio etc.) to have the text manipulation power of vim or emacs.
rjh
this is exactly how i do.Many people don't know ctrl+arrow usage, and dont have the common sense to use home, end. You can extend this for selecting text. For example, if you want to select everything excluding the last word, home, shift+end, shift+ctrl+left arrow.
rao
@rjh: `coming from a UNIX background I believe a program should specialise in what it is good at and try not to do everything.` - That is an argument *against* using vim to program. Use a tool specialized for that language - don't try to hammer a nail using a swiss army knife.
BlueRaja - Danny Pflughoeft
@BlueRaja: The question wasn't specifically about IDEs so VIM is a valid answer
Otto Allmendinger
Unless I was working with ridiculously long lines (hardly ever the case), I just press and hold Ctrl+Right, and release when I get to the desired position. With keyboard properties set to shortest repeat delay and fastest repeat rate, you're moving at about 30 words per second. I find this faster/more practical than having to figure out the "shortest path" mentally every time.
Daniel Liuzzi
@BlueRaja: Vim is for editing text. Program sources are text. A separate tool for refactoring is fine, as you shouldn't have to do it a lot anyways (and half the time no tool can automate it for you)... @Daniel: It's still 10x faster to use the vim command than to ctrl+(left|right) 10 times, and the mental calculation takes about a millisecond.
Longpoke
For vim: what happened to '/3' followed by Enter? What is the need to remember f-<Control A> when 'search for next appearance of 3' is right there?
Adriano Varoli Piazza
+9  A: 

I spend significantly more time tracing, testing, debugging, reading, and thinking about my code than I spend typing it. I could increase my typing speed 100x and don't think I would get a significant boost in productivity.

mikerobi
Perhaps, but that's not the point of this discussion :)
Thomas
If you're prototyping in a console/REPL/similar environment, being able to quickly express yourself becomes less of a barrier to thinking (and trying) things through. Again, sometimes you need to adjust five different places in code somewhat atomically. The faster you can get through them, the less likely you'll forget a step by the time you get through them.
steamer25
The funny aspect is that most slow typing programmers say that typing speed does not matter and almost no fast typing programmer would agree with this.
Marek
It's not so much about the actual time spend typing but about not having your flow of thoughts interrupted.
Christian
Typing skill also decreases your chances of making mistakes. You would probably spend less time tracing, testing, debugging and reading the code if there wouldn't be those typos in variable names. And most programmers don't just think about a non-trivial problem and code it in one go, without experimenting, changing, refactoring or rolling back the code several times. And of course, there's documentation, emails and instant messages to be written which can all contain code.
Heikki Naski
@Marek, I think that largely depends on how fast or how slow, most programmers probably fall in the middle.
mikerobi
@Heikki Nask, real programmers don't write documentation ;)
mikerobi
@mikerobi, yeah, but it also takes a lot more editing skill to write assembly blindfolded in a blizzard. Nice of you to help me make the point about typos, by the way.
Heikki Naski
I disagree with this. Have you ever watched a programmer who does everything the slow way? It really is ridiculously slow. Furthermore, it's so slow that you have to slow your mind down so you don't get to far ahead of what you're doing.
tster
@Christian: Exactly - But the faster you think, the faster you have to expel the buffered thoughts. Otherwise you'll fill up and will start losing chunks from the mindstream.
tsilb
Fast typing/editing is needed to stay in sync with your brain developing the code. Or as the Mylyn 3.0 tagline says: "Code at the Speed of Thought"
Bananeweizen
+5  A: 

Avoid mouse, learn shortcuts. What can be done with mouse usually can be done ten times faster using keyboard if you know your shortcuts.

Also think more and type less, and use an advanced editor that you know well.

Two exemples of precious features:

  • smart use of regex or of macros avoided me hours of typing (a standard typist may find them too complex, but for programmers it should be a piece of cake).
  • use autocompletion features of your editor (also avoid typo for keywords).
kriss
+1 for noting that autocompletion is great for checking typos. I don't personally think that it saves huge amounts of time since if you type ~70 wpm you will probably save only a couple of seconds when autocompleting a long symbol name, and sometimes you lose time looking at the popup and selecting the correct symbol. The typo prevention is why I use automatic completions, and it's more comfortable too.
Heikki Naski
If you type enough that there's no ambiguity, it's very easy to fall into the pattern of [CTRL]+[SPACE], [ENTER]. Saves a few keystrokes, especially in languages such as Java, where every class is ClassWayTooLongOfANameOne. ;)
Andrei Krotkov
+16  A: 

Learn Vim. It is available on virtually every platform, and you can do things from the keyboard that are unimaginable in most other editors. The learning curve is steep so expect your productivity to plummet for a couple of weeks, then soar as your muscle memory learns the Vim way of doing things.

See my comment to AD's answer to this question for an example.

Dave Kirby
Would upvote 10,000 times. Every other answer, except (grudgingly), the one about Emacs, is some workaround for a sub-par editor.
Derrick Turk
steep learning curve is not worth it...
Tim
@Tim: For something you're going to do for the next forty years or so, it makes little sense to complain about a steep learning curve. If it takes you forty hours to become reasonably proficient with vim, and it saves you 0.1% of your working time for your next forty years, you're coming out ahead.
David Thornley
I don't know anyone who can be as productive in vim within 40 hours as they can be in something like visual studio right from the start... My choice of IDE is also chosen for other capabilities - not just super-fancy ctrl-alt/keyboard tricks.
Tim
@Tim: With fancy IDEs with frameworks that do the typing jobs for you, your productivity will be boosted by automated code generation. However, the question here is "to type and edit code faster".
shinkou
@Tim wins the award for lazy and being one of the many developers I meet who keep doing things the slow way for the rest of his life. Let me guess, touch typing is too steep a learning curve, too? Hunt-and-peck programmers are the biggest joke ever.
PP
@PP I have more important things to learn than an esoteric, outdated editor.
Tim
@Tim outdated how? And esoteric how? [Citation needed]
Adriano Varoli Piazza
"The learning curve is steep" is all one needs to hear.
Tim
Oh, I suppose becoming proficient in VS or Eclipse is a piece of cake, then. Yea, learning to set up a project, compile it, etc, easy peasy.
Adriano Varoli Piazza
A: 

I think you have to try and use as much macros as possible, editors like emacs can be really helpful but most text editors now support a bunch of macros that can keep your hands on the keyboard and free it from the evil mouse...

rabidmachine9
+1  A: 

Buy and learn to use a Kinesis Contoured keyboard:

I bought my first one in 1995 and I own five of them. To learn it, you are best off using a typing-tutor program, but once you've learned you can switch back and forth easily.

Norman Ramsey
I have one. It saved me from having to get surgery, after 2 years of hardcore coding on a laptop for a startup. :) I love it. Using it right now. Every developer should seriously have the chance to try it out for a week.
Richard Hein
I'm not sure my typing speed would seriously increase with such a keyboard; it is already high using a cheap ordinary US keyboard (I do, however, baulk at UK keyboards, the shape of the Enter key and the tiny size of the left shift key seems completely impractical).
PP
It's not about the typing speed, in this case, but about keeping your wrists healthy
Adriano Varoli Piazza
+1  A: 

I use Emacs for my coding and there are couple of things that work for me.

  1. Use YASnippet.
  2. M-x comment-region and M-x uncomment-region help comment/uncomment chunks of code quickly
  3. show-paren-mode, with a background color like "honeydew2" helps in focussing on blocks of code
  4. Keyboard shortcuts tied to the key to insert (), [] and {}.
Sid H
+4  A: 

Navigate backward and forward between the places in code that you're editing.

A lot of time can be wasted scrolling and mouse-wheeling between several physically distant areas in the same project. In Visual Studio, hit Ctrl + - and you will jump back to the last place in the code that you made an edit. Ctrl + Shift + - will jump you forward again.

For bonus points, bind these shortcuts to the back and forward buttons on your mouse. Awesome.

Daniel I-S
I think this is editor-specific...
Thomas
Oops! Yes, this is Visual Studio specific. But I'll leave it here, since it's still useful, and there's some other editor-specific stuff above.
Daniel I-S
I think it's fine. Navigating to places where edits were made is a concept, and it's good to see an example. For Vim, use '. to go the last change and '' to move back to the place before last jump.
Heikki Naski
+3  A: 

Learn to use either hand to type Shift, Meta/Alt, and Ctrl.

(One reason I don't use a Mac is that the Mac requires four modifier keys, and I can't find a reliable keyboard that has all four on each side.)

Norman Ramsey
The standard Apple aluminum keyboard has all 4 modifiers on both sides.
drawnonward
@drawn: tragically, the 17" macbook pro does not. That's one reason it's gathering dust in a closet...
Norman Ramsey
+1  A: 

If you use Emacs, do the tutorial (C-h t) all the way to the end.

If you use another editor, do what it takes to use the "fast navigation commands".

Norman Ramsey
If you use emacs, scrap it and learn Vim :). Now flame me :).
slacker
@slacker: if I were starting today I'd learn vim. But nobody is volunteering to port 28 years' worth of emacs lisp...
Norman Ramsey
+20  A: 

Learn and get comfortable with the beginning/end-of-line and beginning/end-of-file shortcut keys.

By environment, those are:

EnvironmentBOLEOLBOFEOF
───────────────┼──────────┼──────────┼─────────────┼─────────────
Windows (all)  │  Home    │  End     │  Ctrl+Home  │  Ctrl+End
Linux (all)    │  Home    │  End     │  Ctrl+Home  │  Ctrl+End
Mac (all)      │  ⌘←       │  ⌘→       │  ⌘↑          │  ⌘↓
───────────────┼──────────┼──────────┼─────────────┼─────────────
Emacs          │  Ctrl+A  │  Ctrl+E  │  Meta+<     │  Meta+>
Vim            │  0       │  $       │  gg         │  G

You can quickly highlight an entire line of code by pressing the EOL key, then holding ⇧ and pressing the BOL key (that's End, Shift+Home on Windows) and then use the up or down arrows to highlight multiple lines.

Aaronaught
Note that this is on a Windows machine, not on a Mac. On a Mac, Home and End scroll to the beginning and end, respectively, of a file without moving the cursor. To move to the beginning and end of a line, use ⌘← and ⌘→, respectively. Hold down ⇧ to select as well (so to select a whole line, you can hit ⌘→ and then ⌘⇧←). To go to the beginning and end of a file, use ⌘↑ and ⌘↓, respectively. (The ⌘ and ⇧ symbols denote, respectively, the command and shift keys.)
Antal S-Z
I'd even go further with using Emacs. Home and End buttons are too far, since you have to move your hands from the home row. Ctrl-a and Ctrl-e are closer and faster. Also, using Ctrl-b and Ctrl-f to move the cursor left and right is faster than to move your hand to the arrow keys.
Kimmo Puputti
Eek, I guess I should have qualified this as being Windows/Visual Studio centric. I'll try and edit this to include all platforms/environments. Being Community Wiki, you guys can feel free to edit too! (just keep it readable and organized)
Aaronaught
BOF and EOF are Meta+< and Meta+> in Emacs, couldn't get them appear in the post...
Kimmo Puputti
I use ^ for Vim's BOL. Had no idea that 0 worked too.
Auguste
@Auguste: 0 in Vim goes to the BOL, and ^ goes to the first non-whitespace character on the line. ^ can therefore move you forward. Eclipse, and I believe lots of other IDEs, has the Home button first go to the first non-whitespace character, and if the cursor is in that place and Home is pressed, it goes to the BOL.
Heikki Naski
Apparently there's some browser wonkiness with the formatting on the Mac line - I'm not sure what the deal is, but I'm pretty sure the current version is correct on *most* browsers, so please leave it...
Aaronaught
This alone is the reason I hate coding on a Mac. Every time I hit home only to lose my place in the document and end up at the beginning of the file, I want to thrash my keyboard into a million bits and pieces
Chris
+3  A: 

It's a shame that the DVORAK keyboard layout hasn't really caught on.

QWERTY was allegedly designed with the intention of capping typing speeds so as to prevent mechanical breakage of the good ol' typewriters.

Zaid
If I could get a Dvorak, I would take the time to learn it.
dboarman
I'm using dvorak myself and notice the difference, but I seem to be the exception. See also http://stackoverflow.com/questions/455525/is-the-switch-to-dvorak-worth-it
Thomas
http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard#Programmer_Dvorak
Pindatjuh
I swapped my keys on this laptop: almost 2 hours trying to type, and its quite easy to learn!
Pindatjuh
Please read http://www.utdallas.edu/~liebowit/keys1.html or http://reason.com/archives/1996/06/01/typing-errors before investing your time in learning Dvorak.
Rafał Dowgird
-1, reading Rafal Dowgird's links pretty much disprove this answer.
Maulrus
I once learned to use Dvorak but didn't find it that much better for programming. It also had the large drawback that it became harder to quickly switch back to QWERTY when sitting down at someone else's computer and pretty much impossible for anyone else to use my computer.
Christopher Barber
I use Dvorak right now because I can't take the time to get used to QWERTY again. Learning Dvorak was a net loss: I can't type any faster, it took a while to get proficient again, symbols are hard to get to, my wrists don't feel any better, and as Christopher was saying it makes switching/sharing computers really awkward.
IV
+2  A: 

If Visual Studio is in context, then there are several 3rd party plugin/tools which enhance typing efficiency of developers.

One such, I use is CodeRush. There are even videos available for the same.

System.ArgumentException
A: 

I'm surprised no one has mentioned it here yet. Get an IDE or editor that does code completion, and learn to use it well with the keyboard shortcuts. Most decent ones will complete variable names. Some, for example XCode, will fill in things like if statements and switch blocks for you. Then, you just press a keyboard shortcut (command-/ in XCode) to move to the next spot you need to fill in. This does two things: it types out the stuff for you, and it keeps you from having to remember the exact syntax or making a mistake in it (you will never forget to break; a switch case if you do this).

Also, it doesn't work so well for programming, but for regular typing, use an editor that has good auto-completetion. The auto-completetion in Snow Leopard has probably increased my effective typing speed by 150%. Maybe there is an awesome IDE out there that does this for comments.

asmeurer
+7  A: 

Good thread.

My favourite is the shortcut to jump to the closing curly brace: CTRL+] in Visual Studio and CTRL+Shift+P in eclipse. I use this a lot.

David Relihan
...and `]}` in Vim.
slacker
A: 

Abuse your language's preprocessor like a bitch.

#define J template<typename T>
#define LOOP(a, b) for(int i = 0; i < a; i++) { b; }

Saves so much time!

DeadMG
This sounds like a great way to make your code unmaintainable. Using an editor with snippets is a much better idea.
eman
Ed Griebel
-1 for making fellow coders' lives more difficult. This is anti-social.
PP
It was clearly intended to be humourous, PP.
DeadMG
+6  A: 

Switching to overwrite(replace) mode by pressing Insert button can speed things up sometimes quite a bit when you need to make replacements without changing a word length (usually in a vertical block of text). For example if you need to increase indexes by 1 here:

array[0] = ...
array[1] = ...
array[2] = ...
array[3] = ...

Switching to overwrite mode allows you to navigate to required position in every line by using down and left arrow keys, which is much faster than down and backspace as they are far apart. And if your editor remembers cursor position, then all you need is use a down key after each replacement.

serg
Now somebody's going to say how you can type `4 Ctrl+A j` in vim, or something like that... :)
Thomas
Simple bit of advice that I had honestly never thought of. The number of times I have to edit a text file to change a single value is crazy, and this would save me so much time. (Obviously, writing a tool to do the replacements for me would save more time, but you know how it is) :)
ZombieSheep
In Vim, I'd do it with <C-a>j.j.j.
Heikki Naski
Watch out. If there's both more than 9 values, this trick will sometimes overwrite the ] on the 10th row when your fingers continue flying on auto.
Andrei Krotkov
+10  A: 

The single piece of software that saves me a lot of time is the multi clipboard manager (like ClipX). It allows you to copy several parts of a source file at once without switching back and forth between files, and furthermore it keeps the clipboard history so, if you accidentally overwrote the latest clipboard entry, you can easily recover it.

serg
+1 for multi clipboard manager. On OSX I use Jumpcut.
Lo'oris
FYI, current versions of Visual Studio have this built in.
AviD
In other words, a poor man's Vim named registers?
slacker
I use Ditto, almost perfecthttp://ditto-cp.sourceforge.net/
Raveren
+1  A: 

Mac only: Use an editor that supports the native Cocoa text input system. Learn, modify and enhance the key bindings. Remap the caps lock key to behave as ctrl.

All of this together amounts to a very comfortable way of navigating with the cursor sans arrow keys. By default, OS X implements a very minimal subset of Emacs commands. If you add in the word-centric commands (optionf moves one whole word forward, etc), you can reduce the number of trips to the mouse by quite a bit.

You can even implement complete and complicated snippets through the key bindings. For example, I have one like this:

/* This command will make Ctrl-< turn the previous word
 * into an HTML/XML opening and closing tag pair. */
"^<" = ( "setMark:",
         "moveWordBackward:",
         "deleteToMark:",
         "insertText:", "<",
         "yank:",
         "insertText:", ">",
         "setMark:",
         "insertText:", "</",
         "yank:",
         "insertText:", ">",
         "swapWithMark:");
Matt B.
+3  A: 

Eclipse (and Other IDE's I'm sure) has templates (Java->Editor->Template) where you can add you own pattern blocks. For example

if (${name:var} == null) {
    ${name} = new ${type}(${arguments});
    ${cursor}
}

return ${name};

gives you a nice fill-in-the-blank block of code that can be tab\shift+tab navigated until you hit eneter (then it's just regular text).

Also, ctrl+space brings up autocomplete.

KitsuneYMG
I think this is a great idea. However it makes you think: if you do something often enough to make a template why not create a function? There are situations in which you don't want the overhead of a function call, but it is something to consider.
PP
@PP An example (that ships with eclipse) is instanceof. It automatically puts `if([NAME] instanceof [TYPE]) { [TYPE] [NAME]_ = ([TYPE])[NAME]; }` into your editor. Where the [] are linked, replaceable text fields that can be navigated with tab (until you hit enter).
KitsuneYMG
+9  A: 

Learn to use regular expressions in your Editor/IDE.

E.g., Earlier today, I was annoyed by a file that had excess whitespace at the end of the majority of it's lines. Replace \s+$ with empty string took care of it.

steamer25
I have been just amazed sometimes at the sheer amount of work I've saved by using a regular expression search-and-replace. It is really one of the most amazing things computing has to offer - and I consider myself adept at regexps. Sometimes I set up an interactive search and replace and find myself deliriously overjoyed at the transformations occurring in front of my eyes.
PP
+5  A: 

Use incremental search and backward incremental search for navigation. It's like teleporting instead of walking - usually Ctrl-S or Ctrl-R (emacs bindings) or Ctrl-I in Visual Studio plus two to three keystrokes get you anywhere on the screen. Well, unless you're editing ASCII art or binary memory dumps :)

Rafał Dowgird
A: 

Learn an optimized keyboard layout like Neo.

The time it takes to learn pays off shortly after. All programming special characters are easily typeable without moving hands and fingers very far. Just press caps + some-key (caps + n = ( – n being j on a QWERT[YZ] keyboard :D confusing?). A numberblock and a cursor block including Home/End, PgUp/PgDn are integrated into the mainfield of the keyboard.

/**/ is on the homerow. {}()-*:/@? also on the homerow.

Move hands less, type more.

knittl
A: 

I'm all in favour of knowing Vim, because of its portability (which is the reason I learned it back in 1993). I still use it sometimes even though I mostly work in Visual Studio, having used various flavours of it since, well, 1993 (Visual C++ 1.0 FWIW).

However more generally, I would say my top tips are:

  • learn to type! None of the other ideas here will help speed you up half as much as learning to type quickly & accurately. Number one tip - stop looking at the keyboard
  • learn regular expressions - complex replacements I still do in Vim because those are the REs I know best, but VS 2008 does a reasonable job
  • learn how your editor supports quick macros - a lot of search + replace can now be done with refactoring tools but now & then you want to reformat stuff repeatedly and a macro can save you hours of hacking about
  • learn how your editor supports bookmarks: in VS this is Ctrl+F2 to leave a bookmark, F2 to go to the next bookmark. I am always amazed how few programmers know about or use these
AAT
You should have put "learn to type" as a separate answer on it's own.
Vulcan Eager
@Vulcan - you mean because that is the most important speed improvement you can make? I won't disagree with that.
AAT
A: 

Find some site that can help you train your way of type. I don't know any other, but would be nice to see more of this on comments. This is an example to start

Gabriel L. Oliveira
keybr.com is also nice
Vulcan Eager
So nice too man! It has more features, but is some confuse on the keyboard color. But liked it so much. Thank you to share with us.
Gabriel L. Oliveira
+3  A: 

The best musicians still practice, and the best typists would in theory, still practice.

Part of building speed and accuracy is simply "slow down and perfect it", which is amoung the biggest hurdle for music students to overcome (according to well know famous musicians/teachers, such as Andreas Segovia). In theory the same principles apply. It should be easier to perfect than an instrument, because typing is not a performance art (unless you are presenting). So when you make any mistake, you should stop and think and feel your whole body. The muscle tension in the fingers, the hands, spinal column position and curvature, etc.... Then focus on the tension and correct, by relaxing and slowly moving through the motions until it's smooth and you are totally relaxed except for the absolute minimal muscle tension required to move the finger to where you want it to go. This builds muscle memory, and you have to unlearn all the bad habits, by slowing down, and eliminating all wasted motion.

Richard Hein
+1  A: 

![alt text][1]

Nice keyboard like the logitech illuminated. (Would post a pic but I'm new here) Macros. Autocomplete where possible. Editor like E or Textmate which does lots of things for you. Plugins like Zen coding if doing lots of HTML.

Other than that..... staff ? :)

MonkeyMagic
You can post a link to the pic, and somebody (e.g. me) will edit it into your answer.
Thomas
A: 

I find I can type Pascal faster than C/C++ because it contains far less obscure punctuation symbols - therefore requiring far less two-hand coordinated movements to type them.

On many non-US keyboard layouts you need three-key combinations to generate the various brackets {[]}

The keyboard is optimized (yes, optimized to avoid jamming typewriters by putting alternative characters on alternate hands) for text input, not complicated symbols.

If you can't use Pascal, Cobol or Python or another language with this word-based style you might be able to adopt something similar as early Unix apps did.

Will
That header is horrible. When writing C, write C, don't try to make it look like Pascal.
Thomas
@Thomas I second that; never re-define a language if you ever expect any body else to see/use your code. It is the equivalent of walking around in hoodies with your jeans halfway down your legs showing off your underwear. Not cool.
PP
@PP and @Thomas it could be that that particular file is infamous if you're steeped in the history of our trade? Do you think I found it by accident? :D
Will
of course, the serious point about punctuation being difficult on my (non-US) keyboard is an serious contribution to the discussion, and I stand by that bit
Will
If you touch-type without looking at the keyboard, just change the layout to qwerty (or something else suitable for programming). If you don't touch-type, maybe that is the place to start :)
Thomas
@Thomas I have a non-US keyboard because I have a non-US keyboard in a non-US country and do need to type non-US strings, even in my program source.Saying programs should be written in ASCII with US comments and strings is not a very nice sounding solution is it?
Will
I'm not saying that; I'm well aware how annoying such issues are. However, the code itself is ASCII in all but a few programming languages. You could consider externalizing your strings, so you could switch your layout when you're going to work on the UI side of things. Comments, of course, are a more difficult matter... Unfortunately there is no perfect solution. (I wonder if one could hook up two physical keyboards and set each to a different layout? Would the OS understand?)
Thomas
@Thomas so giving that the comment symbols /* in C were chosen because they were on top of the US standard keyboard numeric pad at the time - were there international keyboard layouts at that time? - and the question is asking things that let you edit code faster, using a non-{} language is a good way of achieving that for many people, and you could upvote this answer because its patently valid? :D
Will
+1  A: 

Rebind all your keys

On an English keyboard it may matter less, because programming languages has been invented using English keyboards. International keyboards have a different set or readily available symbols, usually different from the English ones, so many common symbols used in programming are hard to type on those keyboards.

For instance, { on standard Italian keyboard requires 1 key + 2 modifiers.

You will use the numbers much less than your most used symbols, so you should remap them to shift and use most used symbols to default.

Here's how I remapped my keyboard:

base shift alt

Update:

Mac OS X

Edit the keys using Ukelele. You can download the map I've shown here (put it into /Library/Keyboard Layouts and relog.

Linux

  • dump current keymap: xmodmap -pke >current.xmodmap
  • edit it by hand
  • load it in .xinitrc: xmodmap current.xmodmap

Disclaimer: I might not remember correctly, and there might be visual editors I'm not aware of.

Windows

I'm sure it can be done, or at least it could be done a few years ago. I never tried, but you can figure it out.

Lo'oris
@Lo'oris: what operating system / application? Mac OS X?
Peter Mortensen
I have done this on Mac OS X, but it can be done on every system, you just have to find the right tool. Under linux you can edit by hand a custom .xmodmaprc, under windows I'm sure there's a program similar to this one (no idea how it is called).
Lo'oris
I've edited, adding an explanation on how to do it.
Lo'oris
@Lo'oris: Thanks. Some leads for Windows are in http://wiki.neo-layout.org/wiki/Neo%20unter%20Windows%20einrichten (in German, though)
Peter Mortensen
A: 

This is Visual Studio-specific but it also works with Notepad++. Basically it's possible to use the keyboard to scroll the current window leaving the cursor in the same place by using Ctrl+Up or Ctrl+Down.

It's maybe not that useful however as once the cursor reaches the top or the bottom of the screen it will stay there. I use it periodically if I need to check something that I know is just beyond the current window boundary so I can scroll the window up or down without having the cursor move off the current line.

Malice
A: 

Learn to use incremental search for navigation.

Most modern text editors provide some sort of incremental search capability, for instance in Eclipse this is bound to Ctrl+J by default while in Emacs it is bound to Ctrl+S and in Visual Studio it is Ctrl+I. You can use this and its reverse version to jump to code at or near where you want to place your cursor rather than mousing or using simple arrow controls.

Christopher Barber
+1  A: 

Eclipse has a shortcut for looping over arrays and other containers. Type "fore" (short for "foreach") directly after an array declaration, and you get:

int[] myArray = new int[7];
for (int i : myArray) {

}

For other kinds of containers, it will generate an appropriately typed loop:

List<Integer> list;
for (Integer integer : list) {

}

But often I want to loop over a container that was declared elsewhere. I lose the benefit of automatic typing. So I create a variable, assign the container to it, use the shortcut, and immediately inline the variable.

x=l[ctrl-space][arrow keys as needed][enter]; produces x=list;

Quickfix (command-1) gives x the requisite type: List<Integer> x=list;

for[ctrl-space][enter] produces

for (Integer integer : x) {

}

and permits me to tab directly to the x, where I type command-option-i to inline, which deletes the List<Integer> x=list; line, and leaves me with exactly what I wanted:

for (Integer integer : list) {

}

It sounds like a lot of work, but honestly it saves me time - and errors.

Carl Manaster
A: 

Challenge your coworker(s) to a contest. Pick some action you do often and give kudos, prizes, etc. to the person who comes up with the fewest keystrokes/button pushes to accomplish it. Examples:

In some versions of vi zz will close the file and save it. This is one keystroke shorter than ':x' then the enter key.

Or:

In Windows you can copy a file's name in Windows Explorer by right clicking on the file, hitting rename, then hitting Ctrl + c to copy the highlighted file name from the rename input box.

Jay
Click, F2, Ctrl+C would be my choice. Alternatively, click, wait, click, Ctrl+C, but that's slower.
Thomas
+1  A: 

When entering large blocks of numbers for, e.g., initialization of arrays, don't use the numeric keypad, but instead move both hands to the number keys at the top of the keyboard. I was taught to do this when I worked in a data entry department at a bank in college, and I find it faster and more accurate.

Dan Menes
Ten fingers, ten digits... it makes sense. Do you use your thumbs as well?
Thomas
No thumbs--I still reach for 5 and 6.
Dan Menes
A: 

drelihan mentioned the "go to matching brace" shortcuts in Visual Studio and Eclipse. In TextPad, its Ctrl+M, or Ctrl+Shift+M to select the entire block

Dan Menes
A: 

I assume growing an extra finger is out of the question?

Seriously though, I reccomend extensive customization of the function keys on your keyboard and mouse.

George Edison
A: 

Learn or create a shortcut to take the selected text and perform a search for it. On most Mac editors, this is ⌘E ⌘G. This allows you to do a quick “find other occurrences of this symbol” to navigate around the relevant parts of your file.

Kevin Reid
A: 

Context-insensitive Completion

In Vim, ctrl-{n,p} and Eclipse I think the default is meta-/.

It's powerful because it doesn't care if you're writing documentation (I cringe every time I see someone typing out a comment which contains, say, … call ISomeEnterpriseBusnessClass.fozzleTheWidgetWithTheWazzle…), writing inside strings or writing code.

David Wolever
A: 

In Visual Studio (plus EnterpriseManager's editor), comment and uncomment using Ctrl + K + C and Ctrl + K + U. Nice thing, it works well with different languages.

Sorin Comanescu
+2  A: 

ZenCoding is awesome!! It's available for multiple IDEs, and it's great if you program HTML a lot, like me.

Get it here.

It's also useful to press 'Crtl+Space' when using some IDEs, which will give you function parameter hints, etc.

robogeek1993
+1  A: 

Search for the word under cursor to uncover typos

A great feature in itself, but you can also use it to check for typos. For example, * and # in vim and in Eclipse wait for a couple of seconds when the cursor is over a symbol.

Heikki Naski
I use this feature so much I wrote custom functions to do this in Emacs.
PP
+2  A: 

Remember that in Visual Studio if you copy or cut with no text selected, it will copy or cut the whole line. Then when you paste back in with no text selected, the line will be inserted above the line the cursor is on.

This has saved me a lot of time, especially when reordering a few lines. It makes dealing with leading or trailing empty lines a lot easier as well.

RandomEngy
+1  A: 

For me the most valuable has been:

http://www.autohotkey.com/

  • You can reprogram your whole keyboard, as I did since I use AZERTY

    .. no more "ALT-{" to get "{",
    just type {,
    same with ( [ # @ ...
    Who needs ùµ$^² as default keys anyway ?? WTF?? :-)

  • You can program your own shortcuts, for example ALT-² inserts a new method at my machine

  • You can program hotstrings, like if you type hotfunc, it will type a whole function declaration

  • Program hotkeys to launch exe's, create files, ....

  • You can use it in every app, including Visual Studio, notepad, or your emails

  • You can do anything you want, since you can program it yourself

  • Did I mention it's free ?

Run CMD
+1  A: 

In Notepad++ there are two keyboard shortcuts that are perfect for programming:

  • Ctrl+Shift+Up/Down : move the current line up/down
  • Ctrl-D : duplicate the current line (or selected block)
tim_hutton
i hate how ctrl+d does the exact opposite on zend studio :/
Moak
A: 

In Visual Studio 2008, map a good pair of keystrokes to the Edit.GoToFindResults1NextLocation and Edit.GoToFindResults1PrevLocation actions. Saves a lot of time when changing something across multiple files in cases where 'Replace in files' is not an option.

(Ctrl + ;, Ctrl + N and Ctrl + ;, Ctrl + P are decent enough setting here)

Vulcan Eager
A: 

Type and edit code faster? Master your tools! Whichever tool you are using, learn to use it at its fool. First thing is the editor, Vim is amazing, Emacs too. At least it is very important that you can expand its functionality with macros.

Also learn tools for browsing code like global and cscope. If you cannot find what you want fast, you cannot edit fast.

Being more generic, learn some code spelunking to move faster even when the code is totally alien to you.

Francisco Garcia
+1  A: 

Easy Line Copy: Move the cursor to a line and press Ctrl+C WITHOUT selecting the text of line.

Easy Line Cut/Delete: Move the cursor to a line and press Ctrl+X WITHOUT selecting the text of line.

Easy Property Creation: Type prop and press tab twice

Faisal
Specific to Visual Studio, but useful.
Thomas
+6  A: 

Block Selection

alt text

Alt+Shift+Up

Alt+Shift+Down

Alt+Shift+Left

Alt+Shift+Right

This has saved me tons of time when making repetitive changes in long blocks of code (providing it's properly indented). It works with Visual Studio as well as with Notepad++.

Image source and more complete explanation.

Daniel Liuzzi
Emacs also offers this functionality in cua-mode: press ctrl-Enter to activate.
PP
For completeness: in vim, visual block mode is activated with Ctrl+V. Replacing (with 'c') replaces all lines in the block, which is tremendously useful.
Thomas
+1  A: 

Teach yourself to use the mouse with your less-good hand. Filling in dialogues goes a lot faster that way, particularly if the TAB navigation hasn't been programmed correctly.

Brian Hooper