Visual block mode (which you can enter with CTRL-V) is perfect for this kind of usage. You can copy and paste squares much like your router boxes and you can do so without shifting columns.
Here is an example working with your initial diagram.
Start by using a visual selection to copy the first router on the top left corner. First move to the upper left
+, then use Ctrl+V to enter visual block select mode, then use 4j (to move down 4 lines, getting to the
+ on the bottom left corner) followed by e (to move to the
+ on the bottom right corner), so you'll have visually selected the whole router in visual block mode. You'll have this:
Here you can use y to yank (copy) the visual block with the router.
At this point, move the cursor to the position where you want to paste it, which is on the upper line, but above the lower router. Place your cursor at the top left corner of where the box should go. Like this:
Here you can use a shortcut to select a block that has the same dimensions of your last selection, by passing a "count" to a v command. From
[count], select the same number of characters or lines as used for the last Visual operation, but at the current cursor position, multiplied by
So 1v will get you a selection of the right size you want to replace. Like so:
At this point, simply using p to put the block will replace the current block with what you have in your default register, which is the router you copied. This is what you get:
Which matches what you wanted in the first place.
But let's assume you pasted it without replacing a block and ended up with the shifted lines, like in your second diagram:
It's not too hard to correct that either. You can use a similar technique. Start by using a visual block selection around your router. (You'll use it only to "measure" it.) You can use the same sequence of commands mentioned on the first procedure.
Then hit Esc to clear the selection. You only used it to measure the size of the box, so you don't need to perform any operations on it.
Now move the cursor to the right, after the router.
Use 1v to select a box of the same size as your last selection:
And finally use x (or d) to remove it.
The final result is exactly what you expected:
One final tip if you're planning to use Vim for drawing diagrams is that you might want to use
set virtualedit=all (see
:help 'virtualedit', so you can move to parts of the buffer where you don't have any spaces and insert or paste items there, having Vim add spaces (or tabs) as needed to keep your text on the right columns.
In your particular example it turns out you didn't really need this, but if you're positioning boxes with routers in an empty buffer, it's quite advantageous to be able to move freely and have Vim take care of putting spaces around it.
To draw the lines, you can also use visual block selection. Select a visual block that is one line high (for a horizontal lines) covering the spaces you want to replace, then use r- to turn that into a sequence of dashes. For vertical line, create a visual block selection of a single column and use r| for a vertical line. See
:help v_b_r for more details on visual block replace.