开发者

Making Emacs tabs behave exactly like vim's

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 Backsp开发者_JAVA技巧ace 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.


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:

(eval-after-load "cc-mode"
  '(define-key c-mode-map (kbd "TAB") 'self-insert-command))

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:

(global-set-key (kbd "DEL") 'backward-delete-char)
(setq c-backspace-function 'backward-delete-char)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜