Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As of Mac OS X Lion 10.7, Terminal supports “bracketed paste mode,” which enables the terminal emulator to tell the program connected to the tty when the user pastes text, so that the program won’t interpret it as editing commands. Programs that support it send the terminal an escape sequence to enable this mode, in which the terminal surrounds pasted text with a pair of escape sequences that identify the start and end.</p> <p>To enable this in Vim, put the following code in your ~/.vimrc file:</p> <pre><code>if &amp;term =~ "xterm.*" let &amp;t_ti = &amp;t_ti . "\e[?2004h" let &amp;t_te = "\e[?2004l" . &amp;t_te function! XTermPasteBegin(ret) set pastetoggle=&lt;Esc&gt;[201~ set paste return a:ret endfunction map &lt;expr&gt; &lt;Esc&gt;[200~ XTermPasteBegin("i") imap &lt;expr&gt; &lt;Esc&gt;[200~ XTermPasteBegin("") vmap &lt;expr&gt; &lt;Esc&gt;[200~ XTermPasteBegin("c") cmap &lt;Esc&gt;[200~ &lt;nop&gt; cmap &lt;Esc&gt;[201~ &lt;nop&gt; endif </code></pre> <p>This makes it so that when Vim switches the terminal to/from the alternate screen† (t_ti, t_te) it enables/disables bracketed paste mode (ESC [? 2004 h, ESC [? 2004 l). When it receives the escape sequence indicating the start of a paste (ESC [ 200 ~), it enables Paste mode (set paste) and switches to Insert mode if necessary ("i"). When it receives the matching end-of-paste marker (ESC [ 201 ~) it disables Paste mode (pastetoggle) and remains in Insert mode. The <code>cmap</code> commands arrange for the Vim command line to ignore the escape sequences and accept the pasted text as-is.</p> <p>Note that this only enables bracketed paste mode when the $TERM value starts with "xterm…"; if you're setting $TERM to something else, you may want to revise that test to include your $TERM value. Or, you could omit the test altogether, since it isn’t strictly necessary—it’s just trying to be careful not to do something that might be incompatible with some other terminal type.</p> <p>In Terminal, this works with all the various Paste commands, as well as with drag-and-drop.</p> <p>† The terminal has a main screen and an "alternate" screen. Each screen has its own contents and state. Text in the alternate screen does not scroll up into the scrollback log. It is typically used by programs that take over control of the whole screen and are therefore referred to as "full screen" programs. This includes vim, emacs, less and top, for example.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload