TransWikia.com

tabs after pastetoggle instead of spaces

Vi and Vim Asked by aldwinaldwin on August 31, 2021

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.

One Answer

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.

Answered by Ralf on August 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP