Word Count

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

Word Count

Matthew Singleton
I'm looking for a way to count the number of words in a block of text.  I
am a bit of a vim novice.  What I'm doing now is, selecting a block in
visual mode, and then typing

:!wc -w

This is taking the selection as input to the shell command, and replacing
the selection with the output (the word count).  It's not too much of an
annoyance to just hit u and go on with my life, but it would be nice if
there were some way to pipe a selection to a shell command without
replacing the input with the output.  Is there a solution?

Matt
Reply | Threaded
Open this post in threaded view
|

Re: Word Count

Gerald Lai-2
On Mon, 6 Feb 2006, Matthew Singleton wrote:

> I'm looking for a way to count the number of words in a block of text.  I
> am a bit of a vim novice.  What I'm doing now is, selecting a block in
> visual mode, and then typing
>
> :!wc -w
>
> This is taking the selection as input to the shell command, and replacing
> the selection with the output (the word count).  It's not too much of an
> annoyance to just hit u and go on with my life, but it would be nice if
> there were some way to pipe a selection to a shell command without
> replacing the input with the output.  Is there a solution?

Select a block in visual mode, and hit 'g' followed by 'Ctrl-g'. See
":help word-count".

Hope this helps.
--
Gerald
Reply | Threaded
Open this post in threaded view
|

Re: Word Count

Matthew Winn
On Sun, Feb 05, 2006 at 11:29:11PM -0800, Gerald Lai wrote:

> On Mon, 6 Feb 2006, Matthew Singleton wrote:
>
> >I'm looking for a way to count the number of words in a block of text.  I
> >am a bit of a vim novice.  What I'm doing now is, selecting a block in
> >visual mode, and then typing
> >
> >:!wc -w
> >
> >This is taking the selection as input to the shell command, and replacing
> >the selection with the output (the word count).  It's not too much of an
> >annoyance to just hit u and go on with my life, but it would be nice if
> >there were some way to pipe a selection to a shell command without
> >replacing the input with the output.  Is there a solution?
>
> Select a block in visual mode, and hit 'g' followed by 'Ctrl-g'. See
> ":help word-count".

Also, the answer to the part about sending a selection to a command
without altering the buffer is to use

    :w !command

The space between the w and the ! is required.  If it's omitted then
Vim takes it as meaning ":w! command".

--
Matthew Winn ([hidden email])