Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to put regex matches to buffer but cannot get even simpler example y :.put myNewBuffer return msg [line] [put] [buffer] working ie how to put something to buffer?

So to regular expressions and ex

  1. what does (.,.)~ replaces the previous regular expression with the previous replacement pattern from a substitution mean? Some example helpful, source of the quote.
  2. please, give some examples how you use regexes with ex. For example, how can you buffer areas between starting word having h as the first character until the word ending to s character?
  3. What about if the last thing only on a line ie ending word is the word ending to s or the end of line $?
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The vim manual may be a better and more up-to-date than that old Ex manual. Most likely, you will be using ex that comes with vim on most modern Linux distributions. To get help in Vim use :help, to get help on a specific command like the Ex command ~, use :help :~. All Ex commands are preceded with a : in Vim. I think (.,.) is simply used to denote a range may be specified as in 2,8 to mean lines 2 through 8 or 1,$ ($ represents last line) for every line in a file. In Vim, typing :1,$~ means run the Ex command ~ on every line in the file.

  1. Vim say :~ is "Repeat last substitute with same substitute string but with last used search pattern." A substitution is normally written as :s/pattern/string/ This looks for a pattern on a line and replaces it with string. :~ repeats last substitute command, but uses the most recent search for pattern.

  2. Try this pattern: /\<h.*s\>

/ is used to start a search in Ex/Vim, \< means match start of word, h matches h, .* where . matches any single character and * repeats that zero or more times so .* means match zero or more characters. s matches s, \> matches end of word.

  1. Try this pattern /words\?$

$ means end of line when used in a pattern match, and \? means previous character is optional. This will match word or words at the end of a line.

share|improve this answer
    
Does this answer your questions? –  penguin359 Apr 2 '11 at 14:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.