打印时Vim有不同的配色方案

时间:2014-03-06 17:13:51

标签: vim

_vimrc中有没有办法在打印文件时设置不同的colorscheme?

我喜欢屏幕上的深色背景光文字方案,但显然不能很好地转化为纸张。

编辑:我可以在打印前手动更改方案,然后将其更改回来并且工作正常。只是好奇是否有办法告诉Vim在打印时总是使用特定的方案。

这是:hardcopy输出的内容: enter image description here

4 个答案:

答案 0 :(得分:6)

这样的东西
:command Hardcopy let colors_save = g:colors_name <Bar> colorscheme default <Bar> hardcopy <Bar> execute 'colorscheme' colors_save

也许扔进'bg'选项。如果您关心局部变量,请将其设为函数:

command Hardcopy call Hardcopy()
function! Hardcopy()
  let colors_save = g:colors_name
  colorscheme default
  hardcopy
  execute 'colorscheme' colors_save
endfun

答案 1 :(得分:3)

Vim插件"Printer Dialog"允许配置打印参数,其中一个是用于打印的colorscheme。

安装并配置“打印机对话框”后,在要打印的Vim窗口中按\pd。将打开以下“对话框”:

enter image description here

在其他方面,可以选择用于打印的语法高亮显示。有关详细信息,请参阅:help printer-dialog。 变量g:prd_syntaxList定义了可以选择的语法突出显示。默认为

g:prd_syntaxList = "no,current,default,print_bw,zellner" 

有关如何设置此功能的详细信息,请参阅:help prd_syntaxList

答案 2 :(得分:1)

:hardcopy将始终以白色背景打印。来自:help hardcopy

The current highlighting colors are used in the printout, with the following
considerations:
1) The normal background is always rendered as white (i.e. blank paper).
2) White text or the default foreground is rendered as black, so that it shows
   up!
3) If 'background' is "dark", then the colours are darkened to compensate for
   the fact that otherwise they would be too bright to show up clearly on
   white paper.

然而,我不确定“[...]颜色是如何变暗以补偿[...]”工作,所以你可能仍然想要使用@ benjifisher的解决方案。

或者,您可以使用:TOhtml来获得相同的表示(在这种情况下肯定使用不同的colorscheme),然后以其他方式打印出来。有关相关选项,请参阅:help TOhtml,例如g:html_number_lines

答案 3 :(得分:0)

使用:TOhtml效果很好。它将使用相同的配色方案创建一个html文件。

我喜欢onehalf(有关vim的github下载说明的链接)配色方案,因为它具有简单的明暗方案。两种方案之间的语法高亮显示都相同,除了可以切换的黑白文本。

因此,您可以在计算机上使用深色方案,然后仍然打印出代码,并保留突出显示的常规语法,我觉得这很有用。

这就是我要做的:

  1. 打开我要打印的代码
  2. :colorscheme :onehalflight尚未更改为灯光方案
  3. 运行:TOhmtl,这也会在vim中打开html文件
  4. 转到新的html文件,并将其保存到所需位置 例如,另存为text.html以供下载::w ~/Downloads/text.html
  5. 使用您喜欢的浏览器打开保存的html文件,然后打印或执行任何操作 想要,这很好,因为它使您可以看到要转到多少页面 在断开打印机之前进行打印!