📄 optwin.vim
字号:
" These commands create the option window."" Maintainer: Bram Moolenaar <Bram@vim.org>" Last Change: 2000 Jul 05" Make sure the '<' flag is not included in 'cpoptions', otherwise <CR> would" not be recognized. See ":help 'cpoptions'".let optwin_cpo_save = &cpolet &cpo = """ function to be called when <CR> is hit in the option-windowfun! OW_CR() " If on a continued comment line, go back to the first comment line let lnum = line(".") let line = getline(lnum) while line[0] == "\t" let lnum = lnum - 1 let line = getline(lnum) endwhile " <CR> on a "set" line executes the option line if match(line, "^set ") >= 0 " For a local option: go to the previous window " If this is a help window, go to the window below it let thiswin = winnr() let local = OW_Find(lnum) if local >= 0 exe line call OW_Update(lnum, line, local, thiswin) endif " <CR> on a "option" line shows help for that option elseif match(line, "^[a-z]") >= 0 let name = substitute(line, '\([^\t]*\).*', '\1', "") exe "help '" . name . "'" " <CR> on an index line jumps to the group elseif match(line, '^ \=[0-9]') >= 0 exe "norm! /" . line . "\<CR>zt" endifendfun" function to be called when <Space> is hit in the option-windowfun! OW_Space() let lnum = line(".") let line = getline(lnum) " <Space> on a "set" line refreshes the option line if match(line, "^set ") >= 0 " For a local option: go to the previous window " If this is a help window, go to the window below it let thiswin = winnr() let local = OW_Find(lnum) if local >= 0 call OW_Update(lnum, line, local, thiswin) endif endifendfun" find the window in which the option applies" returns 0 for global option, 1 for local option, -1 for errorfun! OW_Find(lnum) if getline(a:lnum - 1) =~ "(local to" let local = 1 let thiswin = winnr() exe "norm! \<C-W>p" if exists("b:current_syntax") && b:current_syntax == "help" exe "norm! \<C-W>j" if winnr() == thiswin exe "norm! \<C-W>j" endif endif else let local = 0 endif if local && (winnr() == thiswin || (exists("b:current_syntax") \ && b:current_syntax == "help")) echo "Don't know in which window" let local = -1 endif return localendfun" Update a "set" line in the option windowfun! OW_Update(lnum, line, local, thiswin) " get the new value of the option and update the option window line if match(a:line, "=") >= 0 let name = substitute(a:line, '^set \([^=]*\)=.*', '\1', "") else let name = substitute(a:line, '^set \(no\)\=\([a-z]*\).*', '\2', "") endif exe "let val = substitute(&" . name . ', "[ \\t\\\\\"|]", "\\\\\\0", "g")' if a:local exe "norm! " . a:thiswin . "\<C-W>w" endif if match(a:line, "=") >= 0 || (val != "0" && val != "1") call setline(a:lnum, "set " . name . "=" . val) else if val call setline(a:lnum, "set " . name . "\tno" . name) else call setline(a:lnum, "set no" . name . "\t" . name) endif endif set nomodifiedendfun" Reset 'title' and 'icon' to make it work faster.let old_title = &titlelet old_icon = &iconlet old_sc = &sclet old_ru = &ruset notitle noicon nosc noru" If the current window is a help window, try finding a non-help window." Relies on syntax highlighting to be switched on.let OW_thiswin = winnr()while exists("b:current_syntax") && b:current_syntax == "help" exe "norm! \<C-W>w" if OW_thiswin == winnr() break endifendwhileunlet OW_thiswin" Open the windownew option-windowset ts=15 tw=0" Insert help and a "set" command for each option.call append(0, 'Each "set" line shows the current value of an option (on the left).')call append(1, 'Hit <CR> on a "set" line to execute it.')call append(2, ' A boolean option will be toggled.')call append(3, ' For other options you can edit the value.')call append(4, 'Hit <CR> on a help line to open a help window on this option.')call append(5, 'Hit <CR> on an index line to jump there.')call append(6, 'Hit <Space> on a "set" line to refresh it.')" These functions are called often below. Keep them fast!fun! OW_BinOption(name) exe "norm! \<C-W>p" exe "let val = &" . a:name exe "norm! \<C-W>p" call append("$", substitute(substitute("set " . val . a:name . "\t" . \!val . a:name, "0", "no", ""), "1", "", ""))endfunfun! OW_BinOptionL(name, val) call append("$", substitute(substitute("set " . a:val . a:name . "\t" . \!a:val . a:name, "0", "no", ""), "1", "", ""))endfunfun! OW_Option(name) exe "norm! \<C-W>p" exe "let val = substitute(&" . a:name . ', "[ \\t\\\\\"|]", "\\\\\\0", "g")' exe "norm! \<C-W>p" call append("$", "set " . a:name . "=" . val)endfunfun! OW_OptionL(name, val) call append("$", "set " . a:name . "=" . substitute(a:val, "[ \\t\\\\\"|]", \"\\\\\\0", "g"))endfunlet OW_idx = 1let OW_lnum = line("$")call append("$", "")fun! OW_Header(text) let line = g:OW_idx . " " . a:text if g:OW_idx < 10 let line = " " . line endif call append("$", "") call append("$", line) call append("$", "") call append(g:OW_lnum, line) let g:OW_idx = g:OW_idx + 1 let g:OW_lnum = g:OW_lnum + 1endfun" Restore the previous value of 'cpoptions' here, it's used below.let &cpo = optwin_cpo_save" List of all options, organized by function." The text should be sufficient to know what the option is used for.call OW_Header("important")call append("$", "compatible\tbehave very Vi compatible (not advisable)")call OW_BinOptionL("cp", &cp)call append("$", "cpoptions\tlist of flags to specify Vi compatibility")call OW_OptionL("cpo", &cpo)call append("$", "insertmode\tuse Insert mode as the default mode")call OW_BinOptionL("im", &im)call append("$", "paste\tpaste mode, insert typed text literally")call OW_BinOptionL("paste", &paste)call append("$", "pastetoggle\tkey sequence to toggle paste mode")call OW_OptionL("pt", &pt)call append("$", "helpfile\tname of the main help file")call OW_OptionL("hf", &hf)call OW_Header("moving around, searching and patterns")call append("$", "whichwrap\tlist of flags specifying which commands wrap to another line")call append("$", "\t(local to window)")call OW_Option("ww")call append("$", "startofline\tmany jump commands move the cursor to the first non-blank")call append("$", "\tcharacter of a line")call OW_BinOptionL("sol", &sol)call append("$", "paragraphs\tnroff macro names that separate paragraphs")call OW_OptionL("para", ¶)call append("$", "sections\tnroff macro names that separate sections")call OW_OptionL("sect", §)call append("$", "path\tlist of directory names used for file searching")call OW_OptionL("pa", &pa)call append("$", "wrapscan\tsearch commands wrap around the end of the buffer")call OW_BinOptionL("ws", &ws)call append("$", "incsearch\tshow match for partly typed search command")call OW_BinOptionL("is", &is)call append("$", "magic\tchange the way backslashes are used in search patterns")call OW_BinOptionL("magic", &magic)call append("$", "ignorecase\tignore case when using a search pattern")call OW_BinOptionL("ic", &ic)call append("$", "smartcase\toverride 'ignorecase' when pattern has upper case characters")call OW_BinOptionL("scs", &scs)call append("$", "define\tpattern for a macro definition line")call OW_OptionL("def", &def)call append("$", "include\tpattern for an include-file line")call OW_OptionL("inc", &inc)call OW_Header("tags")call append("$", "tagbsearch\tuse binary searching in tags files")call OW_BinOptionL("tbs", &tbs)call append("$", "taglength\tnumber of significant characters in a tag name or zero")call append("$", "set tl=" . &tl)call append("$", "tags\tlist of file names to search for tags")call OW_OptionL("tag", &tag)call append("$", "tagrelative\tfile names in a tags file are relative to the tags file")call OW_BinOptionL("tr", &tr)call append("$", "showfulltag\twhen completing tags in Insert mode show more info")call OW_BinOptionL("sft", &sft)if has("cscope") call append("$", "cscopeprg\tcommand for executing cscope") call OW_OptionL("csprg", &csprg) call append("$", "cscopetag\tuse cscope for tag commands") call OW_BinOptionL("cst", &cst) call append("$", "cscopetagorder\t0 or 1; the order in which \":cstag\" performs a search") call append("$", "set csto=" . &csto) call append("$", "cscopeverbose\tgive messages when adding a cscope database") call OW_BinOptionL("csverb", &csverb)endifcall OW_Header("displaying text")call append("$", "scroll\tnumber of lines to scroll for CTRL-U and CTRL-D")call append("$", "\t(local to window)")call OW_Option("scr")call append("$", "scrolloff\tnumber of screen lines to show around the cursor")call append("$", "set so=" . &so)call append("$", "wrap\tlong lines wrap")call OW_BinOptionL("wrap", &wrap)call append("$", "linebreak\twrap long lines at a character in 'breakat'")call append("$", "\t(local to window)")call OW_BinOption("lbr")call append("$", "breakat\twhich characters might cause a line break")call OW_OptionL("brk", &brk)call append("$", "showbreak\tstring to put before wrapped screen lines")call OW_OptionL("sbr", &sbr)call append("$", "sidescroll\tminimal number of columns to scroll horizontally")call append("$", "set ss=" . &ss)call append("$", "display\twhen \"lastline\": show the last line even if it doesn't fit")call OW_OptionL("dy", &dy)call append("$", "cmdheight\tnumber of lines used for the command-line")call append("$", "set ch=" . &ch)call append("$", "columns\twidth of the display")call append("$", "set co=" . &co)call append("$", "lines\tnumber of lines in the display")call append("$", "set lines=" . &lines)call append("$", "lazyredraw\tdon't redraw while executing macros")call OW_BinOptionL("lz", &lz)call append("$", "writedelay\tdelay in msec for each char written to the display")call append("$", "\t(for debugging)")call append("$", "set wd=" . &wd)call append("$", "list\tshow <Tab> as ^I and end-of-line as $")call append("$", "\t(local to window)")call OW_BinOption("list")call append("$", "listchars\tlist of strings used for list mode")call OW_OptionL("lcs", &lcs)call append("$", "number\tshow the line number for each line")call append("$", "\t(local to window)")call OW_BinOption("nu")call OW_Header("syntax and highlighting")call append("$", "background\t\"dark\" or \"light\"; the background color brightness")call OW_OptionL("bg", &bg)if has("autocmd") call append("$", "filetype\ttype of file; triggers the FileType event when set") call append("$", "\t(local to buffer)") call OW_Option("ft")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -