以下是我的.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
来包装文本,但它仍然无效。
答案 0 :(得分:3)
选项wrap
和textwidth
会考虑两种完全不同的包装。
textwidth
设置线宽限制,之后每个新单词(表示用空格分隔)将放在一个新行中。
附加.vimrc
可能正常工作,而textwitdh
正是这样做的。
wrap
根本不会影响已编辑的文件内容,只会导致文件中的行显示为多行(如果长度超过显示宽度)。如果发现没有令人愉快的方式来配置它以固定的列宽包裹,我个人认为没有这种需要。
然而,如果你发现屏幕末端的软包装很烦人,可以改变软包装的两个方面。
set columns=73
更改Vim窗口的宽度(这非常令人不安,因为它会改变整个窗口的宽度)linebreak
选项,请参阅help linebreak
了解详情。答案 1 :(得分:2)
也许不是最佳解决方案,但尝试在自动命令中分配textwidth
和formatoptions
,然后格式化文件的所有行。
autocmd BufRead * set fo+=t tw=73|normal gggqG
这在我的测试中起作用。您可以更具体,将*
替换为*.txt
或类似。
答案 2 :(得分:0)
将其放入对我有用的.vimr
c中:
autocmd FileType * set textwidth=58