Emacs tab creation behaves exactly like vim's

I am currently studying Emacs and I am trying to customize an initialization file. Currently it looks like this (found it somewhere on the Internet):

(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 a Vim tab style.

I just want it to behave like Vim when using tabs. This means not replacing the tabs with spaces (I think Emacs does this by default).

So everyone can edit files in their preferred tab width. I usually use 4 for tab width. And when I press Backspace, it will go back to the same number back, which means that if I set the tab to 4 and I press Tab, it will go back 4 characters after I press Backspace. It should also always use 4 spaces for the tab. Because sometimes in emacs it does not.

+6
source share
1 answer

Vim tab processing can be configured, so it is not a good description of what you want to do, but there is enough information in the rest of your description. Mostly.

The easiest way to handle tabs is to never use them. So don't be surprised if setting up tabs the way you like takes a little work.

You set the Tab key to insert a tab character. This is not the case in Emacs: typically, the Tab key is used to indent the current line. What you did is enough for the default value, but language specific modes can still indent Tab . I assume from your inclusion of c-basic-indent that you are working on C code; so you need to specify C mode so you don't want Tab to back out. This should do it:

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

Another thing you come across is that, by default, the Backspace key tries to go back one column, not one character. The following should remove one character:

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

Source: https://habr.com/ru/post/891306/


All Articles