如何在 gnome-terminal 中将制表符显示为 4 个空格
实际上 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您还可以使用隐式间隔,而不是写出显式制表位列表:
这会将制表位设置为每
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:
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.我发现的独特解决方案是输入 Terminal:
并将其附加到 ~/.bashrc 如果您想要永久更改。
PS:这显然涵盖了最多 10 个制表符缩进。
The unique solution I found is to type in terminal:
and append it to ~/.bashrc if you want permanent changes.
PS: This obviously cover up to 10 tab indents.
您需要在底层 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).
将其作为“tabs -4”执行的问题是第一个制表位关闭了一个(至少在我的系统上)。例如,如果我输入“tabs -4”,第一个制表位将从第四列开始,前面有 3 个空格,而不是 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:
如果您使用的是 bash,这就是我在 ~/.bashrc 中的内容:
请注意“for ... done”小曲周围的反引号。
编辑:“完成”语句之前的最后一个“+4”当然应该是+${TABWIDTH}。
If you're using bash, this is what I have in my ~/.bashrc:
Note the backticks around the 'for ... done' ditty.
edit: The last '+4' before the 'done' statement should of course have been +${TABWIDTH}.
您还可以执行 tabs -4 ,它将每 4 列设置一个制表位。
You can also do tabs -4 and it will set a tab stop every 4th column.
选项卡 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.)