tag:blogger.com,1999:blog-6637736252081011583.post617974127595991399..comments2023-10-23T11:13:47.199-07:00Comments on Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Delete Lines Matching KeywordTravis Whittonhttp://www.blogger.com/profile/14592647486468034166noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-6637736252081011583.post-24480462224926172202011-03-03T12:22:38.233-08:002011-03-03T12:22:38.233-08:00why doesn't write work?
I do the following:
...why doesn't write work?<br /><br />I do the following:<br /><br />:g/foo/w newfile<br /><br />and I get all the lines in the current file.fitz1jhttps://www.blogger.com/profile/00780269638050463297noreply@blogger.comtag:blogger.com,1999:blog-6637736252081011583.post-17280038643853823022008-12-29T12:21:00.000-08:002008-12-29T12:21:00.000-08:00Alternately, delete all lines NOT matching keyword...Alternately, delete all lines NOT matching keyword:<BR/>:g!/foo/d<BR/><BR/>CaseyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6637736252081011583.post-88553931588817122562008-09-24T16:20:00.000-07:002008-09-24T16:20:00.000-07:00Thanks a lot..works like a charm!Thanks a lot..works like a charm!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6637736252081011583.post-44408894937708018782008-03-13T06:46:00.000-07:002008-03-13T06:46:00.000-07:00Awesome tip! Thanks Chris.Awesome tip! Thanks Chris.Travis Whittonhttps://www.blogger.com/profile/14592647486468034166noreply@blogger.comtag:blogger.com,1999:blog-6637736252081011583.post-40854838764946118642008-03-09T20:54:00.000-07:002008-03-09T20:54:00.000-07:00i'm really learning to love the global command. my...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.<BR/><BR/><B>Example:</B><BR/>Insert a blank comment on the line before every instance of a match in a file:<BR/><BR/>:%g/.../normal O//<BR/><BR/>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.<BR/><BR/><B><I>Important note when using :global</I></B> -<BR/>: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.Anonymoushttps://www.blogger.com/profile/04871226658814740333noreply@blogger.com