Haiyuan Zhang
Haiyuan Zhang

Reputation: 42752

how can I do the paste in vim without troubled by indent issue

aaa
        bbb
        ccc
ddd

When I using copy the above lines from a file and pasted by "right click the mouse and select paste option and left click the mouse" into a file under edit by Vim in the insert mode, I get the following:

aa
        bbb
                ccc
                ddd

I think it is due to some indent related settings in Vim.

Upvotes: 3

Views: 1015

Answers (6)

Andrés Hazard
Andrés Hazard

Reputation: 43

I have this on my .vimrc

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

You can use F5 to active the paste toggle and F5 to disable it.

Upvotes: 0

Alex.Zhang
Alex.Zhang

Reputation: 133

You can use :set paste and :set nopaste to toggle paste mode.

In addition, you can use key combinations to make it easier. Update your .vimrc config file:

let mapleader = "," "map leader to do extra combination.

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

Now when you can input ,pp to toggle paste mode on and off.

Upvotes: 0

Brian
Brian

Reputation: 15706

:set paste before pasting, then :set nopaste afterward to restore normal behavior.

Upvotes: 0

John3136
John3136

Reputation: 29266

Or just put vim into insert mode (press a or i) before you "right click the mouse and select past option and left click the mouse".

The first "a" in your paste is doing that and so not being included in the paste.

Upvotes: -2

David Pope
David Pope

Reputation: 6587

Before pasting, do :set paste. Afterward, do :set nopaste. See :help paste for more details.

Upvotes: 8

Andrew Marshall
Andrew Marshall

Reputation: 96904

This is because what you're doing is essentially like just typing the text into Vim character-by-character, and so it does everything it would normally do.

The * register represents the system clipboard, so you can paste from it like so:

"*p

This assumes your Vim is compiled with support for the system clipboard. You can test if it is by running vim --version | grep '+clipboard'.

Upvotes: 3

Related Questions