Search code examples
sublimetext3

Delete all lines that don't contain a string in Sublime Text


So I have around 1000 lines of a text document and was wondering if it's possible to delete all lines on Sublime Text that don't contain a certain keyword, in my case: @


Solution

  • (Edited) Steps

    To delete all of the lines NOT containing occurrences of the keyword, use the following:

    Mac

    • Select your keyword (via double click, drag, etc, say @ in your case)
    • Command + Ctrl + G to select all occurrences
    • Hold Command and press Left Arrow
    • Hold Shift and Command and press Right Arrow
    • Cut with Command + X
    • Select All with Command + A
    • Backspace to delete all file contents
    • Paste with Command + V

    Windows

    • Select your keyword (say @ in your case)
    • Alt + F3 to select all occurrences
    • Hold Control and press Home
    • Hold Shift and press End
    • Cut with Ctrl + X
    • Select All with Ctrl + A
    • Backspace to delete all file contents
    • Paste with Ctrl + V