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


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 (

                    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.

PS this was never an issue until about a year ago


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.


I find its easier to put below into top of my ~/.vimrc

unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim

"  to shut off paste indent
se paste

this is on Ubuntu 18.04 and above when using stock vim

here are vim version details

/usr/bin/vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 15 2020 06:40:31)
Included patches: 1-2269
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       -tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     -perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           +python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          -ruby              +wildmenu
+cursorbind        -lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      +sound             -xfontset
+digraphs          +mouse             +spell             -xim
-dnd               -mouseshape        +startuptime       -xpm
-ebcdic            +mouse_dec         +statusline        -xsmp
+emacs_tags        +mouse_gpm         -sun_workshop      -xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          +mouse_netterm     +tag_binary        
+extra_search      +mouse_sgr         -tag_old_static    
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-iU6mZD/vim-8.1.2269=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lcanberra -lacl -lattr -lgpm -ldl     -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm      

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.