Skip to content

Commit

Permalink
feat(options)!: deprecate paste, remove pastetoggle (#22647)
Browse files Browse the repository at this point in the history
we cannot remove 'paste'. It is very common in plugins and configs.

'pastetoggle' can and should be removed though, it's a total waste of everyone's time because it generates bug reports and doesn't work well, and is useless because bracketed-paste works better.
  • Loading branch information
ii14 committed Mar 13, 2023
1 parent 673d2b5 commit 2daf0b3
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 325 deletions.
1 change: 0 additions & 1 deletion runtime/doc/autocmd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ InsertCharPre When a character is typed in Insert mode,
inserted literally.

Cannot change the text. |textlock|
Not triggered when 'paste' is set.
*InsertEnter*
InsertEnter Just before starting Insert mode. Also for
Replace mode and Virtual Replace mode. The
Expand Down
2 changes: 0 additions & 2 deletions runtime/doc/change.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,6 @@ Note that when 'textwidth' is 0, Vim does no automatic formatting anyway (but
does insert comment leaders according to the 'comments' option). An exception
is when the 'a' flag is present. |auto-format|

Note that when 'paste' is on, Vim does no formatting at all.

Note that 'textwidth' can be non-zero even if Vim never performs auto-wrapping;
'textwidth' is still useful for formatting with "gq".

Expand Down
21 changes: 21 additions & 0 deletions runtime/doc/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ OPTIONS
- 'viewoptions' Flags "unix", "slash" are ignored and always enabled.
- *'viminfo'* Deprecated alias to 'shada' option.
- *'viminfofile'* Deprecated alias to 'shadafile' option.
- *'paste'* *'nopaste'* This option is obsolete; |paste| is handled automatically.
Enables "paste mode":
- mappings in Insert mode and Command-line mode are
disabled
- abbreviations are disabled
- 'autoindent' is reset
- 'expandtab' is reset
- 'formatoptions' is used like it is empty
- 'revins' is reset
- 'ruler' is reset
- 'showmatch' is reset
- 'smartindent' is reset
- 'smarttab' is reset
- 'softtabstop' is set to 0
- 'textwidth' is set to 0
- 'wrapmargin' is set to 0
These options keep their value, but their effect is
disabled:
- 'cindent'
- 'indentexpr'
- 'lisp'

UI EXTENSIONS
- *ui-wildmenu* Use |ui-cmdline| with |ui-popupmenu| instead. Enabled
Expand Down
5 changes: 1 addition & 4 deletions runtime/doc/map.txt
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,7 @@ this (see |<>|). Example: >
:map _ls :!ls -l %:S<CR>:echo "the end"<CR>
To avoid mapping of the characters you type in insert or Command-line mode,
type a CTRL-V first. The mapping in Insert mode is disabled if the 'paste'
option is on.
type a CTRL-V first.
*map-error*
Note that when an error is encountered (that causes an error message or might
cause a beep) the rest of the mapping is not executed. This is Vi-compatible.
Expand Down Expand Up @@ -1070,8 +1069,6 @@ Abbreviations are never recursive. You can use ":ab f f-o-o" without any
problem. But abbreviations can be mapped. {some versions of Vi support
recursive abbreviations, for no apparent reason}

Abbreviations are disabled if the 'paste' option is on.

*:abbreviate-local* *:abbreviate-<buffer>*
Just like mappings, abbreviations can be local to a buffer. This is mostly
used in a |filetype-plugin| file. Example for a C plugin file: >
Expand Down
3 changes: 3 additions & 0 deletions runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ The following changes may require adaptations in user config or plugins.
- `printheader`
- `printmbcharset`

'paste' option is now deprecated and 'pastetoggle' is removed. |paste| works
automatically in GUI and terminal (TUI) Nvim. Just Paste It.™

• libiconv and intl are now required build dependencies.

• Unsaved changes are now preserved rather than discarded when |channel-stdio|
Expand Down
97 changes: 2 additions & 95 deletions runtime/doc/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,6 @@ A jump table for the options with a short description can be found at |Q_op|.
line.
When 'smartindent' or 'cindent' is on the indent is changed in
a different way.
The 'autoindent' option is reset when the 'paste' option is set and
restored when 'paste' is reset.
{small difference from Vi: After the indent is deleted when typing
<Esc> or <CR>, the cursor position when moving up or down is after the
deleted indent; Vi puts the cursor somewhere in the deleted indent}.
Expand Down Expand Up @@ -1266,7 +1264,6 @@ A jump table for the options with a short description can be found at |Q_op|.
See |C-indenting|.
When you don't like the way 'cindent' works, try the 'smartindent'
option or 'indentexpr'.
This option is not used when 'paste' is set.

*'cinkeys'* *'cink'*
'cinkeys' 'cink' string (default "0{,0},0),0],:,0#,!^F,o,O,e")
Expand Down Expand Up @@ -2246,8 +2243,6 @@ A jump table for the options with a short description can be found at |Q_op|.
<Tab>. Spaces are used in indents with the '>' and '<' commands and
when 'autoindent' is on. To insert a real tab when 'expandtab' is
on, use CTRL-V<Tab>. See also |:retab| and |ins-expandtab|.
This option is reset when the 'paste' option is set and restored when
the 'paste' option is reset.

*'exrc'* *'ex'* *'noexrc'* *'noex'*
'exrc' 'ex' boolean (default off)
Expand Down Expand Up @@ -2749,9 +2744,8 @@ A jump table for the options with a short description can be found at |Q_op|.
'formatoptions' 'fo' string (default: "tcqj")
local to buffer
This is a sequence of letters which describes how automatic
formatting is to be done. See |fo-table|. When the 'paste' option is
on, no formatting is done (like 'formatoptions' is empty). Commas can
be inserted for readability.
formatting is to be done. See |fo-table|. Commas can be inserted for
readability.
To avoid problems with flags that are added in the future, use the
"+=" and "-=" feature of ":set" |add-option-flags|.

Expand Down Expand Up @@ -3392,7 +3386,6 @@ A jump table for the options with a short description can be found at |Q_op|.
When this option is not empty, it overrules the 'cindent' and
'smartindent' indenting. When 'lisp' is set, this option is
is only used when 'lispoptions' contains "expr:1".
When 'paste' is set this option is not used for indenting.
The expression is evaluated with |v:lnum| set to the line number for
which the indent is to be computed. The cursor is also in this line
when the expression is evaluated (but it may be moved around).
Expand Down Expand Up @@ -3761,7 +3754,6 @@ A jump table for the options with a short description can be found at |Q_op|.
The '-' character is included in keyword characters. Redefines the
"=" operator to use this same indentation algorithm rather than
calling an external program if 'equalprg' is empty.
This option is not used when 'paste' is set.

*'lispoptions'* *'lop'*
'lispoptions' 'lop' string (default "")
Expand Down Expand Up @@ -4474,77 +4466,6 @@ A jump table for the options with a short description can be found at |Q_op|.
Specifies the nroff macros that separate paragraphs. These are pairs
of two letters (see |object-motions|).

*'paste'* *'nopaste'*
'paste' boolean (default off)
global
This option is obsolete; |bracketed-paste-mode| is built-in.

Put Vim in Paste mode. This is useful if you want to cut or copy
some text from one window and paste it in Vim. This will avoid
unexpected effects.
Setting this option is useful when using Vim in a terminal, where Vim
cannot distinguish between typed text and pasted text. In the GUI, Vim
knows about pasting and will mostly do the right thing without 'paste'
being set. The same is true for a terminal where Vim handles the
mouse clicks itself.
This option is reset when starting the GUI. Thus if you set it in
your vimrc it will work in a terminal, but not in the GUI. Setting
'paste' in the GUI has side effects: e.g., the Paste toolbar button
will no longer work in Insert mode, because it uses a mapping.
When the 'paste' option is switched on (also when it was already on):
- mapping in Insert mode and Command-line mode is disabled
- abbreviations are disabled
- 'autoindent' is reset
- 'expandtab' is reset
- 'hkmap' is reset
- 'revins' is reset
- 'ruler' is reset
- 'showmatch' is reset
- 'smarttab' is reset
- 'softtabstop' is set to 0
- 'textwidth' is set to 0
- 'wrapmargin' is set to 0
- 'varsofttabstop' is made empty
These options keep their value, but their effect is disabled:
- 'cindent'
- 'formatoptions' is used like it is empty
- 'indentexpr'
- 'lisp'
- 'smartindent'
NOTE: When you start editing another file while the 'paste' option is
on, settings from the modelines or autocommands may change the
settings again, causing trouble when pasting text. You might want to
set the 'paste' option again.
When the 'paste' option is reset the mentioned options are restored to
the value before the moment 'paste' was switched from off to on.
Resetting 'paste' before ever setting it does not have any effect.
Since mapping doesn't work while 'paste' is active, you need to use
the 'pastetoggle' option to toggle the 'paste' option with some key.

*'pastetoggle'* *'pt'*
'pastetoggle' 'pt' string (default "")
global
When non-empty, specifies the key sequence that toggles the 'paste'
option. This is like specifying a mapping: >
:map {keys} :set invpaste<CR>
< Where {keys} is the value of 'pastetoggle'.
The difference is that it will work even when 'paste' is set.
'pastetoggle' works in Insert mode and Normal mode, but not in
Command-line mode.
Mappings are checked first, thus overrule 'pastetoggle'. However,
when 'paste' is on mappings are ignored in Insert mode, thus you can do
this: >
:map <F10> :set paste<CR>
:map <F11> :set nopaste<CR>
:imap <F10> <C-O>:set paste<CR>
:imap <F11> <nop>
:set pastetoggle=<F11>
< This will make <F10> start paste mode and <F11> stop paste mode.
Note that typing <F10> in paste mode inserts "<F10>", since in paste
mode everything is inserted literally, except the 'pastetoggle' key
sequence.
When the value has several bytes 'ttimeoutlen' applies.

*'pex'* *'patchexpr'*
'patchexpr' 'pex' string (default "")
global
Expand Down Expand Up @@ -4827,8 +4748,6 @@ A jump table for the options with a short description can be found at |Q_op|.
Inserting characters in Insert mode will work backwards. See "typing
backwards" |ins-reverse|. This option can be toggled with the CTRL-_
command in Insert mode, when 'allowrevins' is set.
This option is reset when 'paste' is set and restored when 'paste' is
reset.

*'rightleft'* *'rl'* *'norightleft'* *'norl'*
'rightleft' 'rl' boolean (default off)
Expand Down Expand Up @@ -4877,8 +4796,6 @@ A jump table for the options with a short description can be found at |Q_op|.
separated with a dash.
For an empty line "0-1" is shown.
For an empty buffer the line number will also be zero: "0,0-1".
This option is reset when 'paste' is set and restored when 'paste' is
reset.
If you don't want to see the ruler all the time but want to know where
you are, use "g CTRL-G" |g_CTRL-G|.

Expand Down Expand Up @@ -5610,8 +5527,6 @@ A jump table for the options with a short description can be found at |Q_op|.
show the match can be set with 'matchtime'.
A Beep is given if there is no match (no matter if the match can be
seen or not).
This option is reset when 'paste' is set and restored when 'paste' is
reset.
When the 'm' flag is not included in 'cpoptions', typing a character
will immediately move the cursor back to where it belongs.
See the "sm" field in 'guicursor' for setting the cursor shape and
Expand Down Expand Up @@ -5733,8 +5648,6 @@ A jump table for the options with a short description can be found at |Q_op|.
mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
When using the ">>" command, lines starting with '#' are not shifted
right.
This option is reset when 'paste' is set and restored when 'paste' is
reset.

*'smarttab'* *'sta'* *'nosmarttab'* *'nosta'*
'smarttab' 'sta' boolean (default on)
Expand All @@ -5749,8 +5662,6 @@ A jump table for the options with a short description can be found at |Q_op|.
What gets inserted (a <Tab> or spaces) depends on the 'expandtab'
option. Also see |ins-expandtab|. When 'expandtab' is not set, the
number of spaces is minimized by using <Tab>s.
This option is reset when 'paste' is set and restored when 'paste' is
reset.

*'softtabstop'* *'sts'*
'softtabstop' 'sts' number (default 0)
Expand All @@ -5763,8 +5674,6 @@ A jump table for the options with a short description can be found at |Q_op|.
commands like "x" still work on the actual characters.
When 'sts' is zero, this feature is off.
When 'sts' is negative, the value of 'shiftwidth' is used.
'softtabstop' is set to 0 when the 'paste' option is set and restored
when 'paste' is reset.
See also |ins-expandtab|. When 'expandtab' is not set, the number of
spaces is minimized by using <Tab>s.
The 'L' flag in 'cpoptions' changes how tabs are used when 'list' is
Expand Down Expand Up @@ -6579,8 +6488,6 @@ A jump table for the options with a short description can be found at |Q_op|.
Maximum width of text that is being inserted. A longer line will be
broken after white space to get this width. A zero value disables
this.
'textwidth' is set to 0 when the 'paste' option is set and restored
when 'paste' is reset.
When 'textwidth' is zero, 'wrapmargin' may be used. See also
'formatoptions' and |ins-textwidth|.
When 'formatexpr' is set it will be used to break the line.
Expand Down
2 changes: 0 additions & 2 deletions runtime/doc/quickref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,6 @@ Short explanation of each option: *option-list*
'operatorfunc' 'opfunc' function to be called for |g@| operator
'packpath' 'pp' list of directories used for packages
'paragraphs' 'para' nroff macros that separate paragraphs
'paste' allow pasting text
'pastetoggle' 'pt' key code that causes 'paste' to toggle
'patchexpr' 'pex' expression used to patch a file
'patchmode' 'pm' keep the oldest version of a file
'path' 'pa' list of directories searched with "gf" et.al.
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/vim_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ Options:
'highlight' (Names of builtin |highlight-groups| cannot be changed.)
*'hkmap'* *'hk'* use `set keymap=hebrew` instead.
*'hkmapp'* *'hkp'* use `set keymap=hebrewp` instead.
*'pastetoggle'* *'pt'*

*'imactivatefunc'* *'imaf'*
*'imactivatekey'* *'imak'*
Expand Down
20 changes: 1 addition & 19 deletions runtime/optwin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ func <SID>Update(lnum, line, local, thiswin)
else
let name = substitute(a:line, '^ \tset \(no\)\=\([a-z]*\).*', '\2', "")
endif
if name == "pt" && &pt =~ "\x80"
let val = <SID>PTvalue()
else
let val = escape(eval('&' . name), " \t\\\"|")
endif
let val = escape(eval('&' . name), " \t\\\"|")
if a:local
exe a:thiswin . "wincmd w"
endif
Expand Down Expand Up @@ -211,14 +207,6 @@ func <SID>Header(text)
let s:lnum = s:lnum + 1
endfunc

" Get the value of 'pastetoggle'. It could be a special key.
func <SID>PTvalue()
redir @a
silent set pt
redir END
return substitute(@a, '[^=]*=\(.*\)', '\1', "")
endfunc

" Restore the previous value of 'cpoptions' here, it's used below.
let &cpo = s:cpo_save

Expand All @@ -232,12 +220,6 @@ call <SID>AddOption("cpoptions", gettext("list of flags to specify Vi compatibil
call <SID>OptionG("cpo", &cpo)
call <SID>AddOption("paste", gettext("paste mode, insert typed text literally"))
call <SID>BinOptionG("paste", &paste)
call <SID>AddOption("pastetoggle", gettext("key sequence to toggle paste mode"))
if &pt =~ "\x80"
call append("$", " \tset pt=" . <SID>PTvalue())
else
call <SID>OptionG("pt", &pt)
endif
call <SID>AddOption("runtimepath", gettext("list of directories used for runtime files and plugins"))
call <SID>OptionG("rtp", &rtp)
call <SID>AddOption("packpath", gettext("list of directories used for plugin packages"))
Expand Down
52 changes: 0 additions & 52 deletions src/nvim/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2073,39 +2073,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
}
}

// Check for match with 'pastetoggle'
if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) {
bool match = typebuf_match_len((uint8_t *)p_pt, &mlen);
if (match) {
// write chars to script file(s)
if (mlen > typebuf.tb_maplen) {
gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen,
(size_t)(mlen - typebuf.tb_maplen));
}

del_typebuf(mlen, 0); // remove the chars
set_option_value_give_err("paste", !p_paste, NULL, 0);
if (!(State & MODE_INSERT)) {
msg_col = 0;
msg_row = Rows - 1;
msg_clr_eos(); // clear ruler
}
status_redraw_all();
redraw_statuslines();
showmode();
setcursor();
*keylenp = keylen;
return map_result_retry;
}
// Need more chars for partly match.
if (mlen == typebuf.tb_len) {
keylen = KEYLEN_PART_KEY;
} else if (max_mlen < mlen) {
// no match, may have to check for termcode at next character
max_mlen = mlen + 1;
}
}

if ((mp == NULL || max_mlen > mp_match_len) && keylen != KEYLEN_PART_MAP) {
// When no matching mapping found or found a non-matching mapping that
// matches at least what the matching mapping matched:
Expand All @@ -2116,13 +2083,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
|| (typebuf.tb_buf[typebuf.tb_off + 1] == KS_MODIFIER && typebuf.tb_len < 4))) {
// Incomplete modifier sequence: cannot decide whether to simplify yet.
keylen = KEYLEN_PART_KEY;
} else if (keylen == KEYLEN_PART_KEY && !*timedout) {
// If 'pastetoggle' matched partially, don't simplify.
// When the last characters were not typed, don't wait for a typed character to
// complete 'pastetoggle'.
if (typebuf.tb_len == typebuf.tb_maplen) {
keylen = 0;
}
} else {
// Try to include the modifier into the key.
keylen = check_simplify_modifier(max_mlen + 1);
Expand Down Expand Up @@ -2923,18 +2883,6 @@ int fix_input_buffer(uint8_t *buf, int len)
return len;
}

static bool typebuf_match_len(const uint8_t *str, int *mlen)
{
int i;
for (i = 0; i < typebuf.tb_len && str[i]; i++) {
if (str[i] != typebuf.tb_buf[typebuf.tb_off + i]) {
break;
}
}
*mlen = i;
return str[i] == NUL; // matched the whole string
}

/// Get command argument for <Cmd> key
char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat)
{
Expand Down

0 comments on commit 2daf0b3

Please sign in to comment.