LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-22-2011, 12:18 AM   #1
JosephS
Member
 
Registered: Jun 2007
Distribution: Debian Jessie, Bunsenlabs
Posts: 586

Rep: Reputation: 38
vim: question about regular expressions


I've been searching for information about regex and vim. I'm trying to do a couple of things: remove extra spaces between words, but not the spaces that I use for indenting at the front of a line; removing spaces in front of punctuation. I would appreciate if someone has info on this and a good tutorial for learning regex and vim.

Thanks
 
Old 09-22-2011, 12:24 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You could start here http://vimdoc.sourceforge.net/htmldoc/usr_10.html#10.2, but the entire vim docs are usually avail from within vim eg ':help' and in /usr/share/doc (or similar depending on distro).
See also this dedicated site http://vimregex.com/
 
Old 09-22-2011, 02:03 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hi,
Quote:
Originally Posted by JosephS View Post
...I'm trying to do a couple of things: remove extra spaces between words, but not the spaces that I use for indenting at the front of a line
Code:
:%s\(\w\+\)\s\+/\1 /g
will substitute all multiple whitespace with one Spacecharacter except at the beginning of a line.
Quote:
removing spaces in front of punctuation
Code:
:%s/\s\+\([.,;!]\)/\1/
will remove all space in front of punctuation.

Hope that helps.

Markus
 
Old 09-22-2011, 05:18 PM   #4
JosephS
Member
 
Registered: Jun 2007
Distribution: Debian Jessie, Bunsenlabs
Posts: 586

Original Poster
Rep: Reputation: 38
Thanks for the help. The code helped. I will also look at the tutorials.
 
  


Reply



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
[SOLVED] More question about regular expressions ppmoore Programming 4 11-25-2010 09:37 AM
Regular Expressions Wim Sturkenboom Programming 10 11-19-2009 01:21 AM
\{a,b\} regular expressions sycamorex Linux - General 10 10-18-2008 06:38 PM
Perl - Regular Expressions question... gliesian Programming 2 04-10-2008 07:19 PM
Regular expressions aromes Linux - General 1 10-15-2003 12:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:38 AM.

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