Arrêtez vim indenter de nouvelles lignes après une virgule dans des fichiers texte


2

J'utilise vim / gvim comme éditeur de texte par défaut.

Lorsque je modifie des fichiers de texte brut sans mise en surbrillance de la syntaxe, cela ajoute automatiquement une indentation lorsque j'appuie sur Entrée, si le dernier caractère de la ligne terminée est une virgule.

Cette indentation est de longueur variable, pour placer le curseur sous le premier mot de la ligne précédente.

par exemple la séquence de touches

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

produit cette

a b
a b,
  a b

Si je :setlocal filetype?je reçois filetype=text.

Voici mon ~/.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

Je ne veux pas que vim essaie d'être intelligent avec des fichiers texte. Comment désactiver cette option tout en laissant l'option d'indentation automatique / intelligente activée pour les autres types de fichiers?


Cela n'a rien à voir avec auto- ou smartindent. Nous aurions besoin que vous .vimrcreproduisiez ceci. Un type de fichier est-il détecté pour ces fichiers de texte brut ou est-il :setlocal filetype?vide?
Ingo Karkat

@IngoKarkat J'ai mis à jour la question
spraff

Réponses:


2

Cela est causé par l' 'cindent'option activée . J'ai essayé de jouer avec les 'cino'options, mais apparemment, cela n’a pas d’incidence (mais j’ai peu d’expérience avec celles-ci).

Je pense que vous devriez désactiver c-indenting pour les fichiers de texte brut, et aller simplement avec smart- et autoindent.

Comme vous avez une détection de type textde fichier (to ) pour ces fichiers, ajoutez simplement ce qui suit:

Mettez la setlocal nocindentcommande correspondante dans ~/.vim/ftplugin/text.vim. (Cela nécessite que vous ayez :filetype plugin on.)

Alternativement, vous pouvez définir un :autocmd FileType text setlocal nocindentdirectement dans votre ~/.vimrc, mais cela tend à devenir difficile à manier une fois que vous avez beaucoup de personnalisations.

En utilisant notre site, vous reconnaissez avoir lu et compris notre politique liée aux cookies et notre politique de confidentialité.
Licensed under cc by-sa 3.0 with attribution required.