Friday, August 11, 2006

vertical selection from Nth to Mth character

ZOMG! I got e-mail. That stuff apparently got indexed by Google. So. Here we go.

I do have a question for you, however. When performing a vertical selection, is there any way to advance the screen other than the arrow keys? For instance, if a file were thousands of lines long, is there a way to quickly select characters 10 through 20 for the entire length?


All motion shortcuts must work as usual. (:help motion.txt) In other words. To select vertically across all lines in the file chars 10 to 20 you need something like that (those " are comments):


gg " move to beginning of file, beginning of line
9l " move to 10th symbol in line (l == move 1 char left,
" 9l == move 9 times chars left)
^V " start vertical selection
G " move to last line of file, beginning of line
19l " move to 20th symbol in line.


now y/d/whatever to yank/delete/etc. IOW, no magic - standard shortcuts. I hope that answers your question.

Though there might be problem: if last line of file shorter than 20 characters, or if first line shorter than 10 characters, or tab character is sitting somewhere there - VIM wouldn't be able to do precisely what you want it to do.

P.S. For later case shell comes in handy: man cut for -b & -c options. Using redirection and intermediate file you can get you part into separate file and then open it (along with original) in VIM - and use normal line blocks. With combination of head and tail (man head & man tail) you can get from file lines you need.

No comments: