VS Code

my IDE of choice

2020 started using.

30 Jun 2022 starting note.

Snippets

https://code.visualstudio.com/docs/editor/userdefinedsnippets

Code > Preferences > Configure User Snippets then choose the .json relevant to the language for which those snippets need to be available.

Variables

The following variables can be used:

Variable Name Description
TM_SELECTED_TEXT The currently selected text or the empty string
TM_CURRENT_LINE The contents of the current line
TM_CURRENT_WORD The contents of the word under cursor or the empty string
TM_LINE_INDEX The zero-index based line number
TM_LINE_NUMBER The one-index based line number
TM_FILENAME The filename of the current document
TM_FILENAME_BASE The filename of the current document without its extensions
TM_DIRECTORY The directory of the current document
TM_FILEPATH The full file path of the current document
RELATIVE_FILEPATH The relative (to the opened workspace or folder) file path
CLIPBOARD The contents of your clipboard
WORKSPACE_NAME The name of the opened workspace or folder
WORKSPACE_FOLDER The path of the opened workspace or folder
CURSOR_INDEX The zero-index based cursor number
CURSOR_NUMBER The one-index based cursor number

ex with TM_FILENAME_BASE:

"<img class=\"$1screenshot\" src=\"{static}../../images/$TM_FILENAME_BASE/$CLIPBOARD.jpg\" alt=\"$CLIPBOARD\"/>  ",

outputs:

<img class="screenshot" src="{static}../../images/vs-code/vs-code-shortcuts.jpg" alt="vs-code-shortcuts"/>  

For inserting the current date and time:

Variable Name Description
CURRENT_YEAR The current year
CURRENT_YEAR_SHORT The current year's last two digits
CURRENT_MONTH The month as two digits (example '02')
CURRENT_MONTH_NAME The full name of the month (example 'July')
CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul')
CURRENT_DATE The day of the month as two digits (example '08')
CURRENT_DAY_NAME The name of day (example 'Monday')
CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon')
CURRENT_HOUR The current hour in 24-hour clock format
CURRENT_MINUTE The current minute as two digits
CURRENT_SECOND The current second as two digits
CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch

For inserting random values:

Variable Name Description
RANDOM 6 random Base-10 digits
RANDOM_HEX 6 random Base-16 digits

| UUID | A Version 4 UUID |

Extensions

05 Jul 2022

Current extensions:

app_vs-code-extensions-jul22.jpg

Review:

Display newline characters in your code

02 Dec 2022

Markdown Formatter

➤ use Shift Option F to format .md file.

Keyboard Shortcuts

Default

vs-code-shortcuts

Best way though, instead of searching the web, is to simply open the Keyboard Shorcuts settings (using the shortcut Cmd + K then Cmd + S 😁 ) and search for the desired action.

keyboard-shortcuts-settings

here I was looking for the shortcut to switch editors (ie tabs) with "next editor" and found Cmd + Shift + ] for it in the results list.

Other useful ones

shortcut action
Ctrl + W Open the Switch Windows command
Cmd + Shift + ] Open (ie switch to) Next Editor
Alt + ⬆︎ Move line up
Alt + left click Position the cursor at different places, manually

Also, in Go To (Cmd + P), you can type : (ie @:) to categorise symbols by type, starting with functions.

Text navigation

Check keyboard shortcuts in Cmd + K then Cmd + S and search for "cursor".

Main ones:
- end of line: Ctrl + E
- beginning of line: Ctrl + A
- end of word: Ctrl + Option + right arrow
- beginning of word: Ctrl + Option + left arrow

Basic navigation:
- Move cursor to the beginning of the line:
- Move cursor to the end of the line: Ctrl E
- Move cursor to the beginning of the document: Ctrl+Home (Windows/Linux) or Command+Home (Mac)
- Move cursor to the end of the document: Ctrl+End (Windows/Linux) or Command+End (Mac)

Word-level navigation:
- Move cursor one word to the left/right: Option+Left Arrow/Option+Right Arrow

Page-level navigation:
- Scroll up/down: Command+Up Arrow / Command+Down Arrow

Bottom select: Cmd + Shift + ⬇︎

resources

Settings

File is at ~/Library/Application Support/Code/User/settings.json.

For customising active tab:

"workbench.colorCustomizations": {
    "tab.activeBackground": "#2f5f53", 
},

Tips

remove images from search results when using Command + P

Visual Studio Code's Command + P (Quick Open) feature is designed to search for files within your workspace, not specifically for images. However, if you want to exclude certain file types (e.g., images) from the search results, you can modify the settings to filter them out.

In Settings:

vs-code/vs-code-search-exclude.jpg

I added these patterns:

**/*.jpg
**/*.jpeg
**/*.png
**/*.svg
**/*.gif

Resources

06 Dec 2023

links

social