Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-08-2009, 11:26 PM   #1
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
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?
Old 05-09-2009, 07:26 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
Hmmm ... not a vi solution, but ...

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

And within vim :}
%s:^\(.....\):\1     :


Last edited by Tinkster; 05-09-2009 at 07:31 PM. Reason: vim snippet added


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 05:26 PM
Vim map CTRL-S indenting problem sadarax Linux - General 6 01-17-2008 02:52 PM
Ctrl-F on vim 6.0.152 display only half a screen powah Linux - Software 0 03-15-2007 02:01 PM
VIM - How to map Ctrl-F5? BiThian Linux - General 6 10-26-2006 05:15 PM
vpopmail with relay-ctrl question vanvan *BSD 1 12-12-2005 11:01 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration