5

When I am in a CSS file with a blank line, like this:

enter image description here

and I want to simply make a new line and move down to it, by hitting Enter , vim is auto inserting a tab character, e.g.

enter image description here

Running :set fo? inside the CSS file => formatoptions=croql.
If I disable all formatoptions with :set fo= - it still happens.
however if format options are disabled using :set paste vim does stop inserting the tab - but I dont want to have to work in paste mode all the time!

settings:

  • noautoindent
  • nosmartindent
  • nocindent

If I turn off filetype specific indenting with

filetype indent off

It still happens, what am I missing - do I need to restart vim or something for the settings to take effect?

How can I stop vim autoinserting these tab characters?

7

I found a couple of ways to solve the problem.

1. reload the buffer after running :filetype indent off

Vim's docs (:help :filetype-indent-off) provided an explanation:

You can disable :filetype indent on with:

:filetype indent off

This actually loads the file "indoff.vim" in 'runtimepath'. This disables auto-indenting for files you will open. It will keep working in already opened files. Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.

  • "It will keep working in already opened files." - explained that I simply had to kill and reload the buffer after I ran the command :filetype indent off

2. Reset indentexpr

per docs

Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.

it turned out the issue was caused by indentexpr which had the value of

indentexpr=GetCSSIndent()
Last set from /usr/share/vim/vim74/indent/css.vim

I was able to reset it with: :set indentexpr=""

which also fixed the problem.

| improve this answer | |
1

This issue has already been answered, but I though I could also add my solution:

As suggested by filbranden, it's better to not modified vim's system files. Instead, he suggested to use skip_defaults_vim=1 or create a .vimrc file in my home directory to disable the default features. If I want any of the default features, I can add them to my .vimrc file.

In my case (vim 8.1), disabling the defaults does the trick. I like vim highlight feature, but that feature is defined elsewhere so disabling the defaults do not disable highlighting.

I added the following line at the beginning of /etc/vim/vimrc:

let skip_defaults_vim=1

----------- Old answer (not recommended) -----------

If you simply want to disable auto-indent system wise, for every file type (basically, disable the auto-indent feature completely), you can do the following:

  1. Backup the indent.vim file:
    sudo mv /usr/share/vim/vim81/indent.vim /usr/share/vim/vim81/indent.vim.orig
  2. Create a new empty indent.vim file:
    sudo touch /usr/share/vim/vim81/indent.vim

IMPORTANT NOTE: Modifying system files is not recommended. It can have unexpected side effect. Also, the modification is likely to be overwritten on the next vim update. Avoid this solution if possible.

| improve this answer | |
  • Welcome to Vi and Vim! This will break as soon as you upgrade the Vim package in your system, which will overwrite this file back to its original contents... The indent.vim file is being loaded by the file type detection code, and you can disable indent support easily by adding filetype indent off to your vimrc file instead, that's a much better approach. – filbranden Sep 18 at 2:35
  • Thanks filbranden. I wish that approach would work, that would be much cleaner. Unfortunately, at least on Ubuntu, adding filetype indent off at the end (or even at the beginning of the file) of /etc/vim/vimrc has no effect. – Gael Sep 18 at 3:21
  • That's because filetype plugin indent on will be executed by $VIMRUNTIME/defaults.vim which is run if the user has no .vimrc in their home directory, and it runs after the system-wide vimrc. You should really use a user vimrc file and not the system one... If you want to disable the defaults.vim file, you can use let skip_defaults_vim = 1 in your system vimrc file (but note that defaults.vim sets up a lot of other useful stuff, such as syntax highlighting.) See :help defaults.vim for details. – filbranden Sep 18 at 3:49
  • I have restored the /usr/share/vim/vim81/indent.vim file and verified that the auto-indent was back. Then I touch ~/.vimrc to create an empty .vimrc file. The auto-indent is gone! Thanks. NOTE: I tried this earlier (a few version of vim back, when I was running Debian). After creating an empty .vimrc in my home directory, I would lose a lot of features, such as highlighting which I like. I will edit my answer. – Gael Sep 18 at 4:59
-1

Yes this solved for me also this unkind effect:

I opened, and edited my ~/.vimrc

:filetype indent off

If you do not like the higlight scheme, you just search the selected colorscheme here:

/usr/share/vim/vim74/colors

i use generaly "colorscheme desert", in the 77-th row you find:

  hi Search cterm=NONE ctermfg=grey ctermbg=lightblue
  hi Search cterm=bold ctermfg=black ctermbg=green

that was for me better than the lightbue

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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