简体   繁体   English

Vim 80字符标记,无需添加空格

[英]Vim 80 character marker without adding spaces

I have a marker at 80 characters which I set using 我有一个80个字符的标记,我设置使用

:set colorcolumn=80

But when I do this, if I'm highlighting and copying text to the clipboard, I get spaces after the last character on the line. 但是当我这样做时,如果我突出显示并将文本复制到剪贴板,我会在行上的最后一个字符后面找到空格。 This is very annoying if I'm sending code snippets to people which requires copying using the clipboard. 如果我要向需要使用剪贴板进行复制的人发送代码片段,这非常烦人。

Is there a way to get the marker at 80 characters without those added spaces? 有没有办法让标记为80个字符而没有添加空格?

Also, I have tried highlighting characters after col 80 (and less), but I prefer to see the marker instead of guessing where 80 characters will be. 此外,我尝试在col 80之后突出显示字符(以及更少),但我更喜欢看标记而不是猜测80个字符的位置。

This is because your terminal is handling selections, and has no idea that the spaces vim is using to print the color column are not "real" characters. 这是因为您的终端正在处理选择,并且不知道vim用于打印颜色列的空间不是“真实”字符。 (ie: the terminal only knows what's in its display, not what's in vim's buffer). (即:终端只知道显示器中的内容,而不知道vim缓冲区中的内容)。 If you use gvim it doesn't have this issue. 如果你使用gvim它没有这个问题。

In the console you can simulate the gvim behavior somewhat by using the mouse and clipboard settings. 在控制台中,您可以使用mouseclipboard设置稍微模拟gvim行为。 Something like this should work: 这样的事情应该有效:

set mouse=a clipboard=autoselect

This will cause vim to take over mouse handling even in a terminal, and will tell it to automatically place selected text in the "* register, which corresponds to X11's primary selection. You can set clipboard to autoselectplus if you prefer the clipboard over the primary selection. 这将导致vim甚至在终端中接管鼠标处理,并会告诉它自动将所选文本放在"*寄存器中,这对应于X11的主要选择。如果你喜欢剪贴板而不是主clipboard ,你可以将clipboard设置为autoselectplus选择。

Another option is to just use vim commands instead of the mouse to do this sort of copy and paste. 另一个选择是只使用vim命令而不是鼠标来进行这种复制和粘贴。 You can manually copy to X's primary selection or clipboard by specifying "* or "+ as the register, respectively. 您可以通过分别指定"*"+作为寄存器来手动复制到X的主要选择或剪贴板。 eg: "*y<text-object> or in visual mode just "*y will yank to the selection, and then you can middle-click (or shift-insert in some software) to "paste". 例如: "*y<text-object>或仅在视觉模式下"*y将拉到选择位置,然后您可以在中间单击(或在某些软件中移位插入)以“粘贴”。

A variation of this is to make everything you yank into the default register in vim also end up in the X selection or clipboard: 这种做法的一个变体是让你在vim中进入默认寄存器的所有内容也最终出现在X选择或剪贴板中:

set clipboard=unnamed       " copies to X's primary selection

or 要么

set clipboard=unnamedplus   " copies to X's clipboard

Note that all of these require a build of vim that has X support compiled in and $DISPLAY must be set accordingly. 请注意, 所有这些都需要构建具有编译的X支持的vim,并且必须相应地设置$DISPLAY

See also: 也可以看看:

  • :help 'clipboard'
  • :help 'mouse'
  • :help X11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM