Selecting a large amount of text that extends over many screens in an IDE like Eclipse is fairly easy since you can use the mouse, but what is the best way to e.g. select and de
You should be aware of the normal mode command [count]CTRL-D. It optionally changes the 'scroll' option from 10 to [count], and then scrolls down that many lines. Pressing CTRL-D again will scroll down that same lines again.
So try entering
V "visual line selection mode
30 "optionally set scroll value to 30
CTRL-D "jump down a screen, repeated as necessary
y " yank your selection
CTRL-U works the same way but scrolls up.
v enters visual block mode, where you can select as if with shift in most common editors, later you can do anything you can normally do with normal commands (substitution :'<,'>s/^/#/ to prepend with a comment, for instance) where '<,'> means the selected visual block instead of all the text.
My usual method for commenting out 40 lines would be to put the cursor on the first line and enter the command:
:.,+40s/^/# /
(For here thru 40 lines forward, substitute start-of-line with hash, space) Seems a bit longer than some other methods suggested, but I like to do things with the keyboard instead of the mouse.
Or you may want to give this script a try...
http://www.vim.org/scripts/script.php?script_id=23
Well, first of all, you can set vim
to work with the mouse, which would allow you to select text just like you would in Eclipse
.
You can also use the Visual selection - v, by default. Once selected, you can yank
, cut
, etc.
As far as commenting out the block, I usually select it with VISUAL
, then do
:'<,'>s/^/# /
Replacing the beginning of each line with a #
. (The '<
and '>
markers are the beginning and and of the visual selection.
First answer is currently not quite right? To comment out selection press ':' and type command :'<,'>s/^/# /g
('<, '> - will be there automatically)