Vim配置文件中如何设置光标自动换行

3

我似乎不能在vim 7.3中启用光标换行功能。我已经尝试了其他地方找到的建议,包括以下建议,但没有效果:

  :set whichwrap+=<,>
  :set whichwrap+=>,l
  :set whichwrap+=<,h

有什么建议吗?我已经包含了我的.vimrc文件以防冲突...
syntax on

":set whichwrap+=<,h
set whichwrap+=<,>,[,]

colorscheme koehler
noremap <tab> i
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk

nnoremap ; :
nnoremap : ;

set more                      " use more prompt
set autoread                  " watch for file changes
set number                    " line numbers
set noautowrite               " don't automagically write on :next
set lazyredraw                " don't redraw when don't have to
set showmode
set showcmd
set nocompatible              " vim, not vi
set autoindent smartindent    " auto/smart indent
set smarttab                  " tab and backspace are smart
set tabstop=4                 " 6 spaces
set shiftwidth=2
set scrolloff=5               " keep at least 5 lines above/below
set sidescrolloff=5           " keep at least 5 lines left/right
set history=200
set backspace=indent,eol,start
set linebreak
set cmdheight=2               " command line two lines high
set undolevels=1000           " 1000 undos
set updatecount=100           " switch every 100 chars
set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
set noerrorbells              " No error bells please
set visualbell t_vb=            " and don't make faces
filetype on                   " Enable filetype detection
filetype indent on            " Enable filetype-specific indenting
filetype plugin on            " Enable filetype-specific plugins
set wildmode=longest:full
set wildmenu                  " menu has tab completion
set laststatus=2

set incsearch                 " incremental search
set ignorecase                " search ignoring case
set hlsearch                  " highlight the search
set showmatch                 " show matching bracket
set diffopt=filler,iwhite     " ignore all whitespace and sync

  if v:version >= 700
    " Enable spell check for text files
      autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en
      endif

      " mappings
      " toggle list mode
      nmap <LocalLeader>tl :set list!<cr>
      " toggle paste mode
     nmap <LocalLeader>pp :set paste!<cr>
2个回答

4

你的.vimrc中的以下行存在冲突。注释掉这一行可能会解决问题。

set nocompatible              " vim, not vi

对于自动换行,建议您使用这个,并多使用hl键,而不是左右箭头键:

set whichwrap+=<,>,h,l,[,]

4
这并不是一场冲突,更像是重置了先前设置的一些选项。如果它出现在文件开头,就不会产生任何不良影响。 - Ben
谢谢,这是一些有用的信息。我以为.vimrc本身就使得这个选项毫无意义了。 - Amit
我正在努力禁用Lua中的whichwrap。 - Stephane

0
问题在于将set nocompatible放在vimrc的中间(我也犯了同样的错误)。 实际上,当检测到vimrc时nocompatible被设置, 但是set nocompatible会有一个重置所有选项为默认值的副作用。
:help nocompatible中得知:

这是一种特殊的选项,因为当它被设置或重置时,其他选项也会发生变化。

注意:设置或重置此选项可能会产生许多意想不到的效果:映射以另一种方式解释,撤消行为不同等。如果您在vimrc文件中设置此选项,则应该将其放在最开始处。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接