1

Using following .vimrc

" Just to see tab/spaces/endline clearly:
set encoding=utf-8
set list
set listchars=tab:▸\ ,eol:¬
nnoremap <F5> :set list!<cr>

" Tab to spaces settings
set tabstop=4
set softtabstop=4
set shiftwidth=4
set shiftround
set expandtab

" paste and pastetoggle settings
set nopaste
set pastetoggle=<F2>

Now open a test-file and type following: i<TAB><F2><TAB>

  • go to insert mode
  • TAB => gives space
  • to insert-paste mode
  • TAB => gives TAB but i would like spaces

Is it possible to have spaces in the insert-paste mode or do I really have to leave PASTE mode each time again? I just like to stay in paste mode as i copy-paste a lot of snippets constantly from other terminals.

2
  • 3
    paste mode is just a temporary hack, that should make pasting into the terminal much easier. It is not intended to be a permanent mode. And since the whole point of the paste mode is to get every character as pasted, it does not make sense to replace a tab by a space. Have you tried bracketed paste mode (or using the clipboard) instead? Feb 25 '19 at 9:59
  • Thank you. I think that will do the trick. No more need the paste mode then. Feb 26 '19 at 2:49
0

Yes, you have to.

To make it easier, you could add the following snippet to your vimrc:

set pastetoggle=<F9>
noremap  <F9>   :set invpaste paste?<CR>
inoremap <F9>   <C-O>:set invpaste<CR>

This toggles paste mode by simply hitting F9. This works in normal mode and insert mode.

If you like to use another key, just change <F9> to something else.

BTW: The setting pastetoggle defines a key that should NOT be inserted in the text, but handled normally by Vim. Without this setting, Vim would just insert <F9> in the text if you hit F9 while in insert mode.

5
  • Sorry, this one did not help. Still have <TAB>'s in the paste-insert mode. Feb 26 '19 at 2:50
  • @aldwinaldwin You question was: "Do I have to leave PASTE mode?". The answer is "yes", and this shows how to toggle PASTE mode with just one key press.
    – Ralf
    Feb 26 '19 at 5:29
  • @Ralf why add n and i map? is it necessary? what's the meaning of the paste? in n map command?
    – dedowsdi
    Mar 30 '19 at 2:26
  • @XianDongZhang The i...map to toggle paste while inserting. The paste? shows the status of paste mode. This is not needed in the i-map, as I have showmode set.
    – Ralf
    Mar 30 '19 at 5:46
  • @Ralf I think i'm spoiled by plugins.
    – dedowsdi
    Mar 30 '19 at 8:41

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.