Vim - indentation such as Emacs

I use vim (the main one so that I can work on a simple ssh terminal - still inconvenient with the non-gui version of Emacs), but most of my colleagues in the organization use emacs. Thus, using CVS, we are faced with indentation inconsistencies (tabs become spaces, number of tabs / spaces, code markup, etc.).

Is there a way that I can indent VIM EXACTLY as EMACS. (similar to the default emacs profile that my colleagues use).

(Most importantly, I want vim C ++ and TCL indentation schemes to match emacs schemes).

Yours faithfully,

In JP

+6
vim indentation emacs
source share
3 answers

I don’t know if there is a way to directly import Emacs insertion settings into vim, but you can probably configure the same behavior in vim itself:

set expandtab converts tabs to spaces
set autoindent keep the level of indentation from the previous line
set shiftwidth=4 will affect block indentation using β†’ and << set softtabstop=4 sets the length of the soft tab in spaces
set tabstop=8 sets the width of the tab character

This is explained in the vim wiki .

If you need a separate indentation of type filetype, you have two options:

  • Install autocmd to change the indentation when reading a file and creating a file:
    au BufRead,BufNewFile *.py,*pyw,*.html,*.js set shiftwidth=4 set the shiftwidth for * .py files.
  • Set up the filetype plugin, create name.vim scripts inside the .vim/ftplugin for certain types of files and set the described variables there. This is also described in detail in the vim wiki .
+5
source share

As for the specialized indentation for C ++ and TCL, that is, special material that is applied in aditon to all the other configuration data that has been proposed. Vim has special indentation rules defined in the code for different languages. Some of these are found in the / indent directory of the vim installation, where there is a separate file for each file type. For more information on how this works, read the help for "indentexpr".

Indentation c and, I think, also indentation for C ++ are mainly defined in the Vim source code and have many parameters that you can set, plus it is specially configured in c.vim or C ++. vim indent file. Read the help for "cindent" and "c-indenting" for more help.

In short, the tcl.vim file manages special indentation for tcl files. If you want to reconsider how indents work with tcl, you would like to change the main function in this file. The c / C ++ indentation is mainly controlled by the internal components of Vim, but with many different parameter flags. You can control the indentation of c / C ++ by adjusting the parameters as you want, and / or writing a function for the indent file in the / indent directory. (I believe that there is no C ++ file in the / indent directory, I'm not sure if c.vim is a file to edit there, or you need to create a new C ++. Vim file. I think it will be c.vim the file to be used. which is basically an empty shell in a standard Vim installation, but you can read other .vim indent files to get an idea of ​​how they work.

+1
source share

Here, as a snippet of some options regarding indenting from .vimrc:

 set expandtab set tabstop=2 set shiftwidth=2 set autoindent set smartindent 

All options are well described in vim help:

 :help smartindent :help autoindent 

UPD: also for C-like languages ​​you might consider :help C-indenting

0
source share

All Articles