Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim copy and replace text

Tags:

vim

copy-paste

Lets say that i have this text:

$test = 'lorem';
$test2= 'ipsum';

and I want to copy lorem and paste into ipsum. I tried to do yi' on lorem and then went on ipsum and did ci' but that replaced my pastebin with ipsum. and my previous copy was lost.

like image 245
Gabriel Solomon Avatar asked Mar 06 '09 15:03

Gabriel Solomon


People also ask

How do you replace words in Vim?

In Vim, you can find and replace text using the :substitute ( :s ) command. To run commands in Vim, you must be in normal mode, the default mode when starting the editor. To go back to normal mode from any other mode, just press the 'Esc' key.

How do I replace a word with yanked in Vim?

Move the cursor to another word (say "third"). Repeat the operation (change word and replace it with "first"). Move the cursor to another word and press . to repeat the change. Yank inner text (text containing cursor which is in quotes).

How do I replace a word in vi editor globally?

The % is a shortcut that tells vi to search all lines of the file for search_string and change it to replacement_string . The global ( g ) flag at the end of the command tells vi to continue searching for other occurrences of search_string . To confirm each replacement, add the confirm ( c ) flag after the global flag.

How do I copy text from Vim?

In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard.


1 Answers

yi' on lorem, move to i of ipsum, vep?

like image 55
chaos Avatar answered Nov 01 '22 11:11

chaos