[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Vi Editor: how to replace/delete ?

Posted on 2003-12-09
10
Medium Priority
?
1,611 Views
Last Modified: 2013-12-13
(1) Using VIM (Vi improved), how to delete "ABB_Hello" and "ABB_World" with just one command?

(2) How to remove those spaces in the beginning of Line 3 and 4 with just one command?


ABB_Hello Line 1;
ABB_World Line 2;
           Line 3;
           Line 4;
0
Comment
Question by:codenamecharlie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 8

Expert Comment

by:ssnkumar
ID: 9903192
(1) With a single command you cannot delete both the words! You will have to use delete word command twice.
(2) Goto the first column on each line and (in escape mode) enter "dw" (without quotes), the spaces will get deleted.
     If you know the number of spaces in the begining of those lines and if they are same, then you can remove them with a single command like this(editor prompt): Goto the ":" prompt inside vim. And give the following command there :g/           /s///g
This will work only if the number of spaces is exactly same!
0
 

Author Comment

by:codenamecharlie
ID: 9903201

VI is not smart enough to delete those words with just one single command? Disappointing.....

I thought Vi is powerful enough to do this... ?
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 9903221
Can you please show me any other editor which can do this!?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 3

Assisted Solution

by:scn
scn earned 80 total points
ID: 9903741

(1)
1,2s/ABB_[a-z]*//

(2)
3,4s/^[ ]*//
(there is a space inside the brackets)
0
 
LVL 3

Expert Comment

by:scn
ID: 9903789
I forgot the upper case letters:
(1)
1,2s/ABB_[a-zA-Z]*//
0
 
LVL 6

Expert Comment

by:durindil
ID: 9903984
To delete all occurrences of ABB_Hello:

:%s/ABB_Hello//g

To delete all occurrences of ABB_World:

:%s/ABB_World//g

To delete the spaces, you have to know how many spaces there are:

:%s/^     //g
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 120 total points
ID: 9904645
:g/^ABB_[^ ]*/s///
:3,4 s/^ *//

(second one already suggested by scn:)
0
 

Author Comment

by:codenamecharlie
ID: 9909010
OK, scn and ahoffmann's solutions work, other guys either misunderstand my question or just gimme wrong answers.

BTW, ahoffmann, may you pls explain to me the meaning of the command:

 :g/^ABB_[^ ]*/s///   ???

does 'g' mean "global" ???
what is [^ ]* ? is there a space after ^   ???
also, what is s///     ???   looks weird


Many thx!
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 9909631
Hi codenamecharlie,
The solution I gave for the 2nd Q works fine! Also, it is simple to understand than others!:-)

But I accept that the answers provided by scn and ahoffmann are better than the solution I gave:-))
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9911028
g is different from :g
:g means "process hole file"
s/// used in :g means that the matched pattern is replaxed by nothing:
  s//  -- matches pattern
    // -- replace by nothing
or more syntacticaly: s/pattern/replace/
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question