Notepad++ Secrets: Block Mode
© 2012, Martin Rinehart
Most code edits are done in line mode. (Many code editors only have line mode.) Programmer's editor Notepad++ also has a block mode, and an incredibly nice way to do block edits without really switching modes.
Blocks—When Do You Want Them?
Any time you line things up in columns you are using blocks. We're partial to lining up columns in 2D arrays in JavaScript.
var arr_2d = [ ['col 1, row 1', 'col 2, row 1', 'col 3, row 1'], ['col 1, row 2', 'col 2, row 2', 'col 3, row 2'], ['col 1, row 3', 'col 2, row 3', 'col 3, row 3'], ['col 1, row 4', 'col 2, row 4', 'col 3, row 4'] ];
Oops! Forgot row zero. That's for column headings of course (destined for <th>
cells in your page). But this one makes a mess:
var arr_2d = [ ['Column Heading 1', 'Column Heading 2', 'Column Heading 3'], ['col 1, row 1', 'col 2, row 1', 'col 3, row 1'], ['col 1, row 2', 'col 2, row 2', 'col 3, row 2'], ['col 1, row 3', 'col 2, row 3', 'col 3, row 3'], ['col 1, row 4', 'col 2, row 4', 'col 3, row 4'] ];
Now you really want to mark a block of text (columns two and three, rows 1 through 4) and slide the whole block to the right. Block mode to the rescue!
Marking a Block of Text
Here's the block we want, marked as we want:
How was that done? Simple. Put your cursor at the top-left corner of the block. Press Alt+Shift and the arrow keys to drag over the block. (Don't release either mode key as you drag.) You will mark a block. If you mark every character to the right of the block's start you will have no troubles. (If you want to mark less, good luck! Use a practice file at first.)
Moving a Marked Block
Block marked? Good old Ctrl-X to cut the block.

Position the cursor at the new top-left corner (you'll need to space over to get there) and Ctrl-V to paste. Voila!

One more block to mark, cut and paste and we have column 3 neatly lined up, too.
var arr_2d = [ ['Column Heading 1', 'Column Heading 2', 'Column Heading 3'], ['col 1, row 1', 'col 2, row 1', 'col 3, row 1'], ['col 1, row 2', 'col 2, row 2', 'col 3, row 2'], ['col 1, row 3', 'col 2, row 3', 'col 3, row 3'], ['col 1, row 4', 'col 2, row 4', 'col 3, row 4'] ];
Now, doesn't that look better? (In practice, on a tiny table like this one it may be just as fast to bang in a few spaces. But picture a much larger table and you'll see the potential for this one being a life saver.)
Feedback: MartinRinehart at gmail dot com.
# # #