How to select text between two double quotes in Sublime Text 3?

There are hotkeys , but there is only a method for selecting text between brackets or pair tags.

Changing the standard combination to your own does not help:

{ "keys": ["ctrl+shift+m"], "command": "expand_selection", "args": {"to": "brackets"} } 

  • 3
    Install the plugin github.com/kek/sublime-expand-selection-to-quotesPreferencesKey Bindings - User → add lines // Выделение текста между кавычками { "keys": ["ctrl+alt+'"], "command": "expand_selection_to_quotes" }, - Sasha Chernykh

2 answers 2

Try the Ctrl+Shift+Space combination - for some file formats, it highlights the text just inside the quotes. It works exactly in .scss , .html , as well as in .slim for tag attribute values.

  • one
    It would be nice to specify in which files. Recommend shortcut still would not advise. Your combination invokes a fairly broad command expand_selection {"to": "scope"} , which does not refer to quotes. With the help of the command, a lot of things are allocated, in particular, the text inside the most different brackets, quotes, or with them. Thank. - Sasha Chernykh
  • one
    You are right, the behavior of Ctrl+Shift+Space depends too much on context. Completed the answer file formats. Make a comment to the question in response - I will put a plus. - Vitaly Emelyantsev
  • HTML - i.imgur.com/coVWbAQ.gif - Sasha Chernykh Sept
  • one
    Vitaly Emelyantsev, answered deployed. I remember there were other comments in the discussion of your answer ... - Sasha Chernykh

0. Not recommended


1. Expand Selection to Scope

The selection tool built into Sublime Text, mentioned in the reply from Vitaly Emelyantsev.

1. Demonstration

In all examples, the text is highlighted not only between the quotes, but also the quotes themselves.

Expand Selection to Scope

2. Expected behavior

I could not find the documentation for the expand_selection with the argument {"to": "scope"} , but, based on the name and some characteristics of the behavior, all the text next to the carriage that has the same scope as the character in front of the carriage should stand out.

Scope in Sublime Text can be quite long, for example: text.html.basic source.js.embedded.html meta.delimiter.comma.js, text.html.basic source.js.embedded.html meta.function.declaration.js punctuation.separator.parameter.function.js . Expand Selection To Scope must first highlight text.html.basic source.js.embedded.html meta.delimiter.comma.js, text.html.basic source.js.embedded.html meta.function.declaration.js punctuation.separator.parameter.function.js , then, if there is such a scope near, text.html.basic source.js.embedded.html meta.delimiter.comma.js, text.html.basic source.js.embedded.html meta.function.declaration.js , then text.html.basic source.js.embedded.html meta.delimiter.comma.js, text.html.basic source.js.embedded.html , etc.

In the first example, the demo quotes in the syntax for Suricate have the same scope as the text between them; in the second, quotation marks are included in the comment, so the comment is highlighted, and not the text between quotes. This is the expected behavior.

The expand_selection command with the argument {"to": "scope"} should select text by scopes, not delimiters . Quotes in different syntaxes do not always have their own scopes, so when working with different syntaxes, it is better not to use it to select text between quotes.

3. Actual behavior

Judging by the last two selections on the demo, Expand Selection to Scope has bugs that are played on “clean” Sublime Text without plug-ins and user settings.

In the third and fourth examples, the idea should be allocated text between the quotes. In the third, expand_selection {"to": "scope"} highlights quotes in the built-in HTML script, and fourthly, PackageDev generally offers extremely irrelevant selections on the package syntax.


2. Keyboard Selection

1. Demonstration

Keyboard selection

2. Description

This plugin allows you to select text between different types of quotes, brackets and between different delimiters . Only, as can be seen from the GIF, it selects the text between the single quote - ' and double - " ; between the angle bracket - < and the square one - ] . The plugin does not match the types of quotes and brackets. Also, I don’t understand why in practice you may need a selection between various delimiters.

The rest of the plug-in commands are largely identical to the default Sublime Text commands, starting with Windows shortcuts Ctrl + Left / Right , Alt + Left / Right and Ctrl + Delete . In general, I do not see why Keyboard Selection can be useful.



1. Plugins specifically for highlighting text between quotes

The book "Sublime Text Power User" mentioned 2 plug-ins that answer this question: Select Quoted and Expand Selection To Quotes .


1. SelectQuoted

When pressing the shortcut - Ctrl + ' by default in Windows - the text between the quotes is highlighted first, then together with the quotes, → but then the selection stops.

Select quoted

The second command with the argument "args": {"inside": false} - Ctrl + Shift + ' by default in Windows - does not work for me at all .


2. Expand Selection To Quotes

Expand Selection To Quotes

When pressing the shortcut, Ctrl + ' by default in Windows - first selects the text between the quotes, then together with the quotes → then between the next quotes, etc.



2. Universal solutions

The text between certain delimiters is highlighted by Bracketeer . However, it is not included in this review, because from the descriptions of the plug-in's author - for example, Colinta - at least I find it difficult to personally understand what his plug-ins are for and how they work. If you want to try it, I warn you that nothing will function from the example given by the keymap .


1. ExpandRegion

1. Demonstration

ExpandRegion

2. Description

Smart text selection. And for any type of selection you need to press only one shortcut. The second one is used to return (undo) to the previous selection (see demo for Markdown). Supported syntaxes: HTML, Python, JavaScript, LaTeX.

To make a selection between quotes, you usually have to click on the hotkey 2 or more times. If you only need selections between "quotes", pay attention to solution 1.1, and better 1.2.

3. Configure Hot Keys

After installing the plug-in hotkeys have to ask yourself.

Windows users do not recommend copying the hot keys given in the description of the plugin. They conflict with the global shortcuts of Windows, which are problematic to disable without getting bugs. If you know how to unlink individual Windows hotkeys in order to use them in Sublime Text, share the solution with other users by answering the corresponding question in Super User .

How to use Suricate, and that means the code below, read here . Add the following lines to the User/Default.suricate-profile :

 // Expand Region "sasha_expand_region": { "caption": "Expand Region", "keys": ["super+y"], "call": "sublime.expand_region", }, // Expand Region Undo "sasha_expand_region_undo": { "caption": "Expand Region Undo", "keys": ["super+shift+y"], "call": "sublime.expand_region", "args": { "undo": true }, "context": [{ "key": "expand_region_soft_undo" }] }, 
  • context - a parameter meaning that the command is executed only in a specific context ; in this case, the selection will be canceled for the previous one, if the selection with the expand_region command expand_region . When we didn’t select Super + Y hotkeys, but pressed Super + Shift + Y , the letter y will be printed (unless you have other commands started by the combination Super + Shift + Y ).

4. Setting syntax

The selection with the expand_region command may not work or function poorly in separate syntaxes. For example, I didn't really care about the text for CSS in embedded HTML and in Markdown markup. To fix this, install the Edit PreferencesEdit Preferences: Edit Settings...ExpandRegionscope_selectors → paste the following code between the curly braces:

 "python": ["text.html.markdown.gfm"], "javascript": ["source.css"] 

text.html.markdown.gfm and source.css are syntax scopes, discussed in the next section. We try to select now. If it is still bad, instead of the python parameter we substitute javascript , html and latex ; instead of javascript , respectively python , html and latex . We stop at the option that highlights better.

5. Getting syntax scope

Each scope starts with a scope selector , the same syntax for all scope. For example, for Ruby syntax the default scope selector is source.rb , for C ++ it is source.c++ . I didn’t find it in the documentation or by Google search, so that the first scope selector has a specific exact name, let's call it “syntax scope” or “syntax scope”.

To get the syntax scope, press Ctrl + ' (typewritten reverse apostrophe, the symbol is located on the same key where Cyrillic "e") → enter the code in the opened field:

 view.scope_name(0).split()[0] 

Between the 'single quotes' we get a syntax scope, which can be useful where many.

6. Scope selectors for embedded languages

But in the second case, it would be better if the ExpandRegion allocation rules for JavaScript were applied only in inline CSS, but not the rest of the HTML document, because the javascript parser from ExpandRegion allows you to limit the effect of the javascript parameter from 2.1.4 to the scope scopes - ". "javascript": ["source.css"] means that if HTML somewhere contains scopes containing source.css in the name, ExpandRegion uses the javascript parameter, none — ExpandRegion highlights by default (assuming that no values ​​for other parameters).

Inline CSS and JavaScript scopes contain a scope selector, which is the “syntax scope” as if the file were opened in the embedded language syntax. That is: open the css-file and get the syntax scope - source.css . This source.css will also appear in scopes for inline CSS, starting with text.html.basic source.css.embedded.html . JavaScript has a syntax of source.js , the scope of inline JavaScript begins with text.html.basic source.js.embedded.html .



3. Additional links