Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you paste multiple tabbed lines into Vi? [closed]

Tags:

I want to paste something I have cut from my desktop into a file open in Vi.

But if I paste the tabs embed on top of each other across the page.

I think it is some sort of visual mode change but can't find the command.

like image 303
tristanbailey Avatar asked Sep 12 '08 11:09

tristanbailey


People also ask

How do I indent multiple lines in vi editor?

press v for visual mode. use up / down arrow to highlight text. press = to indent all the lines you highlighted.

How do you copy and paste lines in vi?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.


2 Answers

If you're using plain vi:

You probably have autoindent on. To turn it off while pasting:

<Esc> :set noai  <paste all you want>  <Esc> :set ai 

I have in my .exrc the following shortcuts:

map ^P :set noai^M map ^N :set ai^M 

Note that these have to be the actual control characters - insert them using Ctrl-V Ctrl-P and so on.

If you're using vim:

Use the paste option. In addition to disabling autoindent it will also set other options such as textwidth and wrapmargin to paste-friendly defaults:

<Esc> :set paste  <paste all you want>  <Esc> :set nopaste 

You can also set a key to toggle the paste mode. My .vimrc has the following line:

set pastetoggle=<C-P> " Ctrl-P toggles paste mode 
like image 131
Antti Kissaniemi Avatar answered Nov 04 '22 16:11

Antti Kissaniemi


If you are using VIM, you can use "*p (i.e. double quotes, asterisk, letter p).

like image 43
JayG Avatar answered Nov 04 '22 14:11

JayG