1

I am using vim and simply want to disable auto indent when I paste text into my terminal vim session. I have tried numerous solutions including various incantations of below to ~/.vimrc:

set nopaste

"  https://kb.iu.edu/d/afcw
"  set noautoindent


"   https://vi.stackexchange.com/questions/5310/how-can-i-stop-vim-automatically-inserting-a-tab-in-css-files
"  set indentexpr=""


filetype indent off


"  set pastetoggle=
set pastetoggle=

" set paste


" se paste


" au FileType html,htmldjango setlocal indentexpr=


" set nosmartindent
" set cindent
" filetype plugin indent on
" set cinkeys-=0#
" set indentkeys-=0#
" autocmd FileType * set cindent "some file types override it


"  https://unix.stackexchange.com/questions/106526/stop-vim-from-messing-up-my-indentation-on-comments
set nosmartindent
set cindent
set cinkeys-=0#
set indentkeys-=0#

As you can see bad advice is easily obtained. I am on Ubuntu 18.04 and have not customized anything so its stock vim. I see the vim package has given me

~/.vim/bundle/Vundle.vim/

which I have not modified

vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:44:48)
Included patches: 1-1689
Extra patches: 8.0.0056
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version without GUI.  Features included (+) or not (-):

Here is an example of badness when I paste properly formatted code into vim vim blah.go

import (
            "bufio"
                "fmt"
                    "os"
                        "bytes"
                            "io"
                    )

                    func read_stdin(io_reader io.Reader) (string, error) {

                                var buffer bytes.Buffer

                                    scanner := bufio.NewScanner( io_reader )

                                        for scanner.Scan() {
                                                        buffer.WriteString( scanner.Text() + "\n" )
                                                            }
                                                                if err := scanner.Err(); err != nil {

                                                                                return "", err
                                                                                    }

This auto indent issue pervades many filename suffixes so I am not looking for any suffix specific or source code editing language specific addons.

3

You are looking for :h 'paste' and :h 'pastetoggle'.

It is not really a good idea to set paste in your vimrc since most of the time you don't want to have it set.

The idea is to use set paste just before you copy your text and go back to nopaste right after.

The easiest way to do that is to put something like this in your vimrc:

set pastetoggle=<F11>

Then you can simply press <F11> before and after you paste and you should be good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.