使 Emacs 选项卡的行为与 vim 完全相同
我目前正在学习 Emacs,并且正在尝试设置我的初始化文件。 目前它看起来像这样(在网络上的某个地方找到它):
(setq indent-tabs-mode t)
(setq-default indent-tabs-mode t)
(global-set-key (kbd "TAB") 'self-insert-command)
(setq default-tab-width 4)
(setq tab-width 4)
(setq c-basic-indent 4)
但它的行为不像 Vim 的选项卡样式。
我只是希望它在使用选项卡时表现得像 Vim 一样。 这意味着不要用空格替换制表符(我认为 Emacs 默认情况下会这样做)。
这样每个人都可以按照自己喜欢的制表符宽度编辑文件。我通常使用 4 作为制表符宽度。当我按 Backspace 时,它会向后移动相同的数字,这意味着如果我将 Tab 设置为 4 并按 Tab,那么在我按 Backspace 后,它将返回 4 个字符。 它还应该始终使用 4 个空格作为制表符。因为有时在 emacs 中它不会这样做。
I'm learning currently Emacs and I'm trying to set up my initialization file.
Currently it looks like this (found it somewhere in the web):
(setq indent-tabs-mode t)
(setq-default indent-tabs-mode t)
(global-set-key (kbd "TAB") 'self-insert-command)
(setq default-tab-width 4)
(setq tab-width 4)
(setq c-basic-indent 4)
But it does not behave like Vim's style of tabs.
I just want it to behave like Vim when using tabs.
That means not substituting tabs with spaces (I think Emacs does this by default).
So that everyone can edit files in their preferred tab width. I generally use 4 for the tab width. And that when I press Backspace it will go the same number backwards that means if I've set tab to 4 and I press Tab it shall go back by 4 chars after I've pressed Backspace.
It should also always use 4 spaces for tab. Because sometimes in emacs it does not do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Vim 的制表符处理是可以配置的,因此它不是对您想要执行的操作的良好描述,但您的描述的其余部分在大多数情况下都有足够的信息。
处理选项卡的最简单方法就是永远不使用它们。因此,如果按照您喜欢的方式设置选项卡需要一些工作,请不要感到惊讶。
您已设置 Tab 键来插入制表符。这不是 Emacs 中的习惯:通常使用 Tab 键来缩进当前行。您所做的对于默认值来说已经足够了,但是特定于语言的模式仍然可能使 Tab 缩进。从您包含的
c-basic-indent
来看,我推测您正在处理 C 代码;所以你需要告诉 C 模式你不希望 Tab 缩进。这应该可以做到:您遇到的另一件事是,默认情况下,Backspace 键尝试向后移动一列而不是一个字符。以下应使其删除一个字符:
Vim's tab handling can be configured, so it's not a good description of what you want to do, but the rest of your description has enough information, for the most part.
The easiest way to cope with tabs is never to use them. So don't be surprised if setting up tabs in the way you like them takes a bit of work.
You've set up the Tab key to insert a tab character. That's not the custom in Emacs: usually the Tab key is used to indent the current line. What you've done is enough for the default, but language-specific modes may still make Tab indent. I presume from your inclusion of
c-basic-indent
that you're working on C code; so you need to tell C mode that you don't want Tab to indent. This should do it:Another thing you've run into is that by default, the Backspace key tries to move back by one column rather than one character. The following should make it delete one character: