A blog dedicated to text editing and general exploration of computing knowledge
i'm really learning to love the global command. my favorite application is in conjunction with the 'normal' command. When an ordinary macro needs to be applied at numerous points in a single file, the :g command can be used to apply it or a similar sequence at multiple points.Example:Insert a blank comment on the line before every instance of a match in a file::%g/.../normal O//if the sequence you need to perform is complex, go ahead and make a macro, and to run it in the desired spots, do :%g/.../normal @q (assuming q is the macro register). This will execute the q macro starting at any lines which match.Important note when using :global -:global will execute the given Ex command at any lines in the file that match the given pattern. it does NOT put the cursor at the start of the given match! this messed me up big-time at first, especially with :%g/.../normal... commands.
Awesome tip! Thanks Chris.
Thanks a lot..works like a charm!
Alternately, delete all lines NOT matching keyword::g!/foo/dCasey
why doesn't write work?I do the following::g/foo/w newfileand I get all the lines in the current file.
Post a Comment