0

I defined the following command to export file selection into html file and then use Google Chrome to open it for printing

command! -range WebPrint <line1>,<line2>call Print()
function! Print()
    :'<,'>TOhtml
    :wq
    :!/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome %:p.html
endfunction

One annoying thing is that every time I execute the command, the vim section is gone and I have to type Ctrl-c to go back (hitting <Enter> weirdly execute the command once again). If there a way to automatically return to vim section after the command is run?

1 Answer 1

1

From :help call:

    When a range is given and the function doesn't handle it
    itself, the function is executed for each line in the range,

Your Print function is defined without range, so it is invoked multiple times, once for each line in the selected range.

If that's not what you want, remove <line1>,<line2>.

See also :help function-range-example.

Sign up to request clarification or add additional context in comments.

2 Comments

I see, thanks! Now every time after I call the function, the vim session has been transferred to a bash session saying Press ENTER or type command to continue. Is there a way to automatically go back to vim session?
Use silent !/Applications/.... Probably also with a redraw. See the last two paragraphs under :help !cmd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.