On Mon, Jan 10, 2011 at 12:02:39PM -0500, jbw wrote:
> I'm trying to quickly change the date format in a downloaded csv file.
>
> Is there a way to change the following "12/27/2010" -->
> "2010/12/27" with one substitution command.
For this, I would do something like:
:s/\(\d\{2}\/\d\{2}\)\/\(\d\{4}\)/\2\/\1/
This creates backreferences for the MM/DD part and the YYYY part, and
then just transposes the two with a slash in between.
> The second substitution question I have is how to I perform a
> substitution but just add something to the pattern instead of
> completely replacing it. For the same csv file i want to add a newline
> before the pattern and then add some words after the pattern. I
> remember seeing how to do this before but can't find the instructions
> anymore
>
> for example.
>
> change the following
>
> one $100
>
> to this
>
> one $100 two three four
>
:s/\(\$100\)/\r\1 two three four/
In general, you create a backreference in a pattern by surrounding a
portion of the pattern with "\(" and "\)". Then you can refer to the
captured portions in your substitution with "\1", "\2", etc., numbered
in the order that they were specified. The references will be replaced
with whatever text matched the captured pattern.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php