" Toggle Autowrap
" Default of 72 but can be overridden by tw settings in other vimrc files
let g:orig_tw = 72
function Toggle_autowrap_mode()
if &textwidth == 0
" Must use let instead of set here in order for g:orig_tw to be
" evaluated properly
let &textwidth = g:orig_tw
echo "Autowrap mode on tw=" . &textwidth
else
let g:orig_tw = &textwidth
set textwidth=0
echo "Autowrap mode off tw=" . &textwidth
endif
endfunction
noremap _A :call Toggle_autowrap_mode()<CR>
打印选项的值: :set formatoptions? vs :echo &formatoptions(let不打印值,不像 set)
同时分配给多个选项:
:set et sw=4 sts=4
对
:let [&et, &sw, &sts] = [0, 4, 4]
set global option: setglobal et vs let &g:et = 1
set local option: setlocal et vs let &l:et = 1
See :h :set and :h :let for more details
tl;dr
:set only works with options but the syntax is much simpler. :let works with not just options but also variables, registers, and environment variables. Unlike :set, the right hand side of :let is an expression.