neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

optwin.lua (33641B)


      1 ---@param x string
      2 ---@return string
      3 local function N_(x)
      4  return vim.fn.gettext(x)
      5 end
      6 
      7 ---@type {header:string,[integer]:[string,string]}[]
      8 local options_list = {
      9  {
     10    header = N_ 'important',
     11    { 'cpoptions', N_ 'list of flags to specify Vi compatibility' },
     12    { 'runtimepath', N_ 'list of directories used for runtime files and plugins' },
     13    { 'packpath', N_ 'list of directories used for plugin packages' },
     14    { 'helpfile', N_ 'name of the main help file' },
     15  },
     16  {
     17    header = N_ 'moving around, searching and patterns',
     18    { 'whichwrap', N_ 'list of flags specifying which commands wrap to another line' },
     19    {
     20      'startofline',
     21      N_ 'many jump commands move the cursor to the first non-blank\ncharacter of a line',
     22    },
     23    { 'paragraphs', N_ 'nroff macro names that separate paragraphs' },
     24    { 'sections', N_ 'nroff macro names that separate sections' },
     25    { 'path', N_ 'list of directory names used for file searching' },
     26    { 'findfunc', N_ 'function called for :find' },
     27    { 'cdhome', N_ ':cd without argument goes to the home directory' },
     28    { 'cdpath', N_ 'list of directory names used for :cd' },
     29    { 'autochdir', N_ 'change to directory of file in buffer' },
     30    { 'wrapscan', N_ 'search commands wrap around the end of the buffer' },
     31    { 'incsearch', N_ 'show match for partly typed search command' },
     32    { 'regexpengine', N_ 'select the default regexp engine used' },
     33    { 'ignorecase', N_ 'ignore case when using a search pattern' },
     34    { 'smartcase', N_ "override 'ignorecase' when pattern has upper case characters" },
     35    { 'maxsearchcount', N_ 'maximum number for the search count feature' },
     36    { 'casemap', N_ 'what method to use for changing case of letters' },
     37    { 'maxmempattern', N_ 'maximum amount of memory in Kbyte used for pattern matching' },
     38    { 'define', N_ 'pattern for a macro definition line' },
     39    { 'include', N_ 'pattern for an include-file line' },
     40    { 'includeexpr', N_ 'expression used to transform an include line to a file name' },
     41    { 'jumpoptions', N_ 'controls the behavior of the jumplist' },
     42  },
     43  {
     44    header = N_ 'tags',
     45    { 'tagbsearch', N_ 'use binary searching in tags files' },
     46    { 'taglength', N_ 'number of significant characters in a tag name or zero' },
     47    { 'tags', N_ 'list of file names to search for tags' },
     48    {
     49      'tagcase',
     50      N_ 'how to handle case when searching in tags files:\n"followic" to follow \'ignorecase\', "ignore" or "match"',
     51    },
     52    { 'tagrelative', N_ 'file names in a tags file are relative to the tags file' },
     53    { 'tagstack', N_ 'a :tag command will use the tagstack' },
     54    { 'showfulltag', N_ 'when completing tags in Insert mode show more info' },
     55    { 'tagfunc', N_ 'a function to be used to perform tag searches' },
     56  },
     57  {
     58    header = N_ 'displaying text',
     59    { 'scroll', N_ 'number of lines to scroll for CTRL-U and CTRL-D' },
     60    { 'smoothscroll', N_ 'scroll by screen line' },
     61    { 'scrolloff', N_ 'number of screen lines to show around the cursor' },
     62    { 'wrap', N_ 'long lines wrap' },
     63    { 'linebreak', N_ "wrap long lines at a character in 'breakat'" },
     64    { 'breakindent', N_ 'preserve indentation in wrapped text' },
     65    { 'breakindentopt', N_ 'adjust breakindent behaviour' },
     66    { 'breakat', N_ 'which characters might cause a line break' },
     67    { 'showbreak', N_ 'string to put before wrapped screen lines' },
     68    { 'sidescroll', N_ 'minimal number of columns to scroll horizontally' },
     69    { 'sidescrolloff', N_ 'minimal number of columns to keep left and right of the cursor' },
     70    {
     71      'display',
     72      N_ 'include "lastline" to show the last line even if it doesn\'t fit\ninclude "uhex" to show unprintable characters as a hex number',
     73    },
     74    {
     75      'fillchars',
     76      N_ 'characters to use for the status line, folds, diffs,\nbuffer text, filler lines and truncation in the completion menu',
     77    },
     78    { 'cmdheight', N_ 'number of lines used for the command-line' },
     79    { 'columns', N_ 'width of the display' },
     80    { 'lines', N_ 'number of lines in the display' },
     81    { 'window', N_ 'number of lines to scroll for CTRL-F and CTRL-B' },
     82    { 'lazyredraw', N_ "don't redraw while executing macros" },
     83    { 'redrawtime', N_ "timeout for 'hlsearch' and :match highlighting in msec" },
     84    { 'writedelay', N_ 'delay in msec for each char written to the display' },
     85    { 'redrawdebug', N_ 'change the way redrawing works (debug)' },
     86    { 'list', N_ 'show <Tab> as ^I and end-of-line as $' },
     87    { 'listchars', N_ 'list of strings used for list mode' },
     88    { 'number', N_ 'show the line number for each line' },
     89    { 'relativenumber', N_ 'show the relative line number for each line' },
     90    { 'numberwidth', N_ 'number of columns to use for the line number' },
     91    { 'chistory', N_ 'maximum number of quickfix lists that can be stored in history' },
     92    { 'lhistory', N_ 'maximum number of location lists that can be stored in history' },
     93    { 'conceallevel', N_ 'controls whether concealable text is hidden' },
     94    { 'concealcursor', N_ 'modes in which text in the cursor line can be concealed' },
     95  },
     96  {
     97    header = N_ 'syntax, highlighting and spelling',
     98    { 'background', N_ '"dark" or "light"; the background color brightness' },
     99    { 'filetype', N_ 'type of file; triggers the FileType event when set' },
    100    { 'syntax', N_ 'name of syntax highlighting used' },
    101    { 'synmaxcol', N_ 'maximum column to look for syntax items' },
    102    { 'hlsearch', N_ 'highlight all matches for the last used search pattern' },
    103    { 'termguicolors', N_ 'use GUI colors for the terminal' },
    104    { 'cursorcolumn', N_ 'highlight the screen column of the cursor' },
    105    { 'cursorline', N_ 'highlight the screen line of the cursor' },
    106    { 'cursorlineopt', N_ "specifies which area 'cursorline' highlights" },
    107    { 'colorcolumn', N_ 'columns to highlight' },
    108    { 'spell', N_ 'highlight spelling mistakes' },
    109    { 'spelllang', N_ 'list of accepted languages' },
    110    { 'spellfile', N_ 'file that "zg" adds good words to' },
    111    { 'spellcapcheck', N_ 'pattern to locate the end of a sentence' },
    112    { 'spelloptions', N_ 'flags to change how spell checking works' },
    113    { 'spellsuggest', N_ 'methods used to suggest corrections' },
    114    { 'mkspellmem', N_ 'amount of memory used by :mkspell before compressing' },
    115    { 'winhighlight', N_ 'override highlighting-groups window-locally' },
    116  },
    117  {
    118    header = N_ 'multiple windows',
    119    { 'laststatus', N_ '0, 1, 2 or 3; when to use a status line for the last window' },
    120    { 'statuscolumn', N_ 'custom format for the status column' },
    121    { 'statusline', N_ 'alternate format to be used for a status line' },
    122    { 'equalalways', N_ 'make all windows the same size when adding/removing windows' },
    123    { 'eadirection', N_ 'in which direction \'equalalways\' works: "ver", "hor" or "both"' },
    124    { 'winheight', N_ 'minimal number of lines used for the current window' },
    125    { 'winminheight', N_ 'minimal number of lines used for any window' },
    126    { 'winfixbuf', N_ 'keep window focused on a single buffer' },
    127    { 'winfixheight', N_ 'keep the height of the window' },
    128    { 'winfixwidth', N_ 'keep the width of the window' },
    129    { 'winwidth', N_ 'minimal number of columns used for the current window' },
    130    { 'winminwidth', N_ 'minimal number of columns used for any window' },
    131    { 'helpheight', N_ 'initial height of the help window' },
    132    { 'previewheight', N_ 'default height for the preview window' },
    133    { 'previewwindow', N_ 'identifies the preview window' },
    134    { 'winbar', N_ 'custom format for the window bar' },
    135    { 'winborder', N_ 'border of floating window' },
    136    { 'winblend', N_ 'transparency level for floating windows' },
    137    { 'hidden', N_ "don't unload a buffer when no longer shown in a window" },
    138    { 'switchbuf', N_ '"useopen" and/or "split"; which window to use when jumping\nto a buffer' },
    139    { 'splitbelow', N_ 'a new window is put below the current one' },
    140    { 'splitkeep', N_ 'determines scroll behavior for split windows' },
    141    { 'splitright', N_ 'a new window is put right of the current one' },
    142    { 'scrollbind', N_ 'this window scrolls together with other bound windows' },
    143    { 'scrollopt', N_ '"ver", "hor" and/or "jump"; list of options for \'scrollbind\'' },
    144    { 'cursorbind', N_ "this window's cursor moves together with other bound windows" },
    145  },
    146  {
    147    header = N_ 'multiple tab pages',
    148    { 'showtabline', N_ '0, 1 or 2; when to use a tab pages line' },
    149    { 'tabclose', N_ 'behaviour when closing tab pages: left, uselast or empty' },
    150    { 'tabpagemax', N_ 'maximum number of tab pages to open for -p and "tab all"' },
    151    { 'tabline', N_ 'custom tab pages line' },
    152  },
    153  {
    154    header = N_ 'terminal',
    155    { 'scrolljump', N_ 'minimal number of lines to scroll at a time' },
    156    { 'guicursor', N_ 'specifies what the cursor looks like in different modes' },
    157    { 'title', N_ 'show info in the window title' },
    158    { 'titlelen', N_ "percentage of 'columns' used for the window title" },
    159    { 'titlestring', N_ 'when not empty, string to be used for the window title' },
    160    { 'titleold', N_ 'string to restore the title to when exiting Vim' },
    161    { 'icon', N_ 'set the text of the icon for this window' },
    162    { 'iconstring', N_ 'when not empty, text for the icon of this window' },
    163  },
    164  {
    165    header = N_ 'using the mouse',
    166    { 'mouse', N_ 'list of flags for using the mouse' },
    167    { 'mousescroll', N_ 'amount to scroll by when scrolling with a mouse' },
    168    { 'mousefocus', N_ 'the window with the mouse pointer becomes the current one' },
    169    { 'mousehide', N_ 'hide the mouse pointer while typing' },
    170    {
    171      'mousemodel',
    172      N_ '"extend", "popup" or "popup_setpos"; what the right\nmouse button is used for',
    173    },
    174    { 'mousetime', N_ 'maximum time in msec to recognize a double-click' },
    175    { 'mousemoveevent', N_ 'deliver mouse move events to input queue' },
    176  },
    177  {
    178    header = N_ 'GUI',
    179    { 'guifont', N_ 'list of font names to be used in the GUI' },
    180    { 'guifontwide', N_ 'list of font names to be used for double-wide characters' },
    181    { 'browsedir', N_ '"last", "buffer" or "current": which directory used for\nthe file browser' },
    182    { 'langmenu', N_ 'language to be used for the menus' },
    183    { 'menuitems', N_ 'maximum number of items in one menu' },
    184    { 'winaltkeys', N_ '"no", "yes" or "menu"; how to use the ALT key' },
    185    { 'linespace', N_ 'number of pixel lines to use between characters' },
    186    { 'termsync', N_ 'synchronize redraw output with the host terminal' },
    187  },
    188  {
    189    header = N_ 'messages and info',
    190    { 'shortmess', N_ 'list of flags to make messages shorter' },
    191    { 'messagesopt', N_ 'options for outputting messages' },
    192    { 'showcmd', N_ "show (partial) command keys in location given by 'showcmdloc'" },
    193    { 'showcmdloc', N_ "location where to show the (partial) command keys for 'showcmd'" },
    194    { 'showmode', N_ 'display the current mode in the status line' },
    195    { 'ruler', N_ 'show cursor position below each window' },
    196    { 'rulerformat', N_ 'alternate format to be used for the ruler' },
    197    { 'report', N_ 'threshold for reporting number of changed lines' },
    198    { 'verbose', N_ 'the higher the more messages are given' },
    199    { 'verbosefile', N_ 'file to write messages in' },
    200    { 'more', N_ 'pause listings when the screen is full' },
    201    { 'confirm', N_ 'start a dialog when a command fails' },
    202    { 'errorbells', N_ 'ring the bell for error messages' },
    203    { 'visualbell', N_ 'use a visual bell instead of beeping' },
    204    { 'belloff', N_ 'do not ring the bell for these reasons' },
    205    { 'helplang', N_ 'list of preferred languages for finding help' },
    206  },
    207  {
    208    header = N_ 'selecting text',
    209    { 'selection', N_ '"old", "inclusive" or "exclusive"; how selecting text behaves' },
    210    {
    211      'selectmode',
    212      N_ '"mouse", "key" and/or "cmd"; when to start Select mode\ninstead of Visual mode',
    213    },
    214    {
    215      'clipboard',
    216      N_ '"unnamed" to use the * register like unnamed register\n"autoselect" to always put selected text on the clipboard',
    217    },
    218    { 'keymodel', N_ '"startsel" and/or "stopsel"; what special keys can do' },
    219  },
    220  {
    221    header = N_ 'editing text',
    222    { 'undolevels', N_ 'maximum number of changes that can be undone' },
    223    { 'undofile', N_ 'automatically save and restore undo history' },
    224    { 'undodir', N_ 'list of directories for undo files' },
    225    { 'undoreload', N_ 'maximum number lines to save for undo on a buffer reload' },
    226    { 'modified', N_ 'changes have been made and not written to a file' },
    227    { 'readonly', N_ 'buffer is not to be written' },
    228    { 'modifiable', N_ 'changes to the text are possible' },
    229    { 'textwidth', N_ 'line length above which to break a line' },
    230    { 'wrapmargin', N_ 'margin from the right in which to break a line' },
    231    { 'backspace', N_ 'specifies what <BS>, CTRL-W, etc. can do in Insert mode' },
    232    { 'comments', N_ 'definition of what comment lines look like' },
    233    { 'commentstring', N_ 'template for comments; used to put the marker in' },
    234    { 'formatoptions', N_ 'list of flags that tell how automatic formatting works' },
    235    { 'formatlistpat', N_ 'pattern to recognize a numbered list' },
    236    { 'formatexpr', N_ 'expression used for "gq" to format lines' },
    237    { 'complete', N_ 'specifies how Insert mode completion works for CTRL-N and CTRL-P' },
    238    { 'autocomplete', N_ 'automatic completion in insert mode' },
    239    { 'autocompletetimeout', N_ "initial decay timeout for 'autocomplete' algorithm" },
    240    { 'completetimeout', N_ 'initial decay timeout for CTRL-N and CTRL-P completion' },
    241    { 'autocompletedelay', N_ 'delay in msec before menu appears after typing' },
    242    { 'completeopt', N_ 'whether to use a popup menu for Insert mode completion' },
    243    { 'completeitemalign', N_ 'popup menu item align order' },
    244    { 'pumheight', N_ 'maximum height of the popup menu' },
    245    { 'pumwidth', N_ 'minimum width of the popup menu' },
    246    { 'pummaxwidth', N_ 'maximum width of the popup menu' },
    247    { 'pumblend', N_ 'transparency level of popup menu' },
    248    { 'pumborder', N_ 'border of popupmenu' },
    249    { 'completefunc', N_ 'user defined function for Insert mode completion' },
    250    { 'omnifunc', N_ 'function for filetype-specific Insert mode completion' },
    251    { 'dictionary', N_ 'list of dictionary files for keyword completion' },
    252    { 'thesaurus', N_ 'list of thesaurus files for keyword completion' },
    253    { 'thesaurusfunc', N_ 'function used for thesaurus completion' },
    254    { 'infercase', N_ 'adjust case of a keyword completion match' },
    255    { 'digraph', N_ 'enable entering digraphs with c1 <BS> c2' },
    256    { 'tildeop', N_ 'the "~" command behaves like an operator' },
    257    { 'operatorfunc', N_ 'function called for the "g@" operator' },
    258    { 'showmatch', N_ 'when inserting a bracket, briefly jump to its match' },
    259    { 'matchtime', N_ "tenth of a second to show a match for 'showmatch'" },
    260    { 'matchpairs', N_ 'list of pairs that match for the "%" command' },
    261    { 'joinspaces', N_ "use two spaces after '.' when joining a line" },
    262    {
    263      'nrformats',
    264      N_ '"alpha", "octal", "hex", "bin" and/or "unsigned"; number formats\nrecognized for CTRL-A and CTRL-X commands',
    265    },
    266  },
    267  {
    268    header = N_ 'tabs and indenting',
    269    { 'tabstop', N_ 'number of spaces a <Tab> in the text stands for' },
    270    { 'shiftwidth', N_ 'number of spaces used for each step of (auto)indent' },
    271    { 'vartabstop', N_ 'list of number of spaces a tab counts for' },
    272    { 'varsofttabstop', N_ 'list of number of spaces a soft tabsstop counts for' },
    273    { 'smarttab', N_ "a <Tab> in an indent inserts 'shiftwidth' spaces" },
    274    { 'softtabstop', N_ 'if non-zero, number of spaces to insert for a <Tab>' },
    275    { 'shiftround', N_ 'round to \'shiftwidth\' for "<<" and ">>"' },
    276    { 'expandtab', N_ 'expand <Tab> to spaces in Insert mode' },
    277    { 'autoindent', N_ 'automatically set the indent of a new line' },
    278    { 'smartindent', N_ 'do clever autoindenting' },
    279    { 'cindent', N_ 'enable specific indenting for C code' },
    280    { 'cinoptions', N_ 'options for C-indenting' },
    281    { 'cinkeys', N_ 'keys that trigger C-indenting in Insert mode' },
    282    { 'cinwords', N_ 'list of words that cause more C-indent' },
    283    { 'cinscopedecls', N_ 'list of scope declaration names used by cino-g' },
    284    { 'indentexpr', N_ 'expression used to obtain the indent of a line' },
    285    { 'indentkeys', N_ "keys that trigger indenting with 'indentexpr' in Insert mode" },
    286    { 'copyindent', N_ 'copy whitespace for indenting from previous line' },
    287    { 'preserveindent', N_ 'preserve kind of whitespace when changing indent' },
    288    { 'lisp', N_ 'enable lisp mode' },
    289    { 'lispwords', N_ 'words that change how lisp indenting works' },
    290    { 'lispoptions', N_ 'options for Lisp indenting' },
    291  },
    292  {
    293    header = N_ 'folding',
    294    { 'foldenable', N_ 'unset to display all folds open' },
    295    { 'foldlevel', N_ 'folds with a level higher than this number will be closed' },
    296    { 'foldlevelstart', N_ "value for 'foldlevel' when starting to edit a file" },
    297    { 'foldcolumn', N_ 'width of the column used to indicate folds' },
    298    { 'foldtext', N_ 'expression used to display the text of a closed fold' },
    299    { 'foldclose', N_ 'set to "all" to close a fold when the cursor leaves it' },
    300    { 'foldopen', N_ 'specifies for which commands a fold will be opened' },
    301    { 'foldminlines', N_ 'minimum number of screen lines for a fold to be closed' },
    302    { 'foldmethod', N_ 'folding type: "manual", "indent", "expr", "marker",\n"syntax" or "diff"' },
    303    { 'foldexpr', N_ 'expression used when \'foldmethod\' is "expr"' },
    304    { 'foldignore', N_ 'used to ignore lines when \'foldmethod\' is "indent"' },
    305    { 'foldmarker', N_ 'markers used when \'foldmethod\' is "marker"' },
    306    { 'foldnestmax', N_ 'maximum fold depth for when \'foldmethod\' is "indent" or "syntax"' },
    307  },
    308  {
    309    header = N_ 'diff mode',
    310    { 'diff', N_ 'use diff mode for the current window' },
    311    { 'diffopt', N_ 'options for using diff mode' },
    312    { 'diffexpr', N_ 'expression used to obtain a diff file' },
    313    { 'diffanchors', N_ 'list of addresses for anchoring a diff' },
    314    { 'patchexpr', N_ 'expression used to patch a file' },
    315  },
    316  {
    317    header = N_ 'mapping',
    318    { 'maxmapdepth', N_ 'maximum depth of mapping' },
    319    { 'timeout', N_ 'allow timing out halfway into a mapping' },
    320    { 'ttimeout', N_ 'allow timing out halfway into a key code' },
    321    { 'timeoutlen', N_ "time in msec for 'timeout'" },
    322    { 'ttimeoutlen', N_ "time in msec for 'ttimeout'" },
    323  },
    324  {
    325    header = N_ 'reading and writing files',
    326    { 'modeline', N_ 'enable using settings from modelines when reading a file' },
    327    { 'modelineexpr', N_ 'allow setting expression options from a modeline' },
    328    { 'modelines', N_ 'number of lines to check for modelines' },
    329    { 'binary', N_ 'binary file editing' },
    330    { 'endofline', N_ 'last line in the file has an end-of-line' },
    331    { 'endoffile', N_ 'last line in the file followed by CTRL-Z' },
    332    { 'fixendofline', N_ 'fixes missing end-of-line at end of text file' },
    333    { 'bomb', N_ 'prepend a Byte Order Mark to the file' },
    334    { 'fileformat', N_ 'end-of-line format: "dos", "unix" or "mac"' },
    335    { 'fileformats', N_ 'list of file formats to look for when editing a file' },
    336    { 'write', N_ 'writing files is allowed' },
    337    { 'writebackup', N_ 'write a backup file before overwriting a file' },
    338    { 'backup', N_ 'keep a backup after overwriting a file' },
    339    { 'backupskip', N_ 'patterns that specify for which files a backup is not made' },
    340    { 'backupcopy', N_ 'whether to make the backup as a copy or rename the existing file' },
    341    { 'backupdir', N_ 'list of directories to put backup files in' },
    342    { 'backupext', N_ 'file name extension for the backup file' },
    343    { 'autowrite', N_ 'automatically write a file when leaving a modified buffer' },
    344    { 'autowriteall', N_ "as 'autowrite', but works with more commands" },
    345    { 'writeany', N_ 'always write without asking for confirmation' },
    346    { 'autoread', N_ 'automatically read a file when it was modified outside of Vim' },
    347    { 'patchmode', N_ 'keep oldest version of a file; specifies file name extension' },
    348    { 'fsync', N_ 'forcibly sync the file to disk after writing it' },
    349  },
    350  {
    351    header = N_ 'the swap file',
    352    { 'directory', N_ 'list of directories for the swap file' },
    353    { 'swapfile', N_ 'use a swap file for this buffer' },
    354    { 'updatecount', N_ 'number of characters typed to cause a swap file update' },
    355    { 'updatetime', N_ 'time in msec after which the swap file will be updated' },
    356  },
    357  {
    358    header = N_ 'command line editing',
    359    { 'history', N_ 'how many command lines are remembered' },
    360    { 'wildchar', N_ 'key that triggers command-line expansion' },
    361    { 'wildcharm', N_ "like 'wildchar' but can also be used in a mapping" },
    362    { 'wildmode', N_ 'specifies how command line completion works' },
    363    { 'wildoptions', N_ 'empty or "tagfile" to list file name of matching tags' },
    364    { 'suffixes', N_ 'list of file name extensions that have a lower priority' },
    365    { 'suffixesadd', N_ 'list of file name extensions added when searching for a file' },
    366    { 'wildignore', N_ 'list of patterns to ignore files for file name completion' },
    367    { 'fileignorecase', N_ 'ignore case when using file names' },
    368    { 'wildignorecase', N_ 'ignore case when completing file names' },
    369    { 'wildmenu', N_ 'command-line completion shows a list of matches' },
    370    { 'cedit', N_ 'key used to open the command-line window' },
    371    { 'cmdwinheight', N_ 'height of the command-line window' },
    372  },
    373  {
    374    header = N_ 'executing external commands',
    375    { 'shell', N_ 'name of the shell program used for external commands' },
    376    { 'shellquote', N_ 'character(s) to enclose a shell command in' },
    377    { 'shellxquote', N_ "like 'shellquote' but include the redirection" },
    378    { 'shellxescape', N_ "characters to escape when 'shellxquote' is (" },
    379    { 'shellcmdflag', N_ "argument for 'shell' to execute a command" },
    380    { 'shellredir', N_ 'used to redirect command output to a file' },
    381    { 'shelltemp', N_ 'use a temp file for shell commands instead of using a pipe' },
    382    { 'equalprg', N_ 'program used for "=" command' },
    383    { 'formatprg', N_ 'program used to format lines with "gq" command' },
    384    { 'keywordprg', N_ 'program used for the "K" command' },
    385    { 'warn', N_ 'warn when using a shell command and a buffer has changes' },
    386  },
    387  {
    388    header = N_ 'running make and jumping to errors (quickfix)',
    389    { 'errorfile', N_ 'name of the file that contains error messages' },
    390    { 'errorformat', N_ 'list of formats for error messages' },
    391    { 'makeprg', N_ 'program used for the ":make" command' },
    392    { 'shellpipe', N_ 'string used to put the output of ":make" in the error file' },
    393    { 'makeef', N_ "name of the errorfile for the 'makeprg' command" },
    394    { 'grepprg', N_ 'program used for the ":grep" command' },
    395    { 'grepformat', N_ "list of formats for output of 'grepprg'" },
    396    { 'makeencoding', N_ 'encoding of the ":make" and ":grep" output' },
    397    { 'quickfixtextfunc', N_ 'function to display text in the quickfix window' },
    398  },
    399  {
    400    header = N_ 'system specific',
    401    { 'shellslash', N_ 'use forward slashes in file names; for Unix-like shells' },
    402    { 'completeslash', N_ 'specifies slash/backslash used for completion' },
    403  },
    404  {
    405    header = N_ 'language specific',
    406    { 'isfname', N_ 'specifies the characters in a file name' },
    407    { 'isident', N_ 'specifies the characters in an identifier' },
    408    { 'iskeyword', N_ 'specifies the characters in a keyword' },
    409    { 'isprint', N_ 'specifies printable characters' },
    410    { 'quoteescape', N_ 'specifies escape characters in a string' },
    411    { 'rightleft', N_ 'display the buffer right-to-left' },
    412    { 'rightleftcmd', N_ 'when to edit the command-line right-to-left' },
    413    { 'revins', N_ 'insert characters backwards' },
    414    { 'allowrevins', N_ "allow CTRL-_ in Insert and Command-line mode to toggle 'revins'" },
    415    { 'arabic', N_ 'prepare for editing Arabic text' },
    416    { 'arabicshape', N_ 'perform shaping of Arabic characters' },
    417    { 'termbidi', N_ 'terminal will perform bidi handling' },
    418    { 'keymap', N_ 'name of a keyboard mapping' },
    419    { 'langmap', N_ 'list of characters that are translated in Normal mode' },
    420    { 'langremap', N_ "apply 'langmap' to mapped characters" },
    421    { 'iminsert', N_ 'in Insert mode: 1: use :lmap; 2: use IM; 0: neither' },
    422    { 'imsearch', N_ 'entering a search pattern: 1: use :lmap; 2: use IM; 0: neither' },
    423  },
    424  {
    425    header = N_ 'multi-byte characters',
    426    { 'fileencoding', N_ 'character encoding for the current file' },
    427    { 'fileencodings', N_ 'automatically detected character encodings' },
    428    { 'charconvert', N_ 'expression used for character encoding conversion' },
    429    { 'delcombine', N_ 'delete combining (composing) characters on their own' },
    430    { 'ambiwidth', N_ 'width of ambiguous width characters' },
    431    { 'emoji', N_ 'emoji characters are full width' },
    432  },
    433  {
    434    header = N_ 'various',
    435    { 'virtualedit', N_ 'when to use virtual editing: "block", "insert", "all"\nand/or "onemore"' },
    436    { 'eventignore', N_ 'list of autocommand events which are to be ignored' },
    437    { 'eventignorewin', N_ 'list of autocommand events which are to be ignored in a window' },
    438    { 'loadplugins', N_ 'load plugin scripts when starting up' },
    439    { 'exrc', N_ 'enable reading .vimrc/.exrc/.gvimrc in the current directory' },
    440    { 'maxfuncdepth', N_ 'maximum depth of function calls' },
    441    { 'sessionoptions', N_ 'list of words that specifies what to put in a session file' },
    442    { 'viewoptions', N_ 'list of words that specifies what to save for :mkview' },
    443    { 'viewdir', N_ 'directory where to store files with :mkview' },
    444    { 'shada', N_ 'list that specifies what to write in the ShaDa file' },
    445    { 'shadafile', N_ 'overrides the filename used for shada' },
    446    { 'bufhidden', N_ "what happens with a buffer when it's no longer in a window" },
    447    { 'buftype', N_ 'empty, "nofile", "nowrite", "quickfix", etc.: type of buffer' },
    448    { 'buflisted', N_ 'whether the buffer shows up in the buffer list' },
    449    { 'debug', N_ 'set to "msg" to see all error messages' },
    450    { 'signcolumn', N_ 'whether to show the signcolumn' },
    451    { 'pyxversion', N_ 'whether to use Python 2 or 3' },
    452    { 'inccommand', N_ 'live preview of substitution' },
    453    { 'busy', N_ 'buffer is busy' },
    454    { 'termpastefilter', N_ 'characters removed when pasting into terminal window' },
    455    { 'scrollback', N_ 'number of lines kept beyond the visible screen in terminal buffer' },
    456  },
    457 }
    458 
    459 local local_to_window = N_ '(local to window)'
    460 local local_to_buffer = N_ '(local to buffer)'
    461 local global_or_local_to_buffer = N_ '(global or local to buffer)'
    462 local global_or_local_to_window = N_ '(global or local to window)'
    463 
    464 local lines = {
    465  N_ '" Each "set" line shows the current value of an option (on the left).',
    466  N_ '" Hit <Enter> on a "set" line to execute it.',
    467  N_ '"            A boolean option will be toggled.',
    468  N_ '"            For other options you can edit the value before hitting <Enter>.',
    469  N_ '" Hit <Enter> on a help line to open a help window on this option.',
    470  N_ '" Hit <Enter> on an index line to jump there.',
    471  N_ '" Hit <Space> on a "set" line to refresh it.',
    472  '',
    473 }
    474 
    475 for header_number, options in ipairs(options_list) do
    476  table.insert(lines, ('%2d %s'):format(header_number, options.header))
    477 end
    478 table.insert(lines, '')
    479 
    480 for header_number, options in ipairs(options_list) do
    481  table.insert(lines, '')
    482  table.insert(lines, ('%2d %s'):format(header_number, options.header))
    483  table.insert(lines, '')
    484  for _, opt_desc_and_name in ipairs(options) do
    485    local name, desc = unpack(opt_desc_and_name)
    486 
    487    vim.list_extend(
    488      lines,
    489      vim.split(
    490        ('%s%s\t%s'):format(name, #name >= 15 and '\n' or '', desc:gsub('\n', '\n\t')),
    491        '\n'
    492      )
    493    )
    494 
    495    local info = vim.api.nvim_get_option_info2(name, {})
    496 
    497    if info.scope == 'buf' and info.global_local then
    498      table.insert(lines, '\t' .. global_or_local_to_buffer)
    499    elseif info.scope == 'win' and info.global_local then
    500      table.insert(lines, '\t' .. global_or_local_to_window)
    501    elseif info.scope == 'buf' then
    502      table.insert(lines, '\t' .. local_to_buffer)
    503    elseif info.scope == 'win' then
    504      table.insert(lines, '\t' .. local_to_window)
    505    end
    506 
    507    local shortname = info.shortname or name
    508    if shortname == '' then
    509      shortname = name
    510    end
    511 
    512    if info.type == 'boolean' then
    513      if vim.o[name] then
    514        table.insert(lines, (' \tset %s\tno%s'):format(shortname, shortname))
    515      else
    516        table.insert(lines, (' \tset no%s\t%s'):format(shortname, shortname))
    517      end
    518    else
    519      local value = vim.o[name] --[[@as string]]
    520      table.insert(lines, (' \tset %s=%s'):format(shortname, value))
    521    end
    522  end
    523 end
    524 
    525 --- An optwin buffer has 5 types of lines (given pattern):
    526 --- '^".*'       : comment (other)
    527 --- '^ *[0-9]+'  : header (header)
    528 --- '^[^\ts].*'  : option header + description (opt-desc)
    529 --- '^\t.*'      : description continuation (desc-cont)
    530 --- '^ \tset .*' : option set (set)
    531 ---
    532 ---@param line string
    533 ---@return 'set'|'opt-desc'|'desc-cont'|'header'|'other'
    534 local function line_get_type(line)
    535  if line:find('^ \tset ') then
    536    return 'set'
    537  elseif line:find('^%s-[0-9]') then
    538    return 'header'
    539  elseif line:find('^\t') then
    540    return 'desc-cont'
    541  elseif line:find('^[a-z]') then
    542    return 'opt-desc'
    543  end
    544  return 'other'
    545 end
    546 
    547 ---@return integer|false
    548 local function find_window_to_have_options_in()
    549  local thiswin = vim.fn.winnr()
    550  local altwin = vim.fn.winnr('#')
    551 
    552  if vim.bo[vim.fn.winbufnr(altwin)].filetype == 'help' then
    553    altwin = altwin + 1
    554    if altwin == thiswin then
    555      altwin = altwin + 1 --[[@as integer]]
    556    end
    557  end
    558 
    559  if
    560    altwin == 0
    561    or altwin == thiswin
    562    or vim.bo[vim.fn.winbufnr(altwin)].filetype == 'help'
    563    or vim.fn.winnr('$') < altwin
    564  then
    565    vim.notify("Don't know in which window")
    566    return false
    567  end
    568 
    569  return vim.fn.win_getid(altwin)
    570 end
    571 
    572 local function update_current_line()
    573  local line = vim.api.nvim_get_current_line()
    574  if line_get_type(line) ~= 'set' then
    575    return
    576  end
    577 
    578  ---@type string
    579  local name
    580  if line:find('=') then
    581    name = line:match('^ \tset (.-)=')
    582  else
    583    name = line:match('^ \tset ([a-z]*)'):gsub('^no', '') --[[@as string]]
    584  end
    585 
    586  local info = vim.api.nvim_get_option_info2(name, {})
    587 
    588  ---@type any
    589  local value
    590  if info.global_local or info.scope == 'global' then
    591    value = vim.o[name] --[[@as any]]
    592  else
    593    local win = find_window_to_have_options_in()
    594    if not win then
    595      return
    596    end
    597 
    598    value = vim._with({
    599      win = win,
    600    }, function()
    601      return vim.o[name]
    602    end)
    603  end
    604 
    605  if info.type == 'boolean' then
    606    if value then
    607      vim.api.nvim_set_current_line((' \tset %s\tno%s'):format(name, name))
    608    else
    609      vim.api.nvim_set_current_line((' \tset no%s\t%s'):format(name, name))
    610    end
    611  else
    612    vim.api.nvim_set_current_line((' \tset %s=%s'):format(name, value))
    613  end
    614 end
    615 
    616 local function current_line_set_option()
    617  local line = vim.api.nvim_get_current_line()
    618  if line_get_type(line) ~= 'set' then
    619    return
    620  end
    621 
    622  ---@type string
    623  local name
    624  ---@type string|boolean|integer
    625  local value
    626  if line:find('=') then
    627    name, value = line:match('^ \tset (.-)=(.*)')
    628  else
    629    local option = line:match('^ \tset ([a-z]*)')
    630    name = option:gsub('^no', '') --[[@as string]]
    631    value = vim.startswith(option, 'no')
    632  end
    633 
    634  local info = vim.api.nvim_get_option_info2(name, {})
    635 
    636  if info.type == 'number' then
    637    value = assert(tonumber(value), value .. ' is not a number')
    638  end
    639 
    640  if info.global_local or info.scope == 'global' then
    641    ---@diagnostic disable-next-line: no-unknown
    642    vim.o[name] = value
    643  else
    644    local win = find_window_to_have_options_in()
    645    if not win then
    646      return
    647    end
    648 
    649    vim._with({
    650      win = win,
    651    }, function()
    652      ---@diagnostic disable-next-line: no-unknown
    653      vim.o[name] = value
    654    end)
    655  end
    656 
    657  update_current_line()
    658 end
    659 
    660 local buf = vim.fn.bufnr('nvim-optwin://optwin')
    661 if buf >= 0 then
    662  local winids = vim.fn.win_findbuf(buf)
    663  if #winids > 0 and vim.fn.win_gotoid(winids[1]) == 1 then
    664    return
    665  end
    666 
    667  vim.cmd((vim.env.OPTWIN_CMD or '') .. ' new nvim-optwin://optwin')
    668 else
    669  vim.cmd((vim.env.OPTWIN_CMD or '') .. ' new nvim-optwin://optwin')
    670 
    671  buf = vim.api.nvim_get_current_buf()
    672  vim.bo[buf].tabstop = 15
    673  vim.bo[buf].buftype = 'nofile'
    674  vim.api.nvim_buf_set_lines(buf, 0, -1, true, lines)
    675 
    676  vim.bo[buf].filetype = 'vim'
    677  vim.cmd [[
    678  syn match optwinHeader "^ \=[0-9].*"
    679  syn match optwinName "^[a-z]*\t" nextgroup=optwinComment
    680  syn match optwinComment ".*" contained
    681  syn match optwinComment "^\t.*"
    682  if !exists("did_optwin_syntax_inits")
    683    let did_optwin_syntax_inits = 1
    684    hi link optwinHeader Title
    685    hi link optwinName Identifier
    686    hi link optwinComment Comment
    687  endif
    688  ]]
    689 
    690  vim.keymap.set({ 'n', 'i' }, '<CR>', function()
    691    local lnum = vim.fn.search('^[^\t]', 'bcWn')
    692    local line = vim.fn.getline(lnum)
    693 
    694    local line_type = line_get_type(line)
    695 
    696    if line_type == 'set' then
    697      current_line_set_option()
    698    elseif line_type == 'header' then
    699      vim.fn.search(line, 'w')
    700    elseif line_type == 'opt-desc' then
    701      local name = line:match('[^\t]*')
    702      vim.cmd.help(("'%s'"):format(name))
    703    end
    704  end, { buffer = buf })
    705 
    706  vim.keymap.set({ 'n', 'i' }, '<space>', update_current_line, { buffer = buf })
    707 end
    708 
    709 vim.cmd '1'