Skip to content

Instantly share code, notes, and snippets.

@lunule
Last active March 2, 2026 00:13
Show Gist options
  • Select an option

  • Save lunule/c29b020a33042c2d60f9c0b76c410bbb to your computer and use it in GitHub Desktop.

Select an option

Save lunule/c29b020a33042c2d60f9c0b76c410bbb to your computer and use it in GitHub Desktop.
[Sublime Text - Tips 'N' Tricks] #sublime #sublime-text #text #search #replace #tips #collection #regex

0. Remove empty lines

  • Find & Replace, make sure the regex option is active
  • Find: ^\s*\n
  • Replace: `` (blank)

1. Exclude folders from Find in Files

  • Typical examples: exclude the node_modules folder:

    D:\LIBRARIES\GITRepos\muhammad-ali-center, -*/node_modules/*
    
    D:\LIBRARIES\GITRepos\parcel, -*/node_modules/*, -*/assets/build/*, -*/vendor/*
    
  • Another example of what you can do here: (@here https://forum.sublimetext.com/t/how-turn-off-subfolders-in-find-in-files/18795/12#post_11)

    /home/user/Desktop/Largish_Folder/Final Project, *.cpp, *.hpp, *.tpp, -*/fileHelp Test Zone/*, -*/threadTest/*, -*/Other/*, -*/Test for LC/*, -*/FileHander 2nd Test/*
    

    This one is including in the search all .cpp, .hpp and .tpp, and exluding specific subfolders.


2. Create shorthand to Sort Lines

This solution is super-awesome, because it also incorporates the Permute Lines feature's unique option/argument!!!

2.1 Create a new macro in the Packages/default folder. Details:

  • macro file name: "Sort Unique Lines.sublime-macro" (yes, you can leave/use the spaces between the title's words)
  • full path: "C:\Users\Holden Caulfield\AppData\Roaming\Sublime Text 2\Packages\Default\Sort Unique Lines.sublime-macro"
  • macro content:
[
	{
		"command": "sort_lines",
		"args": { "case_sensitive": false }
	},
	{
		"command": "permute_lines",
		"args": { "operation": "unique" }
	}
]

2.2 Open the Preferences/Key Bindings - User file, and add the following lines to as last binding config:

{
    "keys": [ "ctrl+alt+s" ],
    "command": "run_macro_file",
    "args": { "file": "Packages/default/Sort Unique Lines.sublime-macro" }
}  

FYKI - Pay attention NOT TO USE COMMAS after last parentheses/brackets - this is not a JS array, this is, practically, JSON - the only difference compared to 100% JSON is that here, comments are allowed; but the COMMA-RELATED STRICT RULES ARE THE SAME!!!


3. Select each line's start

  • select the full text
  • click CTRL + SHIFT + L
  • now click the left arrow

FYKI - Same thing for the "all line's end" scenario, only you need to use the right arrow there instead of left.


4. How to paste text to end of every line?

  • Select all the lines you want to prefix or suffix
  • Go to menu Selection -> Split into Lines (Ctrl + Shift + L)

This allows you to edit multiple lines at once. Now you can add *Quotes (") or anything * at start and end of each lines.


5. Set default indentation

If you want it for all files, go to Preferences -> Settings - Default or Preferences -> Settings - User.

Syntax Specific settings can limit it to just the languages you choose. To limit this configuration to PHP files, first open up a PHP file in the editor, and then go to Preferences -> Settings - Syntax Specific. This should open a settings window named PHP.sublime-settings.

In both cases, the configuration should look like this:

{
  "tab_size": 2,
  "translate_tabs_to_spaces": true,
  "detect_indentation": false
}

FYKI: detect_indentation is recommended to kept with the false value - without detect_indentation turned off some experience very strange behavior (it's detecting the indentation incorrectly and using that instead of what has been specified in the settings file).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment