When I have at least two lines indented, sublime allows me to collapse the code:
However, when I only have a single line, I lose that ability:
Is there a configuration option to allow collapsing single indents?
I can't seem to find any.
Related
VS code automatically indents code for me, and this works great. But, VS code also wants to force new lines where they aren't needed when I'm copying text. I've tried to go through the beautification settings and other SO posts, but every toggle seems to either add/remove both the indenting and the new lines, whereas I want one and not the other. Any ideas on how I need to set things to get this to work?
Here's what I get when I paste a block of text:
Here's what I want to have happen:
When I'm editing HTML or CSS in Sublime Text 3 the lines auto-indent when I hit the [ENTER] key, which generally is very useful.
On occasion I find myself wanting to paste a line of markup which is already indented, and this results in double indentation.
Is there some other key combination along with the [ENTER] key that prevents the next line from auto-indenting and instead returns the curson to the very beginning of the line? Please note I don't want to turn off auto-indent on a global basis.
You can do it in various steps, using various keybindings, so you can simply record a macro and do it in one simple custom keybinding (tools > record macro).
Steps:
Press [Enter] to move to a new line.
Press [shift+home] to select until the beginning of line (spaces or tabs used to indent).
Press [backspace] to remove the selected indentation charaters
You're done. Stop recording and save the macro, then use a custom keybinding to do it in a single step.
I found in Windows that CTRL + SHIFT + V (rather than just CTRL + V) does a "paste and indent" whereby the indentation is corrected as necessary.
It's also possible to switch the default paste for paste as indent as per these instructions: https://gist.github.com/twosixcode/1988097
When I do a simple search/replace, without any regex, ST2 adds a newline to each replacement. What am I doing wrong?
Below, I want to change spaces to commas. It does so, but also throws in a newline.
If the text you would like to replace is somewhat limited in size, here is a workaround. It doesn't even incorporate the builtin replace feature, and it can be somewhat slow for large text files.
Hit CMD + F (or CTRL + F) to bring up the Find dialog on the bottom of the window. Enter whatever string you'd like into the text field. Click the "Find All" button, and you'll get multiple write positions into the file. You can write in two places at once! If you've done it correctly, you'll see not just one blinking vertical line (which usually indicates the position in the file that the read/write pointer is at), but multiple. You can then type as usual into the file, and it should add text in multiple places.
How do I list the lines that contains the matches from the "find" command ? ie., I would like to list all the matching lines in a separate window. Currently one can only goto next / previous 'find'.
Try 'Find in Files' (Cmd+Shift+F on a Mac, presumably Ctrl+Shift+F on a PC).
Search results will display in a new tab, and you can double-click any result to jump to that line in the matching file.
To search only open files, put <open files> in the Where field.
To show only the lines that matched without surrounding lines for context, toggle the 'Show Context' option (to the left of the 'Find All' panel).
1.Here is a reference: How can I filter a file for lines containing a string in Sublime Text 2?
Hit Ctrl+F(⌘+F) to "Find All" occurences;
Hit Ctrl+L to Expand All Selection to Line.
Then you can Ctrl+C(⌘+C) or Ctrl+Shift+K(⌃+⇧+K) to
copy/delete the lines.
2.There's now a plugin for filtering lines:
https://github.com/davidpeckham/FilterLines
It allows filtering and code folding based on strings or regular expressions.
I think the simplest way is just to search for the line like this -> ".*find_this_string.*" and make sure that regular expression is ticked. Then you can click "find all" (alt+enter) and just copy and paste all results to a new window.
I am using the "Find All" feature in Sublime Text and I want to see a few more lines back from the find results. I can't find a setting for this -- is there any way to do this?
To expand upon DarkWater's comment to your question:
Add new lines with a regex before and after your search string:
.*\n.*\n.*search_string.*\n.*\n.*
This will match 2 new lines before and after your search_string.
Make sure you enable regular expression searching in the find dialog. Also make sure that you escape any regex special characters in your search_string.
Are you using the Find in Files… command from the Find menu (SUPER + SHIFT + F)?
If so, there's an option in the find panel to see more lines than the result line alone -- the next to last button (there should be 5 option buttons in the find panel), which has a "Show Context" tooltip, should do the trick.
To expand on the solutions provided by #dasl and #zaboco
I found that this variation was more suitable.
Example:
(.*\n){0,2}.*search_string.*(\n.*){0,2}
This will match 0-2 new lines before/after your search_string. Adjust numbers as needed to provide more/less context, but always keep the 0 as the first number in the quantifier.
Again, make sure you enable regular expression searching in the find dialog.
(The original regexes required that 2 lines above/below are present in the files, and excluded some necessary files from the search results)