Hello everyone! I have the following settings for making TAB insert spaces rather than the \t character:
set tabstop=2
set shiftwidth=2
set shiftround
set expandtab
I understand that filetypes can override them and some of them must do in order to work properly (biggest example the Makefile) and I never had any problems until for now that I’m using Rust and it overrides my rules and it uses 4 spaces instead of 2. I made my research and I was able to find a way to change the setting for this filetype using the following option: autocmd Filetype rust setlocal tabstop=2 and it works!!! Well it does but I it will not work when I start the editor, I have to reload the config using the :source command. I tried without plugins but it’s the same thing. Any suggestions?
Are you using the rust.vim plugin? If so this is expected. The plugin sets all these options to what is recommended for Rust code.
You can change it by adding this setting to your config:
*g:rust_recommended_style*
g:rust_recommended_style~
Set this option to enable vim indentation and textwidth settings to
conform to style conventions of the rust standard library (i.e. use 4
spaces for indents and sets 'textwidth' to 99). This option is enabled
by default. To disable it: >
let g:rust_recommended_style = 0
<
Though to be honest I would not actually change this if I don’t have a good reason to do so, it will conflict with rustfmt and other peoples Rust code written with the recommended style. Your choice though…
I’m basically in the same boat. Put that stuff in ~/.config/nvim/after/ftplugin/rust.vim (or the equivalent location for your path settings), and you’ll be ok.
No I don’t use the plugin but thanks a lot for your time. Also when it comes to the recommended style, it’s not that I don’t respect it but It really makes a huge deference (100% actually) to have 2 vs 4 spaces and I thinks that 2 does the job and 4 just wastes extra space. Maybe it looks better in my editor idk…