search
HomeDevelopment ToolsVSCodeIt's worth understanding some vscode cursor operations to make development as smooth as silk!

This article will take you to talk about the cursor operations in vscode. This article will only cover the cursor operations that are most closely related to us, so let’s get started!

It's worth understanding some vscode cursor operations to make development as smooth as silk!

We have only one goal, let us shout our slogan: Make development as smooth as silk! Most of the examples in the article are based on the mac version, because I am a mac, but there is no need to worry about the win version. If you want to break the formation, keep it in mind: command is the ctrl key.

vscode Tips - Cursor Operation

We use the arrow keys every day to operate the cursor. In fact, we also use many of its techniques subconsciously in muscle memory in our daily life. For example, by holding down the cmd key, you can go to the beginning and end of the line, but it is difficult to summarize, and it feels like it is blinding you. Let me give you a breakthrough point: granularity. In our daily use, the left and right arrow keys only have one character, that is, granularity is a character. If we think of the end of a word or sentence, it will be very troublesome; this sentence actually marks our focus: granularity; then, how to operate What about cursor granularity? [Recommended learning: "vscode tutorial"]

Horizontal direction

Combined with the direction keys

##WordsoptionctrllinecmdJust use home/endCode blockcmd shift \Ctrl shift \
Granularity mac win

vertical direction

GranularitymacwinHead of text/End of textCmd up and down arrow keysCtrl Home/End keyMove the current line of code up/downOption up and down arrow keys

Note: [Move the current line up/down] is not a cursor but a code block operation (Because the cursor can be operated directly with the arrow keys), but it is very suitable to be placed here, so that it can match the horizontal direction; horizontally: line-cmd word-option; vertically document-cmd line-option;

Other cursor operations

MeaningmacwinUndo cursor processingCmd UCtrl U

Extension: [Select] operation only needs to add [shift]; [Delete] operation granularity is the same as cursor operation, in the opposite direction, add fn ( For example, all the content before the cursor in the deleted line is [cmd delete] and the content after the cursor is [cmd fn delete 】)

Cursor operation example

Cursor movement for words

Think To move the cursor directly to the entire word, that is, before or after function, you only need to press the Option (Ctrl key on Windows) and the left arrow key.

Its worth understanding some vscode cursor operations to make development as smooth as silk!

Move the cursor to the beginning or end of the line

Hold down the Cmd left arrow key (on Windows Home key), you can move the cursor to the first column of this line

Its worth understanding some vscode cursor operations to make development as smooth as silk!

Move the cursor to the first or last line of the document

Press Cmd and the up and down arrow keys (Ctrl Home/End key on Windows)

Its worth understanding some vscode cursor operations to make development as smooth as silk!

Code Block movement

Cmd Shift \ (Ctrl Shift \ on Windows), you can jump between the pair of curly braces.

Its worth understanding some vscode cursor operations to make development as smooth as silk!

Move current line up/down

Its worth understanding some vscode cursor operations to make development as smooth as silk!

Other cursor operations

Undo cursor processing

Its worth understanding some vscode cursor operations to make development as smooth as silk!

##Multiple cursor operations

So far, we have learned about single cursor movement, selection (actually moving plus the

shift key), deletion (selecting plus delete) and other operations, then, if we need What about operating multiple places at once? At this time we need to come to the advanced use of cursor operations, multi-cursor operations.

Regarding this topic, the key point is actually how to create multiple cursors at the required location, because after creation, the operation is consistent with the single cursor.

Basic operation - mouse creation of multiple cursors

Hold down "Option" on the keyboard (Alt on Windows), and then click to create a new Just click the cursor.

Its worth understanding some vscode cursor operations to make development as smooth as silk!

But obviously, this method is generally applicable but inconvenient. Every time we create a cursor, we need to find the position and click it. According to the 82 principle, we can use shortcut keys To implement the common 20% operations, the following mainly introduces three common scenarios.

Efficiency improvement operations

Processing scenesShortcut keysDetailed explanationSame elementCmd DSelect the element, then press the shortcut key, vscode will select the next one an identical element and create the cursor; press again to create, and so on. Up and down processingCmd Option down arrow keyCreate a cursor below the current cursor. Select multi-line processingOption Shift iSelect multiple lines of content, then press the shortcut key, vscode creates a Cursor

Extensions about cursor operations

Other cursor operations

Meaningmacwin##Undo cursor processing

Select and delete Lenovo

The [Select] operation only needs to add a [shift]; the [Delete] operation granularity is the same as the cursor operation, and vice versa Just add fn for the direction (for example, if you delete the line, all the content before the cursor is [cmd delete] and the content after the cursor is [cmd#] ##fn delete])

At this point, we understand the basic design concept of vscode itself for cursor operations.

Customized shortcut keys

But what if we are not used to it? Naturally, vscode is not so rigid. It supports customizing shortcut keys for behaviors, which is what we call commands. Here is one point that confused me before, that is, what we call creating cursor, moving, etc. corresponds to vscode. In fact, it is an embedded command. Only after you understand this can you customize it. I didn't understand it at first, so the question I kept thinking about was: how should I translate what I want to do.

Three steps: Find the place where

keyboard Shorycut is defined, find the corresponding operation, and bind the shortcut key to the operation.

Eg: Bind the operation of [Select all contents in brackets]Cmd Shift ]Shortcut key as an example

Find the definition Where keyboard Shorycut

Its worth understanding some vscode cursor operations to make development as smooth as silk!

find the corresponding operation

Its worth understanding some vscode cursor operations to make development as smooth as silk!

Bind shortcut keys for operations

Double-click-》Press the shortcut key that needs to be bound-》Press Enter to confirm (if you press the wrong key, just don’t press Enter)

More here In other words, the essence of shortcut keys is the binding of behaviors and specific keys [in specific scenarios]. They are described through JSON in vscode. We can view it by executing

>Open Keyboard Shortcuts(JSON) , if we need to implement an advanced shortcut key, we will need this knowledge.

Its worth understanding some vscode cursor operations to make development as smooth as silk!

Cmd U Ctrl U
##AttributesCommand##WhenUnder what circumstances does this shortcut Key bindings can take effectKeyShortcut keysThe definition of when
Meaning Remarks
Command value


requires more attention. All values ​​can be viewed in the

document. For advanced writing, VS Code Several basic operators are also supported. In this way we can write relatively complex conditional statements.

!
    Negate. For example, if we want to bind a shortcut key when the cursor is not in the editor, then we can use !editorFocus, use ! Negate.
  • ==
  • is equal to. In addition to being boolean, the when condition value can also be a string. For example,
  • resourceExtname corresponds to the suffix name of the opened file. If we want to bind a shortcut key to the js file, we can use resourceExtname == .js. &&
  • And operator. We can combine multiple conditional values. For example, if I want the cursor to be in the editor and the editor is editing a js file, then I can use
  • editorFocus && resourceExtname == .js. =~
  • Regular expression. Still using the above example, if I want to detect whether the file suffix is ​​js, I can also write
  • resourceExtname =~ /js/ and judge it through regular expressions.
  • Summary
Finally, let me sum it up in a jingle, I hope it will be helpful to you: Consider granularity when moving, use shortcut keys for multiple ones, self-binding is required for customization, and remember the shift key for operations.

For more knowledge about VSCode, please visit:

vscode Basic Tutorial

!

The above is the detailed content of It's worth understanding some vscode cursor operations to make development as smooth as silk!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:掘金社区. If there is any infringement, please contact admin@php.cn delete
How to format json with vscodeHow to format json with vscodeApr 16, 2025 am 07:54 AM

The ways to format JSON in VS Code are: 1. Use shortcut keys (Windows/Linux: Ctrl Shift I; macOS: Cmd Shift I); 2. Go through the menu ("Edit" > "Format Document"); 3. Install JSON formatter extensions (such as Prettier); 4. Format manually (use shortcut keys to indent/extract blocks or add braces and semicolons); 5. Use external tools (such as JSONLint and JSON Formatter).

How to compile vscodeHow to compile vscodeApr 16, 2025 am 07:51 AM

Compiling code in VSCode is divided into 5 steps: Install the C extension; create the "main.cpp" file in the project folder; configure the compiler (such as MinGW); compile the code with the shortcut key ("Ctrl Shift B") or the "Build" button; run the compiled program with the shortcut key ("F5") or the "Run" button.

How to install vscodeHow to install vscodeApr 16, 2025 am 07:48 AM

To install Visual Studio Code, please follow the following steps: Visit the official website https://code.visualstudio.com/; download the installer according to the operating system; run the installer; accept the license agreement and select the installation path; VSCode will start automatically after the installation is completed.

How to enlarge fonts with vscodeHow to enlarge fonts with vscodeApr 16, 2025 am 07:45 AM

The methods to enlarge fonts in Visual Studio Code are: open the settings panel (Ctrl, or Cmd,). Search and adjust "Font Size". Choose "Font Family" with the right size. Install or select a theme that provides the right size. Use keyboard shortcuts (Ctrl or Cmd) to enlarge the font.

How to connect to a remote server with vscodeHow to connect to a remote server with vscodeApr 16, 2025 am 07:42 AM

How to connect to a remote server through VSCode? Install Remote - SSH Extended Configuration SSH Create a Connection in VSCode Enter connection information: Host, Username, Port, SSH Key Double-click the saved connection in Remote Explorer

How to run vue with vscodeHow to run vue with vscodeApr 16, 2025 am 07:39 AM

Running a Vue project in VSCode requires the following steps: 1. Install the Vue CLI; 2. Create a Vue project; 3. Switch to the project directory; 4. Install project dependencies; 5. Run the development server; 6. Open the browser to visit http://localhost:8080.

How to compare two files with vscodeHow to compare two files with vscodeApr 16, 2025 am 07:36 AM

How to compare files in VSCode: 1. Open two files, 2. Enable the Differences view (View menu), 3. View the Differences (Add green, delete red, modify purple), 4. Use the arrow keys to navigate, 5. Accept or reject changes. Additional features include merging changes, copying changes, viewing details, and editing differences.

How to run js code with vscodeHow to run js code with vscodeApr 16, 2025 am 07:33 AM

How to run JS code in VSCode? Create .js files and write code; install Node.js and npm; install Debugger for Chrome; open the debug console; select Chrome; add debug configuration; set debug scripts; run code; debug code (optional).

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor