shin
shin

Reputation: 32721

How to delete all dots and number after dots with Vim

UPDATED

I scan a page and I have many lines with dots and numbers like the followings. Due to scan, the numbers are very irregular. There can be space(s) or dot between numbers.

g. Problem-Solving Strategy: Use Logical Reasoning .........................1. 3
h. Problem-Solving Strategy: Use a Venn Diagram ..............................1 4
i. Review: Problem-Solving Strategies .................................... 1 5
(and more lines)
a. Scientific Notation ............................................... 2. 1 -22
b. Variable Expressions .................................................. .24 -26
c. Functions ....................................................................3.  8-39

Now I want to edit this without dots and numbers after dots like this with vim.

g. Problem-Solving Strategy: Use Logical Reasoning
h. Problem-Solving Strategy: Use a Venn Diagram 
i. Review: Problem-Solving Strategies 
(and more lines)
a. Scientific Notation 
b. Variable Expressions 
c. Functions

At the moment I am doing it line by line and it takes a lot of time.

I am wondering if there is a better and shorter way to do it with VIM.

Upvotes: 0

Views: 578

Answers (2)

romainl
romainl

Reputation: 196586

I would do it like this:

:%norm / \ze\.\.^MD<CR>      ^M is Ctrl+V followed by Enter

Or with a substitution:

:%s/\zs \.\..*<CR>

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172600

You can remove the trailing stuff with a simple substitution, anchored to the end of the line ($), that replaces optional whitespace, dots, optional whitespace, and a number with nothing:

:%s/\s*\.\+\s*\d\+$//

Because the number stuff seems to be pretty irregular (based on your example), we need to be more lenient at the end. For this, I've used a collection with named groups; [:space:] is equivalent to \s (but can be used in a [...] collection).

:%s/\s*\.\+[-.[:digit:][:space:]]\+$/

Upvotes: 2

Related Questions