在 X11 中的终端窗口之间复制和粘贴选项卡

Pet*_*aut 12 xorg xterm less copy-paste

当我在两个终端窗口之间使用 X11 鼠标选择复制和粘贴文本时,选项卡经常(但并非总是)转换为空格。这似乎取决于所涉及的终端应用程序和其中运行的程序。

这是我通过实验发现的:

  • 它完全取决于源(副本)端运行的内容。无论正在运行什么,目标(粘贴)端都会粘贴选项卡,如果源保留了它们。
  • gnome-terminal在源端保留选项卡。 xtermkonsole没有。
  • 仅当文件已使用cat. 其他应用,如lessvimemacs,或nano不保留选项卡。

对此有何解释?这些错误是konsole和 中的xterm,还是可以以不同的方式配置?可以less这样配置以保留输出中的选项卡吗?

Sud*_*ash 0

有时这可能是一个问题,尤其是Makefiles需要选项卡的情况。不幸的是,不同程序的问题并不相关。每个人可能都会有一个非常不同的解决方案。

对于 vim,您必须在文件中执行 a:set noexpandtab或。如果您只想设置某些文件类型,那么您可以在您的“我有以下内容”中执行自动命令:set noexpandtab~/.vimrcnoexpandtab~/.vimrc

"indenting defaults: 4 spaces for an indent
set shiftwidth=4
set softtabstop=4
set expandtab

"exceptions to indenting for specific languages and files--------
"for shell scripts: 2 spaces for an indent
autocmd filetype sh setlocal shiftwidth=2
autocmd filetype sh setlocal softtabstop=2

"for Makefiles: use tabs for indents
autocmd filetype make setlocal tabstop=8
autocmd filetype make setlocal noexpandtab
Run Code Online (Sandbox Code Playgroud)

这将为制表符设置默认的 4 个空格vim,并对 shell 脚本和 Makefile 进行例外处理。

对于其他程序,例如less,请尝试查看那里的手册页。它们可能有您需要的配置文件、环境变量或命令行选项。查看 less 手册页:

-xn,... or --tabs=n,...
       Sets tab stops.  If only one n is specified, tab stops  are  set
       at  multiples  of n.  If multiple values separated by commas are
       specified, tab stops are set at those positions, and  then  con-
       tinue  with  the  same  spacing  as  the last two.  For example,
       -x9,17 will set tabs at positions  9,  17,  25,  33,  etc.   The
       default for n is 8.
Run Code Online (Sandbox Code Playgroud)

您注意到的不是错误。“这是一个特点。” 唯一的问题是您需要知道如何将其关闭。

  • `less -xn` 将其配置为使用 n 个空格而不是制表符。 `-U` 使其将选项卡显示为 `^I`。我还没有找到一种方法让它发出文字制表符,以便复制文本将粘贴制表符,但我很想知道如何做。 (2认同)