LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ctrl+v question in vim (https://www.linuxquestions.org/questions/linux-newbie-8/ctrl-v-question-in-vim-724789/)

visitnag 05-08-2009 10:26 PM

ctrl+v question in vim
 
Hi all,

I use vi extensively in editing print files or data files in RHEL4.
To cut and paste the data within vi editor i use
%!cut command to cut the data
or ctrl+v command to select some data, del to cut the data and p to paste where ever i need.
I found ctrl+v command is xlent tool in vi.


Now my problem is i want to insert some spaces, say 4 spaces 5th character using ctrl+v command. Is there any solution for it?

Presently to do this i am doing this process...

$vi myfile (it has 10 records)
:%s/^/ / (i am inserting 5 spaces at beginning of each record)
ctrl+v (going to visual mode)
5 l (selecting 5 spaces from beginning of the record)
10 j (selecting all the records from top)
del (deleting the selected spaces and it will be stored in the buffer)
here i moved the cursor to 5th character of first record and pressed p (small case) to insert the deleted spaces after 5th character of each record)

to avoid all this process is there any direct command to insert spaces within vi after a specific place?

Tinkster 05-09-2009 06:26 PM

Hmmm ... not a vi solution, but ...

Code:

sed -i 's/^(.....)/\1    /' my_file

And within vim :}
Code:

%s:^\(.....\):\1    :

Cheers,
Tink


All times are GMT -5. The time now is 03:42 PM.