如何在 gnome-terminal 中将制表符显示为 4 个空格

发布于 2024-08-17 07:17:43 字数 68 浏览 5 评论 0原文

实际上 gnome 终端将制表符显示为 8 个空格,当您查看文件或查看差异时,这非常烦人,有什么方法可以永久更改此设置吗?

Actually gnome-terminal display tabs as 8 spaces, and this is very annoying when you cat files or view diffs, is there some way to change this permanently?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

风情万种。 2024-08-24 07:17:43

您还可以使用隐式间隔,而不是写出显式制表位列表:

tabs -n

这会将制表位设置为每 n 列出现一次。有关更多信息,请查看选项卡的联机帮助页 http:// manpages.ubuntu.com/manpages/maverick/en/man1/tabs.1.html

Instead of writing out an explicit list of tabstops, you can also use implicit intervals:

tabs -n

This will set tabstops to occur every n columns. For more information, check out the manpage for tabs at http://manpages.ubuntu.com/manpages/maverick/en/man1/tabs.1.html.

乖乖 2024-08-24 07:17:43

我发现的独特解决方案是输入 Terminal:

tabs 5,9,13,17,21,25,29,33,37,41

并将其附加到 ~/.bashrc 如果您想要永久更改。

PS:这显然涵盖了最多 10 个制表符缩进。

The unique solution I found is to type in terminal:

tabs 5,9,13,17,21,25,29,33,37,41

and append it to ~/.bashrc if you want permanent changes.

PS: This obviously cover up to 10 tab indents.

遗弃M 2024-08-24 07:17:43

您需要在底层 tty 上设置制表符宽度,而不是在 gnome-terminal 本身中设置。

理论上,您应该能够使用“setterm -regtabs 4”在 .bashrc 中将制表符宽度设置为 4。

它似乎不适用于我的 Linux 发行版,但当我从远程系统进行 ssh 时它可以工作。

将 tabwidth 重置为 8 的最简单方法是使用“tabs -8”(tabs -d8 可以直观地看到变化)。

You need to set the tabwidth on the underlying tty, not in gnome-terminal itself.

Theoretically, you should be able to use 'setterm -regtabs 4' to set the tabwidth to 4 in your .bashrc.

Doesn't seem to be working on my linux distro, but it works when I ssh from a remote system.

The easiest way to reset the tabwidth to 8 is to use 'tabs -8' (tabs -d8 to get a visual of the change).

简单爱 2024-08-24 07:17:43

将其作为“tabs -4”执行的问题是第一个制表位关闭了一个(至少在我的系统上)。例如,如果我输入“tabs -4”,第一个制表位将从第四列开始,前面有 3 个空格,而不是 4 个。后续的制表位都将正确地用 4 个空格分隔。解决此问题的方法是指定制表位,如下所示:

tabs 1,+4,+4,+4,+4,...

The problem with doing it as "tabs -4" is that the first tab stop is off by one (at least on my system). If I type in "tabs -4", for example, the first tab stop will start in the 4th column with 3 blank spaces in front of it instead of 4. Subsequent tab stops will all be correctly separated by 4 spaces. A workaround to this is to specify the tab stops like so:

tabs 1,+4,+4,+4,+4,...
不必在意 2024-08-24 07:17:43

如果您使用的是 bash,这就是我在 ~/.bashrc 中的内容:

# set tabs to width TABWIDTH
TABWIDTH=4
# for less(1) the option -x4 was added (see above);
# other programs may need their own flags
setterm -regtabs ${TABWIDTH} </dev/tty
tabs -0 </dev/tty
# this erroneously imho sets the first tab at offset 3, not offset 4:
#tabs 1,+${TABWIDTH} </dev/tty
# this works:
tabs 1`for i in {0..40}; do echo -n ",+${TABWIDTH}"; done`
unset TABWIDTH

请注意“for ... done”小曲周围的反引号。

编辑:“完成”语句之前的最后一个“+4”当然应该是+${TABWIDTH}。

If you're using bash, this is what I have in my ~/.bashrc:

# set tabs to width TABWIDTH
TABWIDTH=4
# for less(1) the option -x4 was added (see above);
# other programs may need their own flags
setterm -regtabs ${TABWIDTH} </dev/tty
tabs -0 </dev/tty
# this erroneously imho sets the first tab at offset 3, not offset 4:
#tabs 1,+${TABWIDTH} </dev/tty
# this works:
tabs 1`for i in {0..40}; do echo -n ",+${TABWIDTH}"; done`
unset TABWIDTH

Note the backticks around the 'for ... done' ditty.

edit: The last '+4' before the 'done' statement should of course have been +${TABWIDTH}.

爱冒险 2024-08-24 07:17:43

您还可以执行 tabs -4 ,它将每 4 列设置一个制表位。

You can also do tabs -4 and it will set a tab stop every 4th column.

半衾梦 2024-08-24 07:17:43

选项卡 1、5、9、13、17、21、25 等
似乎工作不完全正确。输入时,当在选项卡上退格时,gnome-terminal 会回退 8 个空格,而不是 4 个。看起来这里有一个 gnome 终端错误。 (注意:如果在 shell 中输入,您将不会看到此内容,因为它会占用制表符来完成文件。您必须首先运行 cat 或 dc 或其他一些不会出于自身目的而使用制表符的命令。)

tabs 1,5,9,13,17,21,25,etc
doesn't appear to work entirely correctly. On input, when backspacing over a tab, gnome-terminal goes back 8 spaces, not four. Looks like there's a gnome-terminal bug here. (Note: you won't see this if typing into the shell, because it usurps tabs for file completion. You have to first run cat or dc or some other command that doesn't arrogate tab characters for its own purposes.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文