将以下文本翻译成中文:
将eborisch的答案与我在这里找到的其他答案以及我必须解决的问题相结合,我想出了以下两部分解决方案:
第一部分使得编辑长行文本更加容易:
" Allow enabling by running the command ":Freeform", or <leader>sw
command! Softwrap :call SetupSoftwrap()
map <Leader>sw :call SetupSoftwrap() <CR>
func! SetupFreeform()
" Use setlocal for all of these so they don't affect other buffers
" Enable line wrapping.
setlocal wrap
" Only break at words.
setlocal linebreak
" Turn on spellchecking
setlocal spell
" Make jk and 0$ work on visual lines.
nnoremap <buffer> j gj
nnoremap <buffer> k gk
nnoremap <buffer> 0 g0
nnoremap <buffer> $ g$
" Disable colorcolumn, in case you use it as a column-width indicator
" I use: let &colorcolumn = join(range(101, 300), ",")
" so this overrides that.
setlocal colorcolumn=
" cursorline and cursorcolumn don't work as well in wrap mode, so
" you may want to disable them. cursorline highlights the whole line,
" so if you write a whole paragraph on a single line, the whole
" paragraph will be highlighted. cursorcolumn only highlights the actual
" column number, not the visual line, so the highlighting will be broken
" up on wrapped lines.
setlocal nocursorline
setlocal nocursorcolumn
endfunc
仅使用这个功能,您就可以得到像Markdown或Readme这样的文本自动换行的效果。
正如其他答案中指出的那样,要在精确的列宽处进行换行,需要告诉vim有多少列,并在每次调整vim大小时覆盖该值:
command! -nargs=? Draft :call SetupDraftMode(<args>)
func! SetupDraftMode()
" I like 80 columns + 4 for line numbers
set columns=84
autocmd VimResized * if (&columns > 84) | set columns=84 | endif
:Softwrap
endfunc
这还有几个问题:
- 在调用set columns之后,vim不会清除屏幕外的列,我无法弄清如何告诉它这样做,所以最好在打开vim后立即调用此命令
- 打开vim时,它会显示一个带有版本号和一些有用命令的提示符,因此这些内容不会被清除。您可以添加
set shm+=I
来禁用该提示符
- 您不能打开任何垂直分割,因为然后两个分割线都将是约40列。您需要将列设置为您所需宽度的2倍,并始终保持分割线打开。
- 我的vimscript很糟糕,但理想情况下,有人可以修改上面的
Draft
函数以接受列宽作为参数,或使用全局变量(g:explicit_vim_width
?),如果您的窗口大小更改,则可以手动设置。
:vsplit
并调整右侧分屏的大小,以使左侧分屏达到我想要的大小... - fbence