Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Printing from VIM...I feel very stupid
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1090

PostPosted: Tue Jul 23, 2019 11:49 pm    Post subject: Printing from VIM...I feel very stupid Reply with quote

Hi I feel so stupid right now, every time I try to search documentation online for this I am getting some strange crap about postcript printing from a MS-Windows machine, and from the alternate program called gvim, which is not installed.

My version of Vim is the regular out of the box one with gentoo. How would I set up printing from within that, or am I essentially forced to spawn a new terminal and navigate to that file and issue the lpr command.

My printer drivers are all working and I have CUPS daemon running as a service too with wrapper around the printer lp drivers for it.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14922

PostPosted: Wed Jul 24, 2019 2:06 am    Post subject: Reply with quote

At worst, you could do :!lpr %, which would run lpr on the current file. There is no need to open a terminal just for that. There might be a more elegant way to do your particular task. This version works on anything that can take a filename, not just lpr. For programs that can work from stdin, there is also :w !lpr, which would run lpr without arguments and write the current file to its stdin. Whether that does anything useful will depend on lpr.
Back to top
View user's profile Send private message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1090

PostPosted: Wed Jul 24, 2019 5:31 am    Post subject: Reply with quote

Thanks Hu, as it turned out this was another situation of “user error” when i went back to the terminal to print the file I became aware of lp not having a default printer. And once i fixed this it became a simple matter of trying again from within vim with the command :hardcopy

Worked nicely!

But great to know about the stdin method is that the same or different from redirecting input like in a bash setting? In other words is it specific to a setting like the command line in vim or elsewhere too? Definitely need to be reading up on this kind of thing. But my first thought within this context is it might not actually work since I was under the impression that the line printer does prefer to deal with the plain format of input of course i could be wrong :wink:
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14922

PostPosted: Thu Jul 25, 2019 1:45 am    Post subject: Reply with quote

It is the same concept, but not quite the same implementation:
Code:
ls -l /dev/fd/ < /etc/passwd ; vim -c 'ls -l /dev/fd/' /etc/passwd
In the first, you see that stdin is actually /etc/passwd. In the second, at least for me, you see that stdin is a temporary file which, if you had the tools to inspect it, would be found to have a copy of /etc/passwd. The specific :w !lpr requires lpr to accept plain text on stdin and do something useful with it. If your configuration doesn't satisfy those assumptions, it won't work.

As an interesting trick you can do with this, run :w !grep -c expr to have grep count the number of occurrences. That is mildly useful. Now mix it with Vim's range specifier: :5,25w !grep -c expr to count expr only in lines 5-25, inclusive.
Back to top
View user's profile Send private message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1090

PostPosted: Sun Jul 28, 2019 4:01 am    Post subject: Reply with quote

Vim tricks are super cool thanks for sharing. Actually just wondering if you know why it is that the following command won't work within vim automatically

:!w3m %

With this command w3m opens without an empty file or no file in the buffer, which is kinda weird. Because if I actually start with this command, but then use the tab-expand feature to replace the entire filename then it does work of loading the document in the browser. I don't really plan to use this feature much, but trying to get comfortable with the limitations of the filename replacement operator in vim.


EDIT:
And yes by the way my machinewas set up to handle :w !lpr that worked smooooothly
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14922

PostPosted: Sun Jul 28, 2019 3:47 pm    Post subject: Reply with quote

That looks like it ought to work. Does the filename have characters that require quoting? Consider:
Code:
$ vim 'a b c'
:!sh -c 'echo $\#; echo +$@-' %
2
+b c-
:!sh -c 'echo $\#; echo +$@-' "%"
0
+-
Thus, quoting of % matters. See :help :! for the details.
Back to top
View user's profile Send private message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1090

PostPosted: Sun Jul 28, 2019 7:07 pm    Post subject: Reply with quote

Cool
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum