I'm trying to use nvim for everything, including writing, and all is great but the text is too crammed when I print it out.
Is it possible to adjust the line spacing when printing with :hardcopy?
My idea of a kludge fix would be to insert a second newline character for every carriage return, including those automatically inserted by line wrapping. Is this possible?
One of the least frustrating ways to do it would be to use a tool like pandoc to convert the text (for example Markdown) to whatever format you need — preferably PDF. However, pandoc uses LaTeX to create the resulting PDF, so regarding the styling you would have to tinker with supplying it a template or other options.
You can do it even easier with (for example) a Node.js tool called mdpdf. After installation, just run
mdpdf file.md --style styles.css
to supply it with a CSS stylesheet in which you can modify the resulting text output with every feature CSS permits. Using larger line spacing would be something like this:
body { line-spacing: 150%; }
This results in a 1.5x line spacing for everything in the document.
Of course, you can also set up a custom Vim command to automate this for you, putting something like the following into your .vimrc:
command MdToPDF !mdpdf %:t --style /full/path/to/styles.css
Calling :MdToPDF in Vim will then run that command for you.
Finally, if you're happy with the output, just print the PDF.
Related
I've been using vim for a few weeks, and so far I've downloaded a few plugins including airline, nerdtree, and a colorscheme. When I downloaded some files with wget, I noticed that they weren't properly aligned. Text in the code files are normally supposed to be aligned in columns, and there generally shjouldn't be issues with indentation. As an example, when I try running the command cat filename.extension, I get this:
This is how the file is supposed to look. Everything is aligned neatly into columns without any issues. However, if I try editing the file in Vim, it instead looks like this:
The text for whatever reason is not aligned properly, and so far I am not sure how to resolve it...
The file appears to be using tabulations for indentation and alignment.
The de-facto standard width of a tabulation is 8 characters.
cat respects that "standard" to the letter, without the possibility of changing the tabulation width.
Vim also respects it by default but it allows the user to change the tabulation width and you tell it to use a tabulation width of 4 characters.
The file looks different because the two programs have different tabulation settings.
Therefore, if you want the file to look the same in the two programs, use the same tabulation settings. Since they can't be changed in cat, you will have to revert Vim's to their default values.
You didn't show us your vimrc so we don't know exactly what you did and we can't really tell you how to go about it.
I'm trying to take a screenshot of some minified js code so that I can print it onto something. I'm having trouble finding an editor/IDE that can wrap the text properly.
Notice how the right side is jagged because it only wraps after a complete word.
What I'm trying to achieve
https://alpha.wallhaven.cc/wallpaper/120534
Is there a text editor/plugin that lets me wrap text mid-word like this?
I suggest using vim. It wraps the text half way through a word by default but you can configure it to break on spaces using the :set linebreak command.
I am working with text files that contain a lot of unicode characters (≼, ⊓, ⊔, ...). Vim displays them fine, but when I print they are replaced by a generic character. Gedit prints them without problem, but it's a bit of a pain to launch another editor just to print.
Is there a way to get vim (on Linux/Gnome) to print properly? I tried using vim-gnome, in hope that it would use the same infrastructure as gedit, but it does not.
Vim is only able to use 8-bit encoding for printing. If there is encoding that includes all those characters all you need is to use
set printencoding={encoding}
If there is not then you can’t print it from vim directly. You can use :TOhtml command suggested by #DaoWen, do
:TOhtml
:w /tmp/print.html
:!command-that-makes-browser-print-a-file(I-do-not-know-one) /tmp/print.html
:!rm /tmp/print.html
. You can also use my formatvim plugin to print this to pdf through latex (don’t forget to file bug reports: latex-xcolor output is untested):
:Format format latex-xcolor to /tmp/print.tex
:!pdflatex /tmp/print.tex && lp /tmp/print.pdf && rm /tmp/print.*
(you can use html output as well, but that will not make me know a command to print it). Of course, you can map these to a single key.
Try using the :TOhtml command to convert your document to output your buffer in HTML format. You should be able to print the resulting file from your browser.
I would like to format my haddock documentation as I do with javadoc, something like inserting html or any other markup that let me get a cleaner output without uncluding any javascript or CSS... Specially, I would like to know how to insert a line break in the documentation.
thanks!
Haddock is designed to work with multiple output formats, including LaTeX, so it uses its own markup format instead of something like HTML.
I don't think you can insert just a line break, but you can start a new paragraph by leaving a blank line, e.g.
-- | First paragraph.
--
-- Second paragraph.
I wanted to print a simple text document and make sure words wrap on word boundaries. I tried both
set linebreak
and
set wrap
but when printing, it just breaks on the right column in the middle of words. Is this possible for printing?
You are creating a text file without any built-in linebreaks so each paragraph is a single "line", even though with linebreak and wrap set, it looks like they are multiple lines). This is why printing breaks at fixed places. (According to http://www.vim.org/htmldoc/various.html#printing it does not seem like you can have vim respect linebreak/wrap during print.)
To avoid this, if you want text to wrap while you are editing, do
set textwidth=70
to wrap at the 70th column. If you want your file to have long lines (e.g., so it formats fine when loaded into MS Word or something), then you will have to pre-process the text version before printing it. So, for example, you can try:
fmt file.txt | lpr
or if you have enscript installed, you should be able to try:
enscript --word-wrap file.txt
to print. An existing file can be wrapped by running in vim:
gggqG
that is, 'gg' to go to start of file and 'gqG' to reformat 'gq' from the current position (i.e. the first line) to the last line (by going to 'G'). 'gq' will respect your current textwidth setting.