VS Code: відмінності між версіями

Матеріал з Wiki.Zina
Перейти до навігації Перейти до пошуку
>Zina
 
 
Рядок 92: Рядок 92:
<source lang="json">
<source lang="json">
"editor.linkedEditing": true,
"editor.linkedEditing": true,
</source>
=== Показывать pinned tabs отдельной строкой ===
<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> — '''Preferences: open settings (JSON)''' — в <code>settings.json</code> добавить строку:
<source lang="json">
"workbench.editor.pinnedTabsOnSeparateRow": true,
</source>
</source>



Поточна версія на 11:58, 26 серпня 2025

Visual Studio Code

Быстрые клавши

[ред. | ред. код]

См. также:

Интерфейс

Показать/спрятать SideBar Ctrl+B
Переключиться на SideBar и обратно Ctrl+0 (#Key Bindings)
Переключиться на SideBar с фокусом на активном файле Shift+Alt+L (#Key Bindings)
Свернуть папки в SideBar [ (#Key Bindings)
Показать/спрятать Terminal Ctrl+`
Открыть внешний Terminal Ctrl+Shift+C

Переходы

Перейти к переменной F12
Перейти к парной скобке Ctrl+Shift+\
Перейти к парному тегу Ctrl+Shift+5 (#Key Bindings)
Previous edit point Alt+< (Emmet commands and keybindings)
Next edit point Alt+> (Emmet commands and keybindings)

Выделение текста

Smart Select Shift+Alt+→
Previous item Ctrl+Alt+< (Emmet commands and keybindings)
Next item Ctrl+Alt+> (Emmet commands and keybindings)
Выделить тег (или текст внутри тега) Ctrl+Shift+A (Emmet commands and keybindings)

HTML

Обернуть тэгом Alt+E W (Emmet commands and keybindings)
Alt+W (#Key Bindings)
Переименовать тег Alt+E R (Emmet commands and keybindings)
Удалить тег Alt+E D (Emmet commands and keybindings)
Обернуть в <strong> Ctrl+Alt+S (#Key Bindings)
Вставить <br> Ctrl+Shift+Enter (#Key Bindings)
Вставить &nbsp; Ctrl+Shift+Space (#Key Bindings)
Выстроить тег в одну строку (Merge) Alt+E M (Emmet commands and keybindings)
Закомментировать Ctrl+/
Toggle comment (HTML only) Alt+E Alt+/(Emmet commands and keybindings)

Прочее

Переключение слов: true/false, yes/no, on/off, 0/1,
left/right, top/bottom, up/down, width/height
Alt+R (Toggler)
Дублировать строку Ctrl+Alt+Shift+↑, ↓ на NumPad
Переименовать переменную F2
Посчитать математическое
выражение (demo)
Alt+E = (Emmet commands and keybindings)

Настройки

[ред. | ред. код]

Чтобы работало автодополнение HTML тэгов в файлах .twig: Settings → поиск Emmet. Найти секцию Emmet: Include languages и добавить:

  • Item : twig
  • Value : html

Auto Rename Tag

[ред. | ред. код]

Ctrl+Shift+P — Preferences: open settings (JSON) — в settings.json добавить строку:

"editor.linkedEditing": true,

Показывать pinned tabs отдельной строкой

[ред. | ред. код]

Ctrl+Shift+P — Preferences: open settings (JSON) — в settings.json добавить строку:

"workbench.editor.pinnedTabsOnSeparateRow": true,

Key Bindings

[ред. | ред. код]

Ctrl+Shift+P — найти команду Preferences: Open Keyboard Shortcuts (JSON) (это файл keybindings.json)

Focus toggle between editor and sidebar

[ред. | ред. код]

Ctrl+0
Shift+Alt+L

  // Unbind unconditional default
  { "key": "ctrl+0", "command": "-workbench.action.focusSideBar" },
  // to ←
  { "key": "ctrl+0", "command": "workbench.action.focusSideBar", "when": "!sideBarFocus" },
  // from →
  { "key": "ctrl+0", "command": "workbench.action.focusActiveEditorGroup", "when": "sideBarFocus" },
  // Show current file in sidebar explorer with focus
  { "key": "shift+alt+l", "command": "workbench.files.action.focusFilesExplorer", "when": "editorTextFocus" },

Collapse Explorer Folders

[ред. | ред. код]

[

  {
    "key": "[",
    "command": "workbench.files.action.collapseExplorerFolders",
    "when": "explorerViewletFocus && !inputFocus"
  }

Перейти к парному тегу

[ред. | ред. код]

Ctrl+Shift+5

  // Перейти к парному тегу
  {
    "key": "ctrl+shift+5",
    "command": "editor.emmet.action.matchTag",
    "when": "editorTextFocus && !inDebugRepl"
  },

Wrap selected text within a HTML tag

[ред. | ред. код]

Alt+W

  // Wrap selected text within a HTML tag by Alt+W
  {
    "key": "alt+w",
    "command": "editor.emmet.action.wrapWithAbbreviation",
    "when": "editorHasSelection && editorTextFocus"
  },

Wrap strong

[ред. | ред. код]

Ctrl+Alt+S

  // Wrap <strong> by Ctrl+Alt+S
  {
    "key": "ctrl+alt+s",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
      "langId": "html",
      "name": "<strong>"
    }
  },

Insert <br>

[ред. | ред. код]

Ctrl+Shift+Enter

  // Insert <br> by Ctrl+Shift+Enter
  { 
    "key": "ctrl+shift+enter", 
    "command": "type",
    "args": { 
      "text": "<br>"
    },
    "when": "editorTextFocus"
  },

Insert nbsp;

[ред. | ред. код]

Ctrl+Shift+Space

  // Insert &nbsp; by Ctrl+Shift+Space
  { "key": "ctrl+shift+space", "command": "type",   "args": { "text": "&nbsp;" },  "when": "editorTextFocus" },

Сниппеты

[ред. | ред. код]

Ctrl+Shift+P — snippet — Preferences: Configure User Snippets — выбрать подходящий расширению файл и добавить в него код из генератора сниппетов:

В поле Tab trigger... вписать буквосочетание-префикс, по набору которого и нажатию Tab будет вставляться сниппет.

Чтобы префикс срабатывал при ошибочном наборе на кириллице, нужно вписать его в виде массива:

"prefix": ["date", "вфеу"],

Тэг <а href...> по букве ф

[ред. | ред. код]
  "a href кириллицей": {
    "prefix": ["ф"],
    "body": [
      "<a href=\"${1}\">${1}</a>"
    ],
    "description": "a href"
  },

Тэг <strong> по клавише ы

[ред. | ред. код]

Сначала в Ctrl+Shift+P — snippet — Preferences: Configure User Snippets вставить снипепет для вставки тэга по нажатию клавиши ы:

"<strong>": {
  "prefix": "ы",
  "body": [
    "<strong>${TM_SELECTED_TEXT}${1}</strong>"
  ],
  "description": "Wrap <strong>"
}

Затем в User > keybinding.json добавить вызов этого сниппета по хоткею Ctrl+Alt+s:

{
    "key": "ctrl+alt+s",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
      "langId": "html",
      "name": "<strong>"
    }
  }

Replace Rules

[ред. | ред. код]

Экстеншен Replace Rules позволяет задать несколько правил поиска и замены и выполнить их за один раз.

Форматирование литературного текста, удаление Sizzy Online Custom Elements

[ред. | ред. код]

Ctrl+Shift+P — Preferences: open settings (JSON) — в settings.json добавляем:

    "replacerules.rules": {
        "Строки текста обернуть в тег <p>": {
          "find": "^(?![\\s\\n<])(.*)$",
          "replace": "<p>$1</p>"
        },
        "Абзацы, заголовки, списки - с новой строки": {
            "find": "([^\r\n])(<p>|<h[1-5]>|<br>|<li>|<div)",
            "replace": "$1\n$2"
        },
        "Убрать переводы строк перед заголовками": {
            "find": "(<p>\\s*|<br>\\s*)(<h\\d>)",
            "replace": "$2"
        },
        "Remove trailing spaces": {
            "find": "[ \t]+$",
            "replace": ""
        },
        "Close p tags": {
            "find": "<p>(.+[^(</p>\\s*)])\\n",
            "replace": "<p>$1</p>\n"
        },
        "Дефис в длинное тире": {
            "find": "([  >,.;…\n\r\t])[-–]([  …\n\t])",
            "replace": "$1—$2"
        },
        "Кавычки": {
            //"find": "(\\s|\\n|\\t)&quot;((.|\n)+?)&quot;",
            "find": "(\\s|\\n|\\t|>| |\\()(&quot;|&laquo;)((.|\\n)+?[^\\s\\n\\t]*)(&quot;|&raquo;)",
            "replace": "$1«$3»"
        },
        "Троеточия": {
            "find": "\\.\\.\\.",
            "replace": "…"
        },
        "H3 to H2": {
            "find": "<h3>((.|\n)+?)</h3>",
            "replace": "<h2>$1</h2>"
        },
        "H4 to H3": {
            "find": "<h4>((.|\n)+?)</h4>",
            "replace": "<h3>$1</h3>"
        },
        "Sizzy - remove Online Custom Elements": {
            "find": "sizzy-\\w+-\\d *",
            "replace": ""
        }
    },
    "replacerules.rulesets": {
        "Форматирование литературного текста": {
            "rules": [
                "Remove trailing spaces",
                "Дефис в длинное тире",
                "Кавычки",
                "Троеточия"
            ]
        }
    },

Ctrl+Shift+P — Preferences: Open Keyboard Shortcuts (JSON) — в keybiddings.json добавляем:

  { // Replace Rules — Форматирование литературного текста
    "key": "ctrl+shift+]",
    "command": "replacerules.runRuleset",
    "when": "editorTextFocus && !editorReadonly",
    "args": {
        "rulesetName": "Форматирование литературного текста"
    }
  }

Вызывать команду или комбинацией Ctrl+Alt+R и выбором отдельных правил, или настроенной комбинацией Ctrl+Shift+]

Другие плагины

[ред. | ред. код]

См. также

[ред. | ред. код]