Reputation: 42832
I need to change
1 A
2 B
3 C
4 D
to
A
B
C
D
which means the decimal letter at the begining of every line and the following one or more blank should be deleted .
I'm only familiar with Reqex in Perl, so I try to use :%s/^\d\s+// to solve my problem, but it does not work. so does anyone of you can tell me how to get the work done using vim ?
thanks.
Upvotes: 3
Views: 2324
Reputation: 882166
One way is to use the global command with the search-and-replace command:
:g/^[0-9] */s//
It searches for the sequence:
^
[0-9]
<space>
<space>*
and then substitutes it for nothing (s//)
.
While you can do a similar thing with just the search-and-replace command on its own, it's useful to learn the global command since you can do all sorts of wonderful things with the lines selected (not just search and replace).
Upvotes: 3
Reputation: 36000
If it's in a column like that you could go into the column visual mode by pressing:
esc ctrl+q
then you can highlight what you want to delete
Upvotes: 0
Reputation: 994121
If you still want to use Perl for this, you can:
:%!perl -pe 's/^\d\s+//'
Vim will write the file to a temporary file, run the given Perl script on it, and reload the file into the edit buffer.
Upvotes: 1
Reputation: 3464
You can also use the Visual Block mode (Ctrl+V), then move down and to the right to highlight a block of characters and use 'x' to remove them. Depending on the layout of the line, that may in fact be quicker (and easier to remember).
Upvotes: 1
Reputation: 99354
You should use instead
:%s/^\d\s\+//
Being a text editor, vim tends to treat more characters literally‒as text‒when matching a pattern than perl. In the default mode, +
matches literal +
.
Of course, this is configurable. Try
:%s/\v^\d\s+//
and read the help file.
:help magic
Upvotes: 1