2

I use vim/gvim as my default text editor.

When I'm editing plain text files with no syntax highlighting, it automatically adds indentation when I press enter, if the last character on the finished line is a comma.

This indentation is variable length, to bring the cursor under the first word in the previous line.

e.g. the key sequence

a <space> b <enter> a <space> b , <enter> a <space> b 

produces this

a b
a b,
  a b

If I :setlocal filetype? I get filetype=text.

Here is my ~/.vimrc:

if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup      " do not keep a backup file, use versions instead
else
  set backup        " keep a backup file
  set backupdir=/home/bernie/.vim/tmp
  set directory=/home/bernie/.vim/tmp
endif
set history=500     " keep 50 lines of command line history
set ruler       " show the cursor position all the time
set showcmd     " display incomplete commands
set incsearch       " do incremental searching


  set autoindent    " always set autoindenting on
  set smartindent   " guesses indents
  set cindent       " more flexible indenting.
    set cino =>s,   " 1 tab after each brace
    set cino+=e0,       " Braces starting on a new line treated the same
    set cino+=n0,       " Treat ifs the same even if there are no braces
    set cino+=f0,       " Functions aren't special either.
    set cino+={0,}0,^0, " No per-brace fiddling.
    set cino+=:0,=s,    " Don't indent "case"s but indent their bodies
    set cino+=l1,       " Cases with braces get no extra indentation
    set cino+=g0,h0,    " No extra indents for "public", "private", etc.
    set cino+=p0,t0,    " No extra indents for function types and locals
    set cino+=+s,       " Continued lines are indented.
    set cino+=cs,C1,N0, " Indent multi-line comments.
    set cino+=)50,*50   " Search wide for unclosed brackets and comments
                " Don't understand the (n un Un wn mn commads
  set guioptions-=T " no toolbar
  set vb t_vb=      " flashing
  set columns=80
  set lines=80
  colorscheme koehler

  set autowrite         " save all buffers before certain commands

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  augroup END

else

endif " has("autocmd")

set guifont=Monospace\ 8

set formatoptions-=t

I don't want vim to try to be clever with plain text files. How do I turn this off, but leave auto/smart indentation on for other file types?

  • This has nothing to do with auto- or smartindent. We'd need your .vimrc do reproduce this. Is any filetype detected for those plain text files, or is :setlocal filetype? empty? – Ingo Karkat Sep 4 '18 at 9:02
  • @IngoKarkat I have updated the question – spraff Sep 4 '18 at 11:09
1

That is caused by the enabled 'cindent' option. I tried fiddling with the 'cino' options, but apparently it is not affected by that (but I have little experience with those).

I think you should disable c-indenting for plain text files, and just go with smart- and autoindent.

As you have a filetype detection (to text) for those files, just add the following:

Put the corresponding setlocal nocindent command into ~/.vim/ftplugin/text.vim. (This requires that you have :filetype plugin on.)

Alternatively, you could define an :autocmd FileType text setlocal nocindent directly in your ~/.vimrc, but this tends to become unwieldy once you have many customizations.

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.