Beenden Sie das Einrücken neuer Zeilen nach Komma in einfachen Textdateien

311
spraff

Ich verwende vim / gvim als Standard-Texteditor.

Beim Bearbeiten von Nur-Text-Dateien ohne Hervorhebung der Syntax wird automatisch ein Einzug hinzugefügt, wenn ich die Eingabetaste drücke, wenn das letzte Zeichen in der fertigen Zeile ein Komma ist.

Diese Einrückung hat eine variable Länge, um den Cursor unter das erste Wort in der vorherigen Zeile zu bringen.

zB die Tastenfolge

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

produziert dies

a b a b, a b 

Wenn ich :setlocal filetype?komme ich filetype=text.

Hier ist mein ~/.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, " 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 

Ich möchte nicht, dass vim versucht, mit einfachen Textdateien klug zu sein. Wie kann ich diese Option deaktivieren, aber für andere Dateitypen die automatische / intelligente Einrückung aktiviert lassen?

2
Das hat nichts mit Auto- oder Smartindent zu tun. Wir brauchen Ihre `.vimrc`, um dies zu reproduzieren. Wird für diese Nur-Text-Dateien ein Dateityp erkannt oder ist der Datentyp "setlocal" leer? Ingo Karkat vor 5 Jahren 0
@IngoKarkat Ich habe die Frage aktualisiert spraff vor 5 Jahren 0

1 Antwort auf die Frage

1
Ingo Karkat

Dies wird durch die aktivierte 'cindent'Option verursacht. Ich habe versucht, mit den 'cino'Optionen herumzuspielen, aber anscheinend ist das davon nicht betroffen (aber ich habe wenig Erfahrung damit).

Ich denke, Sie sollten c-indenting für Nur-Text-Dateien deaktivieren und einfach Smart- und Autoindent verwenden.

Da Sie über eine Dateityperkennung textfür diese Dateien verfügen, fügen Sie einfach Folgendes hinzu:

Setzen Sie den entsprechenden setlocal nocindentBefehl in ~/.vim/ftplugin/text.vim. (Dies erfordert, dass Sie haben :filetype plugin on.)

Alternativ können Sie :autocmd FileType text setlocal nocindentdirekt eine in definieren ~/.vimrc, die jedoch bei vielen Anpassungen schwerfällig wird.