1484

I am making the effort to learn Vim.

When I paste code into my document from the clipboard, I get extra spaces at the start of each new line:

line
  line
    line

I know you can turn off auto indent but I can't get it to work because I have some other settings conflicting or something (which look pretty obvious in my .vimrc but don't seem to matter when I take them out).

How do I turn off auto indenting when I paste code but still have vim auto indent when I am writing code? Here is my .vimrc file:

set expandtab  
set tabstop=2  
set shiftwidth=2  
set autoindent  
set smartindent  
set bg=dark  
set nowrap  
dreftymac
  • 31,404
  • 26
  • 119
  • 182
Rimian
  • 36,864
  • 16
  • 117
  • 117
  • 4
    FWIW, vim [8.0.210](https://github.com/vim/vim/commit/ec2da36ca48b40c0654b32a8d2c9f52e796daa5e) adds native support for bracketed paste, so it will avoid indenting pasted text. – sh1 Nov 09 '17 at 17:12
  • 2
    For new files in order to avoid fiddling with vim's paste/nopaste you can do `cat > mynewfile.txt` press **Enter**, paste your text, press **Enter** again, and then Ctr+D to save. The file is now created and you can edit it with `vim mynewfile.txt`. – ccpizza Oct 06 '19 at 19:22
  • the cat solution has one disadvantage : variables are changed to the value of that variable – Sloomy Jul 11 '22 at 19:58
  • several years ago this was never an issue ... seems the default behavior has changed as I always use very minimal vim customizations – Scott Stensland Aug 25 '22 at 16:00

27 Answers27

2620

Update: Better answer here: https://stackoverflow.com/a/38258720/62202

To turn off autoindent when you paste code, there's a special "paste" mode.

Type

:set paste

Then paste your code. Note that the text in the tooltip now says -- INSERT (paste) --.

After you pasted your code, turn off the paste-mode, so that auto-indenting when you type works correctly again.

:set nopaste

However, I always found that cumbersome. That's why I map <F3> such that it can switch between paste and nopaste modes while editing the text! I add this to .vimrc

set pastetoggle=<F3>
lsl
  • 4,371
  • 3
  • 39
  • 54
P Shved
  • 96,026
  • 17
  • 121
  • 165
  • 44
    This isn't any easier than `:set noai` followed by `:set ai`. The suggestion of `:r! cat` is shorter. – Leopd May 26 '10 at 21:34
  • 81
    I think `set paste` is easier, definitely. It is much more semantic than `noai` or even `noautoindent`, which is more important when typing "noai" and "paste" take about the same insignificant amount of time when you are proficient enough as a touch typist. – Victor Zamanian Feb 15 '13 at 15:27
  • 54
    `:set noai` doesn't always work, depending on how the other indent-related settings are configured as per the OP. `:set paste` appears to be a shorthand for several settings all at once. – MarkHu Apr 26 '13 at 01:16
  • 15
    Late to the party, but `set copyindent` will take care of this for you seamlessly. – Matt Ryan Feb 06 '14 at 17:53
  • 37
    `:set paste` also disables other features like braces completion, which is also not wanted when pasting code. – Manuel Faux Jun 06 '14 at 11:07
  • 2
    Working in `vim` on a DD-WRT build, `:set paste` does not work, however `:set noai` does. Thanks for that @Leopd, took me forever to figure this out. – Matt Clark Dec 13 '14 at 20:57
  • Is there a way to disable autoindent in my `.vimrc` *only* when pasting from the system clipboard? – jvriesem Sep 11 '15 at 22:57
  • 4
    @jvriesem: there is a plugin for that: https://github.com/ConradIrwin/vim-bracketed-paste – LCC Oct 26 '15 at 21:54
  • :set paste was the only thing that worked for me. OS X El Capitan / Terminal – heisian Nov 04 '16 at 21:30
  • 1
    FYI `set noai` works in BusyBox's vi whereas `:set paste` does not. – stdout Dec 07 '16 at 13:20
  • 1
    This answer is out of date. There are better solutions further down that _automate_ this mode switching according to signals from the terminal. – sh1 Dec 21 '16 at 06:11
  • @sh1: What solutions do you mean? – helvete Sep 20 '17 at 10:26
  • 2
    @helvete, [here](https://stackoverflow.com/a/36512548/2417578) for example. – sh1 Sep 20 '17 at 18:18
  • @Leopd Though the OP just wanted autoindent turned off, setting paste mode is the best and complete option as there can be many other undesired effects (like autocompletion) to avoid. Code golfing approach doesn't suite here. Original/fundamental intentions of those options are different. – 0xc0de Oct 31 '17 at 07:44
  • 1
    @sh1 'Outdated', really? How can setting builtin options be outdated by any plugin? It just uses a trick to simplify this task. Besides it says: - Unfortunately, this means that they will also run the contents of the input buffer if there's a newline in anything you paste into the terminal. - I hope you are aware of and understand that. – 0xc0de Oct 31 '17 at 07:58
  • @0xc0de, I am quite plainly arguing that "[using] a trick to simplify this task" is better. I say "this answer is out of date" because the solutions that I'm saying are better were posted much later than this. I'm sure that when this became the accepted answer it did deserve it and I don't mean to be critical of that decision in the context that it was made. – sh1 Nov 01 '17 at 07:14
  • @jvriesem, with Vim 8+, it can do "set paste" for you when pasting from the system clipboard. That way you don't have to "set paste" manually, and won't forget to turn it off after. https://stackoverflow.com/questions/2514445/turning-off-auto-indent-when-pasting-text-into-vim/56781763#56781763 – wisbucky Jul 17 '19 at 23:28
  • The "better" solution works perfectly locally, but via ssh on putty doesn't work – X3MBoy Aug 25 '22 at 17:12
293

To avoid undesired effects while pasting, there is an option that needs to be set:

set paste

A useful command to have in your .vimrc is set pastetoggle=<F10> or some other button, to easily toggle between paste and nopaste.

0xc0de
  • 8,028
  • 5
  • 49
  • 75
Jacob Rask
  • 22,804
  • 8
  • 38
  • 36
150

I usually use :r! cat and then paste ( shift + insert ) the content, and CTRL+D.

No need to enable & disable, direct usage.

thegeek
  • 2,388
  • 2
  • 13
  • 10
  • I like this direct usage option. I'm still learning how to read vim syntax on web pages, though. What do your steps mean? In particular, supposing I have something on the system clipboard, what do I press to paste it into a document in vim? – jvriesem Nov 04 '15 at 20:55
  • 10
    This answer would be more helpful with information about why and how `:r! cat` works. – K Erlandsson May 09 '16 at 13:32
  • 15
    @KErlandsson, `:r` inserts the contents of a file into the current document. `!cat` says, run cat which essentially opens stdin (*nix shells) `(shift + insert)` or for some terminals, right mouse click will paste the contents of the clipboard to the terminal `CTRL+D` is end-of-file, so it close the `:r !cat` session. – Daniel Sep 05 '16 at 19:39
  • 1
    Is this 'direct', really? Than setting an option `paste` made solely for this purpose? @jvriesem This isn't a 'direct' option, if what I assume of your understanding of that word is correct. – 0xc0de Oct 31 '17 at 07:50
  • You can also use `:r! cat` then `CTRL+SHIFT+V` to paste in the terminal (then `CTRL+D`). – Paul Rougieux Jan 09 '18 at 14:12
  • shotest and simplest ctrl+d – Adiii Oct 25 '19 at 10:41
99

If you are working locally, you can paste from the system clipboard with the key sequence:

"+p

This is a proper vim command, so no need to worry about entering an insert mode or switching off autoindent first.

Of course if you are working remotely (console over SSH, for example) then this won't work and you should go the :set noai, insert mode, paste into console, leave insertmode, :set ai route as described elsewhere.

thomasrutter
  • 114,488
  • 30
  • 148
  • 167
  • 12
    I write this answer ages ago. Nowadays I use `:set paste` and `:set nopaste` instead because despite being longer, it's easier to remember and I don't have to look it up every time! – thomasrutter Feb 06 '13 at 02:49
  • 6
    In some embedded systems (based on busybox mainly) `:set paste` is not implemented, so `:set noai` should be used instead. – jcarballo Aug 06 '13 at 19:26
  • When you have a large text to copy, isn't it faster to use the + register instead? – pedromanoel Apr 14 '14 at 14:35
  • 1
    @pedromanoel that only works when working locally. It won't work accessing vim over SSH, for example, if you copied something locally and want to paste it into vim which is in your SSH session. – thomasrutter Apr 15 '14 at 00:24
  • I found that in a telnet session to an embedded system using `:set noai` works correctly. – BrightIntelDusk Apr 24 '14 at 18:18
  • 1
    @thomasrutter but I mapped this to `p`.. very useful! – Dane Mar 07 '18 at 11:06
  • So, we cand do something like: `:inoremap + "+p` – SergioAraujo Mar 10 '18 at 11:00
82

While setting the paste mode with paste/nopaste/pastetoggle is perfectly fine, you still have to manually enable paste mode before pasting and disable paste mode after pasting. Being the lazy person that I am, below is the best solution that I've found so far, which automatically toggles the paste mode when you paste.

Here's a little trick that uses terminal's bracketed paste mode to automatically set/unset Vim's paste mode when you paste. Put following in your .vimrc:

let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"

inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()

function! XTermPasteBegin()
  set pastetoggle=<Esc>[201~
  set paste
  return ""
endfunction

Now you can paste without explicitly turning paste mode on/off - it is handled automatically for you.

Source: Coderwall

Note: This solution doesn't work in WSL (Windows 10 Subsystem for Linux). If anyone has a solution for WSL, please update this answer or add it in the comments.

Tmux If using tmux, then the declarations need to be double escaped. The code for this is also in Coderwall

Daithí
  • 4,717
  • 5
  • 26
  • 35
thdoan
  • 18,421
  • 1
  • 62
  • 57
  • This is briliant. One thing though... With every paste I get a "0" (zero) charracter in the start of every paste. Any tip for that? – Julius Š. Sep 25 '18 at 08:28
  • also *note* in if using *tmux* then you need to double escape. Code for this is in Coderwall link in answer – Daithí Feb 17 '19 at 00:03
  • 4
    If you are even lazier and copy pasting above code into your .vimrc, do take care of the indentation of the function XTermPasteBegin(). – k1133 Aug 27 '19 at 10:41
  • 3
    I was curious how this worked, and so I searched for Paste Bracketing and found https://gitlab.com/gnachman/iterm2/-/wikis/Paste-Bracketing which explains that the `t_SI` and `t_EI` variables are enabling paste bracketing and disabling it. When paste bracketing is on, pasted text is prefixed by `esc[200~` and followed by `esc[201~`. – PatS Apr 01 '20 at 20:44
  • Unfortunately, this mapping delays switching from insert mode to normal mode about half a second. Is there a way to reduce this delay? – Take Dec 31 '20 at 09:55
  • I just found a plugin which removes the delay: https://github.com/ConradIrwin/vim-bracketed-paste – Take Dec 31 '20 at 10:14
  • After saving this in my ~/.vimrc, I open a file with vi to paste in, but command should I type first? What qwerty keys should I input to enter that command? `ESC + [2004h` results in "Not an editor command" – Wassadamo Aug 05 '22 at 21:36
40

Mac users can avoid auto formatting by reading directly from the pasteboard with:

:r !pbpaste
maniacalrobot
  • 2,413
  • 2
  • 18
  • 20
  • 3
    This is an awesome response. When I do this, however, it hides the document (it looks like I'm back on the command line), but has the text on my clipboard. It prompts me to press enter, so I do, and it returns me back to my document without any changes. What happened, and how do I do what you are saying? – jvriesem Nov 04 '15 at 20:58
  • If you just type `:.!pbpaste`, this should work by replacing the current line with the output of the paste buffer. In general, vim allows you to pipe data that is in your current file to another program and replace the text with the output of the command. So `:1,3!pbpaste` replaces the first three lines of your file with the paste buffer. I use `:.!ppjson` to take a very long (unformatted JSON string) and format it and replace the long string with the formatted equivalent. ppjson is just a bash script that runs `python -m json.tool`. – PatS Apr 01 '20 at 19:41
  • On Linux, `xsel --clipboard` instead of `pbpaste` does the same thing. – Soren Bjornstad Nov 14 '21 at 16:56
20

Here is a post by someone who figured out how to remap the paste event to automatically turn paste mode on and then back off. Works for me in tmux/iTerm on MacOSX.

Von
  • 4,365
  • 2
  • 29
  • 29
  • 1
    Thanks for the tip. I also tracked down a plugin where the person has bundled up similar functionality - http://stackoverflow.com/a/36512548/255961. – studgeek Apr 09 '16 at 03:54
  • This seems to cause a string of 'eeeeeee' when I insert a piece of text from my clipboard. – John Jiang Sep 16 '18 at 05:23
19

I just put set clipboard=unnamed in my .vimrc. That makes the default paste buffer map to X's clipboard.

So, if I mark a bit of text in a terminal, I can simply press p to paste it in vim. Similarly, I can yank things in vim (e.g. YY to yank the current line into the buffer) and middle click in any window to paste it.

I don't know. I find it super convenient.

peterh
  • 11,875
  • 18
  • 85
  • 108
Soren
  • 753
  • 6
  • 11
  • 1
    IMHO, this is the best answer, no need for toggling with F11 (which is preconfigured by default in vim). This works in macs OSX system, I don't know about the others. – LightMan Jul 29 '18 at 11:37
19

I am a Python user who sometimes copy and paste into Vim. (I switched from Mac to Windows WSL) and this was one of the glitches that bothered me.

If you touch a script.py and then vi script.py, Vi will detect it is a Python script and tried to be helpful, autoindent, paste with extra indents, etc. This won't happen if you don't tell it is a Python script.

However, if that is already happening to you, the default autoindent could be a nightmare when you paste already fully indented code (see the tilted ladder shape below).

I tried three options and here are the results

set paste        # works perfect 
set noai         # still introduced extra whitespace
set noautoindent # still introduced extra whitespace

enter image description here enter image description here

B.Mr.W.
  • 18,910
  • 35
  • 114
  • 178
  • same boat—did you end up setting a keyboard shortcut or using a plugin or something that is a viable option? Or just living with it :) – aadibajpai Oct 10 '20 at 00:37
  • 2
    @aadibajpai I put `set pastetoggle=` in my `.vimrc` so pressing F2 toggles paste on and off. – Stephen C Oct 15 '20 at 19:59
17

Add this to your ~/.vimrc and you will only have to press F2 before and after pasting:

set pastetoggle=<F2>
anh_ng8
  • 1,100
  • 10
  • 16
13

Another answer I did not see until now:

:se paste noai
sjas
  • 18,644
  • 14
  • 87
  • 92
  • the command :set paste noai works for pasting in afterwards - do you know of a way to reformat already pasted in text? – serup Mar 22 '23 at 11:53
11

When working inside a terminal the vim-bracketed-paste vim plugin will automatically handle pastes without needing any keystrokes before or after the paste.

It works by detecting bracketed paste mode which is an escape sequence sent by "modern" x-term compatible terminals like iTerm2, gnome-terminal, and other terminals using libvte. As an added bonus it works also for tmux sessions. I am using it successfully with iTerm2 on a Mac connecting to a linux server and using tmux.

studgeek
  • 14,272
  • 6
  • 84
  • 96
  • Beware of what it also notes further: Unfortunately, this means that they will also run the contents of the input buffer if there's a newline in anything you paste into the terminal. – 0xc0de Oct 31 '17 at 08:01
  • 1
    @0xc0de, that quote is not relevant here. That's talking about what a _shell_ will do when it does _not_ support bracketed paste mode. That's the point in bracketed paste mode -- to stop that from happening. – sh1 Nov 01 '17 at 06:46
  • This worked much better for me than the other solutions. Thanks. – jjj Nov 05 '17 at 20:55
9

Stick this in your ~/.vimrc and be happy:

" enables :Paste to just do what you want
command Paste execute 'set noai | insert | set ai'

Edit: on reflection, :r !cat is a far better approach since it's short, semantic, and requires no custom vimrc. Use that instead!

Dergachev
  • 348
  • 3
  • 6
7

Another way to paste is via <C-r> in insert mode and dropping the contents of the register (here the global register). See: :h i_ctrl-r and h i_CTRL-R_CTRL-O.

From the vim help documentation:

Insert the contents of a register literally and don't auto-indent. Does the same as pasting with the mouse. Does not replace characters! The '.' register (last inserted text) is still inserted as typed.{not in Vi}

So to paste contents into vim without auto indent, use <C-r><C-o>* in most unix systems.

You can add a mapping in the your vimrc inoremap <C-r> <C-r><C-o> so you can paste the contents of the * register normally without the auto indent by using <C-r>*.

Note: this only works if vim is compiled with clipboard.

TheChetan
  • 4,440
  • 3
  • 32
  • 41
  • Cheers, this is the best solution so far since I only have this problem with for some reason, p in command mode is unaffected by this problem. Ideally it would be nice if could simply behave like p, but this will do in the meantime! – Nicolas Martel Dec 11 '20 at 19:41
  • Live will never be the same for me, thank you! – Artur Dumchev Nov 08 '22 at 14:08
6

Although :pastetoggle or :paste and :nopaste should be working fine (if implemented - they are not always as we can see from the discussion) I highly recomment pasting using the direct approach "+p or "*p and reading with "+r or "*r:

Vim has acess to ten types of registers (:help registers) and the questioner is interested in quotestar and quoteplus from section

  1. Selection and drop registers "*, "+ and "~

Use these registers for storing and retrieving the selected text for the GUI. See quotestar and quoteplus. When the clipboard is not available or not working, the unnamed register is used instead. For Unix systems the clipboard is only available when the +xterm_clipboard feature is present. {not in Vi}

Note that there is only a distinction between "* and "+ for X11 systems.

:help x11-selection further clarifies the difference of * and +:

                                                  quoteplus quote+

There are three documented X selections: PRIMARY (which is expected to represent the current visual selection - as in Vim's Visual mode), SECONDARY (which is ill-defined) and CLIPBOARD (which is expected to be used for cut, copy and paste operations).

Of these three, Vim uses PRIMARY when reading and writing the "* register (hence when the X11 selections are available, Vim sets a default value for 'clipboard' of "autoselect"), and CLIPBOARD when reading and writing the "+ register. Vim does not access the SECONDARY selection.

Examples: (assuming the default option values)

  • Select an URL in Visual mode in Vim. Go to your browser and click the middle mouse button in the URL text field. The selected text will be inserted (hopefully!). Note: in Firefox you can set the middlemouse.contentLoadURL preference to true in about:config, then the selected URL will be used when pressing middle mouse button in most places in the window.

  • Select some text in your browser by dragging with the mouse. Go to Vim and press the middle mouse button: The selected text is inserted.

  • Select some text in Vim and do "+y. Go to your browser, select some text in a textfield by dragging with the mouse. Now use the right mouse button and select "Paste" from the popup menu. The selected text is overwritten by the text from Vim. Note that the text in the "+ register remains available when making a Visual selection, which makes other text available in the "* register. That allows overwriting selected text.
codingdave
  • 1,207
  • 16
  • 23
  • i have noticed using middle click in vim doesn't appear to mess up indentation so that might be an idea – Fuseteam Feb 07 '20 at 12:24
5

From vim: ]p

From outside: "*]p or "+]p

Bruno
  • 93
  • 1
  • 6
4

This works for me ( case for + register, what i use like exchange buffer between aps ):

imap <silent> <S-Insert> <C-O>:set noai<CR><C-R>+<C-O>:set ai<CR>
Sergey Vakulenko
  • 1,655
  • 18
  • 23
3

This issue has already been answered, but I though I could also add my own solution:

If you simply want to disable auto-indent system wise, for every file type (basically, disable the auto-indent feature completely), you can do the following:

  1. Backup the indent.vim file:
    sudo mv /usr/share/vim/vim81/indent.vim /usr/share/vim/vim81/indent.vim.orig
  2. Create a new empty indent.vim file:
    sudo touch /usr/share/vim/vim81/indent.vim
Gael
  • 444
  • 3
  • 10
  • I actually prefer this solution, since it doesn't permanently alter vim's original settings. – Zak Aug 30 '22 at 20:35
2

If you are on a mac, macvim seems to handle it well without having to toggle paste.

brew install macvim --override-system-vim

Marcus Ericsson
  • 1,949
  • 1
  • 12
  • 13
2

Native paste / bracketed paste is the best and simplest way since vim 8 (released in 2016). It even works over ssh! (Bracketed paste works on Linux and Mac, but not Windows Git Bash)

  1. Make sure you have vim 8+ (you don't need the +clipboard or +xterm_clipboard options).

    vim --version | head -1

  2. Simply use the OS native paste command (e.g. ctrl+shift+V or cmd+V) in Normal Mode. Do not press i for Insert Mode.


Test

  1. Copy (ctrl+shift+C or cmd+C) the output of this (2 lines with a tab indent) to the system clipboard:

    echo -e '\ta\n\tb'

  2. Launch a clean vim 8+ with autoindent:

    vim -u NONE --noplugin -c 'set autoindent'

  3. Paste from the system clipboard (ctrl+shift+V or cmd+V) in Normal Mode. Do not press i for Insert Mode. The a and b should be aligned with a single tab indent. You can even do this while ssh-ing to a remote machine (the remote machine will need vim 8+).

  4. Now try the old way, which will autoindent the second line with an extra tab: Press i for Insert Mode. Then paste using ctrl+shift+V or cmd+V. The a and b are misaligned now.


Installing Vim 8

wisbucky
  • 33,218
  • 10
  • 150
  • 101
  • 1
    best and simplest way! Also, Google suggested it in ```Featured snippet``` for my search 'paste content no tabs vim', maybe because, I used 'tab' keyword, only in this answer mentioned :) – David Jul 14 '19 at 06:44
1

Please read this article: Toggle auto-indenting for code paste

Some people like the visual feedback shown in the status line by the following alternative for your vimrc:

nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
set showmode
d.danailov
  • 9,594
  • 4
  • 51
  • 36
1

The fastest way I’m aware of to quickly go to paste-insert mode for a one-shot paste is tpope’s unimpaired, which features yo and yO, presumably mnemonics for “you open”. They’re only documented in his vimdoc, as:

A toggle has not been provided for 'paste' because the typical use case of wrapping of a solitary insertion is so wasteful: You toggle twice, but you only paste once (YOPO). Instead, press yo or yO to invoke o or O with 'paste' already set. Leaving insert mode sets 'nopaste' automatically.

Micah Elliott
  • 9,600
  • 5
  • 51
  • 54
1

The following vim plugin handles that automatically through its "Bracketed Paste" mode: https://github.com/wincent/terminus

Sets up "Bracketed Paste" mode, which means you can forget about manually setting the 'paste' option and simply go ahead and paste in any mode.

thiagowfx
  • 4,832
  • 6
  • 37
  • 51
0

Sadly I found the vim plugin mentioned not to be working with iTerm2 3.0.15 (to be fair I don't know if this broke on older versions) - but I found this hack instead.

Map command-p to do the paste and using iTerm2 vim keys. Obviously this only works for iTerm2.

How it works. I use "jk" to enter escape mode so you will also need:

:inoremap jk

in your .vimrc.

Then it just invokes P to enter paste mode, "+p to paste from the clipboard and then P to disable paste mode. hth.

enter image description here

Goblinhack
  • 2,859
  • 1
  • 26
  • 26
  • 1
    Wait, what, you use 'jk' for this? – 0xc0de Oct 31 '17 at 07:46
  • Oh yeah, I'd forgotten to mention that. Just add ":inoremap jk " to your .vimrc. As to *why* I use jk, ask Apple and why they felt the need to move and get rid of the physical escape key. 8( – Goblinhack Oct 31 '17 at 11:41
  • BTW it takes some training but after a while jk feels faster and I think I prefer it now over escape... Anyway would be interesting to know if iTerm2 accepts here also. – Goblinhack Oct 31 '17 at 11:48
  • Way to go Apple! – 0xc0de Nov 01 '17 at 05:40
0

If you use the vim above v8.2, you can check with :help tmux-integration.

If you experience issues when running Vim inside tmux, here are a few hints. You can comment-out parts if something doesn't work (it may depend on the terminal that tmux is running in):

if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
    " Better mouse support, see  :help 'ttymouse'
    set ttymouse=sgr

    " Enable true colors, see  :help xterm-true-color
    let &termguicolors = v:true
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"

    " Enable bracketed paste mode, see  :help xterm-bracketed-paste
    let &t_BE = "\<Esc>[?2004h"
    let &t_BD = "\<Esc>[?2004l"
    let &t_PS = "\<Esc>[200~"
    let &t_PE = "\<Esc>[201~"

    " Enable focus event tracking, see  :help xterm-focus-event
    let &t_fe = "\<Esc>[?1004h"
    let &t_fd = "\<Esc>[?1004l"

    " Enable modified arrow keys, see  :help xterm-modifier-keys
    execute "silent! set <xUp>=\<Esc>[@;*A"
    execute "silent! set <xDown>=\<Esc>[@;*B"
    execute "silent! set <xRight>=\<Esc>[@;*C"
    execute "silent! set <xLeft>=\<Esc>[@;*D"
endif
Ela Dute
  • 686
  • 8
  • 13
0

If you want to turn off autoindent forever,you can remove this file /usr/share/vim/vim82/indent.vim and add set paste to your vimrc file

luoziluojun
  • 116
  • 10
0

VimL:

inoremap <silent> <S-Insert> <Cmd>set paste<CR><C-r>+<Cmd>set nopaste<CR>

Neovim lua:

vim.keymap.set("i", "<S-Insert>", [[<Cmd>set paste<CR><C-r>+<Cmd>set nopaste<CR>]], { noremap = true, silent = true })