I have this project where python files are indented with 2 chars, not 4.
On my mac, I use macvim (VIM - Vi IMproved 9.1 (2024 Jan 02, compilé Jan 4 2024 03:08:50)). When I edit a file like this:
#!/usr/bin/env python3
# vim: se ts=2 sw=2 et ai mouse=:
Everything is ok. Vim does not try to indent code for me. When I hit TAB, vim adds 2 spaces. I have to press BACKSPACE twice to unindent. That's something I'm used to and the behavior I'm looking for. Example:
def foo():
#<- the cursor stays at column 0.
# Pressing TAB adds 2 chars
# I have to press BACKSPACE twice to get back at column 0.
Now, on "Raspbian GNU/Linux 12 (bookworm)" GNU/Linux, with vim-nox (VIM - Vi IMproved 9.0 (2022 Jun 28, compilé May 04 2023 10:24:44)) modelines are activated too, but the effect with the same modeline is not quite the same.
def foo():
#<- cursor automatically at postition 2, strange for me but acceptable
# but now TAB adds 4 chars and
# pressing BACKSPACE once removes 4 chars
Some default configuration is at work here and tries to help me. Unfortunately, my fingers have been used to the first, more basic behavior for decades, that this help is in fact counterproductive.
more info vim packages:
ii vim-common 2:9.0.1378-2 all Vi IMp
ii vim-nox 2:9.0.1378-2 armhf Vi I
ii vim-runtime 2:9.0.1378-2 all Vi IMp
ii vim-tiny 2:9.0.1378-2 armhf Vi I
file /etc/vim/vimrc.local
" always load defaults early
source $VIMRUNTIME/defaults.vim
" prevent vim to reload defaults and so override the settings we make here
let g:skip_defaults_vim = 1
se background=dark
se ai modeline modelines=5 ruler showmatch showmode noic
se scrolloff=0
"
" Don't let vim use the mouse.
if has('mouse')
set mouse=
endif
if exists('+incsearch')
set noincsearch
endif
if has('syntax')
syntax on
endif
" Tente de désactiver les autoindentations "malines"
se indentexpr= nocindent nosmartindent
" un ruler avec les positions des caractères (offset + 1) en decimal et hexa
se rulerformat=%30(%7o:%-5O%=%l,%c%V%=%P%)
No ~/.exrc
, ~/.vimrc
, ~/.vim/vimrc
, /home/me/project/.vimrc
, /home/me/project/.exrc
.
The question:
How do I, at least, persuade this helping module to use 2 chars not 4 or even better, deactivate it completely ?
:verbose setlocal ts? sw? sts? et? ai? formatoptions? indentexpr? indentkeys?
$ /path/to/vim filename +set\ modeline
in both environments.