Use ctrl+v to select a column of text consisting of the first character of the place you want your new column to go in front of. Use I to go into insert mode, and type one space. Press Esc, and you'll see you have inserted a column of single spaces. Now use ctrl+v again to highlight the column of spaces.
Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.
Visual Block Mode of Vim allows us to perform different operations like delete, copy-paste, i.e., yanked and put, etc. To enable the Visual block mode in Vim, you have to try out the “Ctrl+V” command within the normal mode. You can see that the new. txt file has been opened in the Visual Block mode.
CTRL-V enters block selection mode (allowing you to select rectangular blocks of text). In gvim this conflicts with Windows' paste shortcut, so you can use CTRL-Q instead.
Unfortunately, CTRL-Q [G] doesn't do what you'd like since the [G] motion moves linearly through the file, so you still need to rely on a using a counted [j] motion. You can avoid having to know exactly how big the file is by using an obscenely large count, like 9999. So the full command is CTRL-Q [9999j].
Alas I don't know of way that will avoid the ugly count hack offhand.
EDIT: Oh, I read your question too fast and missed that you already mentioned that you new about the visual block mode. I guess this is a pretty useless answer, then, sorry!
G goes to the last line, but moves the cursor to the first non-blank position if the startofline
or compatible
(which enables startofline
) options are set. If you want to keep the same column, set nosol
before going into visual block mode, and then hit G.
From the manual entry for startofline
:
When "on" the commands listed below move the cursor to the first non-blank of the line. When off the cursor is kept in the same column (if possible). This applies to the commands: CTRL-D, CTRL-U, CTRL-B, CTRL-F, "G", "H", "M", "L", gg, and to the commands "d", "<<" and ">>" with a linewise operator, with "%" with a count and to buffer changing commands (CTRL-^, :bnext, :bNext, etc.).
The easy way for selecting column you can use plugin vis.vim
go to visual mode, select column ctrl+v
, then you can do whatever you want with it
Use V, v or Ctrl+V to visually mark some region.Then type :B cmd
(this command will appear as: :'<,'>B cmd
)
The command will then be applied to just the visually selected region.
For example:
Use ctrl-v
to select a column and then do a substitute on just that column.
Ctrl-V ..move.. :B s/pattern/becomes/
Use Ctrl-V to select a column, then apply an external filter to just that column:
Ctrl-V ..move.. :B !sort
I'm sure I'm not the only one who came here looking for a solution to a more general problem. Say I have:
Some text.
one two three
one two three
one two three
one two three
one two three
one two three
Some more text.
The following macro will select eg. all of the 'two' column when the cursor is anywhere inside it:
<C-v>iWmw{joO`woOmwoO}koO`w
<C-v>iW
visual block select in Word (can of course have different macros for iw
, a"
etc.)mw
Set mark at the right boundary{j
Go to the start of the paragraphAssuming you started somewhere in the middle, at this point your selection will look like this, where uppercase represents selected characters and $
represents the cursor:
Some text.
$NE Two three
ONE Two three
ONE Two three
one two three
one two three
one two three
Some more text.
oO
swaps the cursor to the corner on the same side (left) but the other end (bottom):
Some text.
ONE Two three
ONE Two three
$NE Two three
one two three
one two three
one two three
Some more text.
`w
will now get you back to the right boundary:
Some text.
one TWO three
one TWO three
one TW$ three
one two three
one two three
one two three
Some more text.
oOmwoO}koO`w
repeats the process for going down to the bottom of the paragraph.
Result:
Some text.
one TWO three
one TWO three
one TWO three
one TWO three
one TWO three
one $WO three
Some more text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With