Skip to main content
`:print` is default command, it can be omitted
Source Link
LEI
  • 1.7k
  • 9
  • 18

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//ng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then (if there is more thenthan one line) you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//ng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then (if there is more then one line) you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//ng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then (if there is more than one line) you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//ng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern/p

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then (if there is more then one line) you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//ng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern/p

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//ng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then (if there is more then one line) you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Add g flag and some explanation
Source Link
tommcdo
  • 7.9k
  • 1
  • 32
  • 37

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//nng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern/p

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//n

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern/p

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Quincy's answer is fine, but there's an exact way to do this which doesn't require editing the buffer:

:%s/pattern//ng

This will print a message like 3 matches on 2 lines, and no changes will be made to your buffer.

The n flag makes the :substitute command print the number of matches instead of performing an actual substitution; the g flag enables reporting of multiple matches per line.


Another thing that might be useful to your use case is to print all lines that match a pattern:

:global/pattern/print

which can be shortened to:

:g/pattern/p

This is one of the simplest uses of the :global command (which is mind-bogglingly powerful). It will simply print out all of the lines that match pattern, and then you press Enter or type another command to make it go away.

A bit of trivia: This command is the origin of the name grep, as it would commonly be described as g/re/p, where re stands for "regular expression".

Source Link
tommcdo
  • 7.9k
  • 1
  • 32
  • 37
Loading