0

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 ?

4
  • 2
    Can you update the "broken" one (if so, does that fix it)? See also How to debug my vimrc and try :verbose setlocal ts? sw? sts? et? ai? formatoptions? indentexpr? indentkeys?
    – D. Ben Knoble
    Commented Jul 8 at 19:58
  • My system is up to date. and this is the vim version that comes with Debian/raspbian. So I'd say i can't upgrade to 9.1.
    – exore
    Commented Jul 9 at 0:30
  • @D.BenKnoble, Thank you for the "how to debug" pointer. I'll check that and update the question.
    – exore
    Commented Jul 9 at 0:32
  • 1
    First things first: establish a baseline with $ /path/to/vim filename +set\ modeline in both environments.
    – romainl
    Commented Jul 9 at 6:59

1 Answer 1

0

The se doesn't correspond to any Vim 9.1 option.

I would remove the se part of the modeline and do:

#!/usr/bin/env python3
# vim: ts=2 sw=2 et ai mouse=:
12
  • 1
    thanks for the answer, but I already use the modeline line and it doesn't work as expected.
    – exore
    Commented Jul 9 at 0:23
  • 2
    @Vivian may I respectfully suggest that some explanation in addition to "I would do" would do a good job of hinting to the subtle changes you introduced?
    – Friedrich
    Commented Jul 9 at 5:40
  • 1
    Thanks @Friedrich :-) I have made an attempt to make my intention a bit less cryptic. Commented Jul 9 at 5:58
  • 2
    @VivianDeSmedt, «The se doesn't correspond to any Vim 9.1 option». Indeed, because that's not an option. That's the abbreviation of the set command. See vimhelp.org/options.txt.html#modeline . the modeline as it is, is a perfectly valid modeline. The form you suggest, with no se command, traditionally does not end in :, although vim accepts it and happily deals with an empty implicit set command.
    – exore
    Commented Jul 10 at 16:32
  • 2
    (You can put all the :verbose setlocal together; see vi.stackexchange.com/questions/45174/… which I think we're still waiting on.)
    – D. Ben Knoble
    Commented Jul 10 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.