【问题标题】:vim Comment Newlines Unexpected Behaviorvim 注释换行符意外行为
【发布时间】:2009-01-19 19:32:33
【问题描述】:

在使用 vim 时,当我用 // 开始注释时,在我输入一个空格后,它会立即开始一个新的注释行。

例如,如果我输入以下内容:

//hello world my name is stefan

我会得到:

//hello
//world
//my
//name
//is
//stefan

这种行为也体现在 python 代码中,如果我以 print 开头一行,每个空格都被解释为换行符

print "Hello world my name is Stefan"

print
"hello
world
my
name
is
stefan"

这是预期的行为还是我的设置搞砸了?以下是我的.vimrc:

" An example for a vimrc file.
"
" Maintainer:   Bram Moolenaar <email address>
" Last change:  2006 Nov 16
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"         for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"       for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" TagList plugin settings
nmap <f12> :TlistToggle<end>

" 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

set nobackup        " do not keep a backup file, use versions instead
set history=50      " 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

" 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

" In many terminal emulators the mouse works just fine, thus enable it.
" set mouse=a

" 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

  set autoindent        " always set autoindenting on

endif " has("autocmd")

set   backupdir=./.backup,.,/tmp
set   directory=.,./.backup,/tmp

map <F1> :NERDTree <CR>
map <F2> :q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>:q!<CR>
map <F5> :AV<CR>
map <F6> :AS<CR>
map <F7> :IHV<CR>
map <F8> :IHS<CR>

【问题讨论】:

  • 我可以建议将 映射到 :qa!反而? :)
  • 我看不出这有什么问题,但我建议你做一个 :set 并将输出放在这里,这样我们就可以看到哪些设置处于活动状态。
  • @roe 哈哈,这是我积累的 vim 知识,我想留给后代 ;)

标签: newline vim


【解决方案1】:

我的猜测是你混淆了“tw”(又名 textwidth)和旧的 vi 命令来设置文本边距“wm”。 "tw" 设置页面的实际宽度(即 tw=77 表示您希望每行 77 个字母),但 "wm" 设置离屏幕边缘多远,因此在 80 列屏幕上 "wm= 3" 将具有与 "tw=77" 相同的效果。因此,如果您的 tw 设置为非常小的值,它会尝试在每个单词之后换行。

【讨论】:

  • 我想补充一点,我又做了一次,然后回到这里修复它。你帮了我两次,保罗! :)
  • @Stefan,昨天我需要找到如何执行特定的 SQL 查询,所以我在 SO 上进行了搜索,发现了一年前我在另一份工作时问过的一个问题,我当时接受的答案再次帮助了我。几乎让你希望你能再次投票,不是吗?好吧,你不必这样做 - 答案可以帮助任何需要它的人,即使是你。
  • 哈哈,正是我的想法。干杯。
【解决方案2】:

我无法在您的 vimrc 中发现它,但您的 tw 似乎设置为较低的值(0 除外),例如 5 左右。尝试设置 tw=0,看看会发生什么。

编辑:
正如 Paul 指出的那样,您可能混淆了 tw (textwidth) 和 ts (tabstop),后者通常设置为 4 或 2。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 2011-11-07
    • 2014-05-07
    相关资源
    最近更新 更多