How to match decimal letter and space in vim?

I need to change

1  A
2  B
3  C
4  D

to

A
B
C
D

which means that the decimal letter at the beginning of each line and the next one or more spaces should be removed.

I am only familiar with Reqex in Perl, so I am trying to use:% s / ^ \ d \ s + // to solve my problem, but this will not work. so can any of you tell me how to get the job done with vim?

thanks.

+3
source share
8 answers

Vim requires a backslash for +, so try

:%s/^\d\s\+//

+7
source

One way is to use a global command with a find and replace command:

:g/^[0-9]  */s//

He is looking for the sequence:

  • beginning of line ^
  • numeral [0-9]
  • space <space>
  • zero or more spaces <space>*

(s//).

" ", , ( ).

+3

:%s/^[0-9]  *//
+2

:%s/^\d\s\+//

, vim - - , perl. + +.

, .

:%s/\v^\d\s+//

.

:help magic
+1

Visual Block (Ctrl + V), , "x", . ( ).

+1

Perl , :

:%!perl -pe 's/^\d\s+//'

Vim will write the file to a temporary file, run the given Perl script and reload the file into the editing buffer.

+1
source

Reset the plus sign:

:%s/^\d\s\+//
0
source

If in a column like this, you can go into the visual mode of the column by clicking:

esc ctrl+q

then you can highlight what you want to delete

0
source

Source: https://habr.com/ru/post/1718146/


All Articles