停止 vim 在纯文本文件中的逗号后缩进新行

停止 vim 在纯文本文件中的逗号后缩进新行

我使用 vim/gvim 作为我的默认文本编辑器。

当我编辑没有语法高亮的纯文本文件时,如果结束行上的最后一个字符是逗号,则按下回车键时它会自动添加缩进。

此缩进的长度是可变的,将光标置于上一行的第一个单词下方。

例如按键序列

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

产生这个

a b
a b,
  a b

如果我:setlocal filetype?得到了filetype=text

这是我的~/.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

我不想让 vim 巧妙处理纯文本文件。如何关闭此功能,但保留其他文件类型的自动/智能缩进?

答案1

这是由启用的'cindent'选项引起的。我尝试摆弄'cino'选项,但显然它不受此影响(但我对这些没有经验)。

我认为您应该禁用纯文本文件的 c-indenting,而只使用智能缩进和自动缩进。

由于您对这些文件进行了文件类型检测(text),只需添加以下内容:

将相应setlocal nocindent命令输入~/.vim/ftplugin/text.vim。 (这要求您有:filetype plugin on。)

或者,您可以:autocmd FileType text setlocal nocindent直接在中定义一个~/.vimrc,但是一旦您进行了许多自定义,这往往会变得难以处理。

相关内容