How can I make an insert in vim without indentation problems

aaa
        bbb
        ccc
ddd

      

When I use copies of the above lines from a file and pasted "right click and select paste option and left click" in a file running Vim in insert mode, I get this:

aa
        bbb
                ccc
                ddd

      

I think it has to do with some of the Vim fallback related settings.

+3


source to share


6 answers


Do before pasting :set paste

. Then do it :set nopaste

. For details see :help paste

.



+7


source


This is because what you are doing is essentially like you are typing into a personal Vim symbol, and therefore it does everything it normally does.

The register *

represents the system clipboard, so you can paste it like this:



"*p

      

This assumes that your Vim is compiled with system clipboard support. You can check if it works vim --version | grep '+clipboard'

.

+3


source


:set paste

before insertion, then :set nopaste

to restore normal behavior.

0


source


You can use :set paste

and :set nopaste

to switch to insert mode.

Alternatively, you can use keyboard shortcuts to make them easier. Update the .vimrc config file:

let mapleader = ","

"to make an additional combination.

map <leader>pp :setlocal paste!<cr>

Now that you can enter ,pp

to turn insert mode on and off.

0


source


I have this on my .vimrc

set pastetoggle=<f5> "for better pasting from clipboard

You can use F5 to activate the insert switch and F5 to disable it.

0


source


Or just put vim in insert mode (press a or i) before "right click and select the previous option and left click".

The first "a" in your paste does this and is therefore not included in the paste.

-2


source







All Articles