以下是我的 .vimrc 文件的全部内容:
出于某种原因,set wrap和set textwidth=73(在文件底部)不起作用(我想让文件在 73 列处换行)。我仍然可以进入一个文件并输入超过 73 列。
这里是否有需要修复的冲突命令?还是我做错了什么?
set nocompatible
set smartindent
set cursorline
filetype plugin indent on
set background=dark
syntax enable
set grepprg=grep\ -nH\ $*
syntax on
set mouse=a
set history=1000
set showmode
if has('cmdline_info')
    set ruler                   " show the ruler
    set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " a ruler on steroids
    set showcmd                 " show partial commands in status line and
endif
set backspace=indent,eol,start      " backspace for dummys
set linespace=0                 " No extra spaces between rows
set nu                          " Line numbers on
set showmatch                   " show matching brackets/parenthesis
set incsearch                   " find as you type search
set hlsearch                    " highlight search terms
set winminheight=0              " windows can be 0 line high 
set ignorecase                  " case insensitive search
set smartcase                   " case sensitive when uc present
set wildmenu                    " show list instead of just completing
set wildmode=list:longest,full  
set scrolljump=5                " lines to scroll when cursor leaves screen
set scrolloff=3                 " minimum lines to keep above and below cursor
set gdefault                    " the /g flag on :s substitutions by default
set autoindent                  " indent at the same level of the previous line
set shiftwidth=4                " use indents of 4 spaces
set expandtab                   " tabs are spaces, not tabs
set tabstop=4                   " an indentation every four columns
set softtabstop=4               " let backspace delete indent
set matchpairs+=<:>
set comments=sl:/*,mb:*,elx:*/
autocmd FileType c,cpp,java,php,js,python,twig,xml,yml autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
set foldmethod=syntax  "fold based on indent
set foldnestmax=10      "deepest fold is 10 levels
set foldlevel=0         "this is just what i use
set wrap
set textwidth=73
set formatoptions+=t
编辑:我希望 VIM 自动换行 73 行(实时)。那可能吗?我试过添加set formatoptions+=t换行文本,但它仍然无效。
也许不是最好的解决方案,但尝试在自动命令中分配textwidth和formatoptions,然后格式化文件的所有行。
autocmd BufRead * set fo+=t tw=73|normal gggqG
这在我的测试中有效。您可以更具体,并*用*.txt或类似替换。