Is there any way to exclude folded code from search. When I search for text and that text appears to be in folded part of the code Sublime always unfolds that code snippet and its annoying. I could not find any settings regarding it.
You can make use of Sublime Text's "Find In Selection" feature - select all the unfolded regions, then open the find panel and perform your search with "in selection" toggled on.
Here is a plugin to do this:
import sublime
import sublime_plugin
class FindInUnfoldedTextCommand(sublime_plugin.TextCommand):
def run(self, edit):
folded_regions = self.view.folded_regions()
self.view.sel().clear()
self.view.sel().add_all(folded_regions)
self.view.run_command('invert_selection')
self.view.window().run_command('show_panel', { "panel": "find", "reverse": False, "in_selection": True })
To set this up:
from the Tools menu -> Developer -> New Plugin...
select the template plugin code and replace it with the above
save it, in the folder ST recommends (Packages/User/) with a name like find_in_unfolded_text.py - the filename isn't important, just the extension is.
Open the ST console (View menu -> Show Console)
Type/paste view.run_command('find_in_unfolded_text') Enter
Enter your search string
Violia! The folded text is ignored.
As an alternative to steps 4 and 5, you can add this new command to the menu, to the command palette, or create a keybinding for it.
Related
Sublime's "Find in Files" (CTRL-SHIFT-F or CMD-SHIFT-F) search results always have word wrap on by default. This is really annoying whenever a file containing a single huge line of text gets caught in the results, since:
wrapping the huge line takes ages and slows Sublime (and perhaps the whole computer) to a crawl, and
it makes the results difficult to read, since the wrapped line may take up screens and screens of space
It's possible to disable word-wrap from the "View" menu, but this change doesn't persist after closing the "Find Results" tab.
Is there a way to turn off word wrap for all Find Results?
Yes, with the Find Results tab active (ensure the "Use Buffer" option is enabled in the Find in Files panel to get a tab instead of an output panel when you perform the search), you can navigate to the Preferences -> Syntax Specific menu item and enter:
"word_wrap": false,
and save it. This will ensure that word wrap is always disabled for Find Results.
(You can always turn "Use Buffer" off again afterwards, it's only necessary for the menu item to open the correct syntax specific settings file, which is Packages/User/Find Results.sublime-settings.)
In default, Sublime opens the files without word wrapping. If you want to enable it, just go to Preferences > Settings and add "word_wrap": true to the Preferences.sublime-settings file
I use multiple windows of Sublime Text at once and would like to set each one to a different color theme. By default, changing the 'color preferences' changes them for all open windows.
Note it is possible to set the color scheme for a single window using a 'project settings' file (which suggests it is possible in general), but then the folder must be opened via the 'project settings' (and not just opening the folder).
How can I (programmatically or via the app) set a separate color scheme for a single SublimeText window?
You can do this with a small plugin. Create a new file with Python syntax, and the following contents:
import sublime_plugin
class ChangeWindowColorSchemeCommand(sublime_plugin.WindowCommand):
def change_scheme(self, scheme):
for view in self.window.views():
view.settings().set("color_scheme", scheme)
def run(self):
message = 'Enter path to color scheme:'
path = 'Packages/Color Scheme - Default/Monokai.tmTheme'
self.window.show_input_panel(message, path, self.change_scheme, None, None)
Save the file in your Packages/User folder (accessible via Preferences -> Browse Packages...) as change_window_color_scheme.py. You can trigger the plugin in two ways - from the console, and via a key binding. To run it via the console, open the console with Ctrl` and enter
window.run_command('change_window_color_scheme')
An input panel will open at the bottom of the window, where you can enter the path to the color scheme you want to use. The default value is Monokai, but you can change that in the plugin source if you want. Once you enter the path, hit Enter and all the files in the current window will use that color scheme.
To create a key binding, open Preferences -> Key Bindings-User and add the following:
{ "keys": ["ctrl+alt+shift+s"], "command": "change_window_color_scheme" }
If the file is empty, surround the above with square brackets [ ]. Save the file, and you can now trigger the plugin using CtrlAltShiftS, or whichever key combination works best for you.
When I select multiple lines of text in text editor Sublime Text 3, and try to find (Ctrl+F) an existing string in it, it fails. In fact, any highlighting I do somehow makes the string unfindable. For example, if I highlight all text in my file, and Ctrl+F an existing string, it is unable to find any matches. Only when the string I want to find is not highlighted can the string be searched.
I have the 'in selection', 'highlight matches', and 'wrap' flags on when highlighting. My user preferences are as follows:
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_size": 10,
"auto_find_in_selection": true,
"trim_trailing_white_space_on_save": true,
"ignored_packages":
[
"Vintage"
]
}
Any help will be appreciated. I have been trying to figure this out for an hour. Originally I had "auto_find_in_selection" set to false - I thought that was the culprit, but the problem persisted even after setting it to true.
go to settings-> user and add this line:
"find_selected_text": true
next time you select a text and press cmd+'f' it will be there as default search.
I had been fighting with this problem as well and for now (ST3 Build 3059) it still seems to be a bug. It seems like that the editor is not updating the selection for the search/replace bar while you have it open.
Here's a workaround:
1) Close the find/replace bar
2) Make your selection
3) Open search/replace bar and enter your search query
Hope this helps!
Is there a way to show the files that are open in SublimeText on the left of the screen, in a simple list?
I'd simply like the open files to appear on the left in a clickable way like this
file1.txt
file2.css
file3.htm
etc
is that possible?
Go to the "View" menu and choose "Side Bar", then "Show Open Files"
Right click on open file in editor...
Click on Reveal in Side Bar option, it will sync the open file with side bar
Ctrl+K+B will reveal the 'Side bar', with open file information. It is really worth using projects, they are really simple and provides for easy folder/project/file switching.
I also strongly reccomend going to preferences>Key Bindings - Default through the menus, and looking at all the functionality and keyboard shortcuts. Also 'preferences>Settings - Defualt`, shows you all of the configurable options (there are a lot). These are basically 'must dos' for getting full goodness out of Sublime.
If you want to do it only using keyboard, Command + Shift + P and select View: Toggle Open Files in Side Bar
Here's the key binding to run this shortcut using the keyboard:
[
{ "keys": ["super+shift+j"], "command": "reveal_in_side_bar" },
]
I can't find the Reformat button, I know I can use ctrl+k+d, but I wish to have also the toolbar with the button. can someone help me ?
You can use Edit > Advanced > Format Document and you can also move this as a button to any toolbar. Go to Tools > Customize > Commands, select Toolbar and push Add Command button. Then select Edit category and find Document Format.
Apparently VS2010 (maybe others) hide certain commands depending on the style you choose. I chose Web Dev (code) as my choice and the Document Format is not present to be added to a toolbar. But, if I change to C# Code (tools>Import/Export) then the Document Format command is right there in the Edit menu where others here have said it is.
I had to import the C# Dev layout, but unchecked colors and code formatting options (so it won't overwrite those). What section you must import to get the format document button, I don't know, I didn't experiment that deep.
Seems stupid MS chose to force us down specific paths for layout with no convenient way to get out of it.
If you can't find it in the Edit menu: you can also find it if you press CTRL + P and then type >format. The shortcut is SHIFT + ALT + F