How to avoid typing 80 repeted Characters?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to avoid typing 80 repeted Characters?

jose neta
Hi!

I found my self doing always the same :-(
When I need to code, I need to write comment lines as follow:

#  
Comment-----------------------------------------------------------------
-------------

I lose to much time writting 80 character. And I know that Vim as the  
answer, and that's why I love it.

The firts question is:

How do I repeat for instance the caracther "-" from column x to y.
That must be till column y no matter which size is my comment.
If it was a comment line with a fixed length, I could use the  
command :abbreviate, but it isn't.

The second question is:

How do I delete characters in a line from column x to column y.
For instance; if the statement if:
"How to avoid typing 80 repeted Characters?"

How can I delete from column 4 to 6 (removing the word "to")?


Thank you
Reply | Threaded
Open this post in threaded view
|

Re: How to avoid typing 80 repeted Characters?

Nico Weber-3
Hi,

> #  
> Comment---------------------------------------------------------------
> ---------------
>
> I lose to much time writting 80 character. And I know that Vim as  
> the answer, and that's why I love it.
>
> The firts question is:
>
> How do I repeat for instance the caracther "-" from column x to y.
> That must be till column y no matter which size is my comment.
> If it was a comment line with a fixed length, I could use the  
> command :abbreviate, but it isn't.

You can type a number in front of any command in normal mode to  
repeat it. The easiest way to do what you want to do is

80i-<esc>

(this enters 80 - and leaves the cursor at the end of the line). Now  
type

0R# bla <esc>o

(0 puts the cursor into the first column, R starts replace mode, '#  
bla # enters your comment, <esc> goes back to normal mode, o opens a  
new line and starts insert mode).

This sounds complicated, but can be done quite fast. You can map the  
first keystrokes (80i-<esc>0R) onto a key if you want.

In general, try to do as much as possible in normal mode.

>
> How do I delete characters in a line from column x to column y.
> For instance; if the statement if:
> "How to avoid typing 80 repeted Characters?"
>
> How can I delete from column 4 to 6 (removing the word "to")?

Depends where your cursor is ;-) The fastest 'general' method is to  
hit /to<cr> (to enter incremental search mode, find 'to', place the  
cursor at it) and then hit dw (delete word). If /to<cr> doesn't end  
up at the correct 'to', hit n to go to the next hit (or N for the  
previous hit). use ? instead of / to search backwards. Depending on  
the context, there can be even faster ways to do this.

Bye,
Nico


Reply | Threaded
Open this post in threaded view
|

Re: How to avoid typing 80 repeted Characters?

Benjamin Esham
In reply to this post by jose neta
José Pinheiro Neta wrote:

> How do I delete characters in a line from column x to column y.
> For instance; if the statement if:
> "How to avoid typing 80 repeted Characters?"
>
> How can I delete from column 4 to 6 (removing the word "to")?

To delete from column 4 to column 6, try

   4|v6|d

Since '|' is an exclusive motion, you could also do

   4|d7|

This uses fewer keystrokes, but is much less obvious (since we use 7  
instead of 6).  To delete column 4 and the next two columns to the  
right, use

   4|v2ld     or     4|d3l

Your questions would probably be better asked on the main vim mailing  
list, or perhaps in the comp.editors group; people there can probably  
give you even shorter solutions than these.

HTH,
--
Benjamin D. Esham
[hidden email]  |  AIM: bdesham128  |  Jabber: same as e-mail
Esperanto, the international language  ☆  http://www.lernu.net