Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The help text is a little vague as to what this command achieves.

                    Print [range] lines (default current line).
                    Note: If you are looking for a way to print your text
                    on paper see |:hardcopy|.  In the GUI you can use the
                    File.Print menu entry.
                    See |ex-flags| for [flags].

I know I've used it by mistake to mean :p[rev] several times in the past, but I've never heard the whirring of a printer. Nor have any strange files appeared, nor have I found the line I am on appear in stdout.

So what then, does typing :print do in vim?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Historically, in the 'ed' editor (which many of the core :commands ultimately originate from), the line would go to stdout.

Of course, since vim is a full screen editor, the output of commands doesn't just go unprocessed to stdout, but rather is displayed at the bottom of the window. (one line goes in the command bar, more than one line [technically more than 'cmdheight'] gets "Press ENTER or type command to continue", more than will fit on the screen gets a -- More -- prompt.)

When you simply type :p you will see (you may not have noticed) the line you are on appear in the command bar.

This command is not particularly useful on its own (it was slightly more useful in ed, when the line you are editing would not otherwise be displayed on the screen), but becomes more useful in conjunction with other addressing modes. For example, :g/re/p (where re is any regular expression) has often been claimed to be the origin of the name of the grep command.

share|improve this answer
add comment

It prints the current line, or the range of lines. The :%p command will print the whole file (for example). "Print" doesn't mean "print on printer" (which the manual that you quote points out too) but probably has more to do with the corresponding p command in e.g. sed and ed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.