{"id":474,"date":"2025-05-20T19:40:20","date_gmt":"2025-05-21T02:40:20","guid":{"rendered":"https:\/\/catbradley.io\/?p=474"},"modified":"2025-05-20T19:40:20","modified_gmt":"2025-05-21T02:40:20","slug":"use-multi-cursor-in-vs-code-to-edit-multiple-lines-simultaneously","status":"publish","type":"post","link":"https:\/\/catbradley.io\/?p=474","title":{"rendered":"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/itsfoss.com\/content\/images\/2025\/04\/multi-line-cursor-in-vscode.webp\" alt=\"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously\" \/><\/p>\n<p>Working with code often involves repetition, changing variable names, updating values, tweaking class names, or adding the same prefix across several lines. <\/p>\n<p>If you find yourself making the same changes again and again, line by line, then multi-cursor editing in Visual Studio Code can help simplify that process.<\/p>\n<p>In this part of our ongoing VS Code series, we\u2019ll take a closer look at this feature and how it can make everyday tasks quicker and more manageable.<\/p>\n<h2>Why use multiple cursors?<\/h2>\n<p>Multi-cursor editing lets you place more than one cursor in your file so you can edit several lines at once. <\/p>\n<p>Instead of jumping between lines or writing the same change repeatedly, you can type once and apply that change across multiple places.<\/p>\n<p>Here are a few common situations where it comes in handy:<\/p>\n<ul>\n<li>Renaming a variable or function in multiple places.<\/li>\n<li>Adding or removing the same snippet of code across several lines.<\/li>\n<li>Editing repeated structures (like object keys, class names, or attribute values).<\/li>\n<li>Commenting out a bunch of lines quickly.<\/li>\n<\/ul>\n<p>Once you start using it, you\u2019ll notice it helps reduce small repetitive tasks and keeps your focus on the code itself.<\/p>\n<h2>Placing multiple cursors: mouse and keyboard<\/h2>\n<p>There are two main ways to place multiple cursors in VS Code using the mouse or keyboard shortcuts. <\/p>\n<p>Let\u2019s start with the mouse-based approach, which is more visual and straightforward for beginners. <\/p>\n<p>Then, we\u2019ll move on to keyboard shortcuts, which are faster and more efficient once you\u2019re comfortable.<\/p>\n<h3>Method 1: Using the mouse<\/h3>\n<p>To place cursors manually using your mouse:<\/p>\n<p>Hold down <code>Alt<\/code> (Windows\/Linux) or Option (Mac), then click anywhere you want to insert a new cursor.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/itsfoss.com\/content\/images\/2025\/04\/multiple-cursor-with-mouse.gif\" class=\"kg-image\" alt=\"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously\" loading=\"lazy\" width=\"800\" height=\"310\" \/><\/figure>\n<p>Each click places a new blinking cursor. You can now type, delete, or paste, and the change will reflect at all cursor positions simultaneously.<\/p>\n<p>To cancel all active cursors and return to a single one, press Esc.<\/p>\n<p>This method is handy for quick edits where the lines aren\u2019t aligned or when you want more control over cursor placement.<\/p>\n<h3>Method 2: Using keyboard shortcuts<\/h3>\n<p>The mouse method is a good starting point, but learning keyboard shortcuts can save more time in the long run. <\/p>\n<p>Below are a few keyboard-driven techniques to add and manage multiple cursors efficiently.<\/p>\n<h4>Add Cursors Vertically in a Column<\/h4>\n<p>When you want to add cursors above or below the current line to edit a block of similar lines (like inserting or deleting the same code at the beginning of each line), use this shortcut:<\/p>\n<p><code>Ctrl+ Alt + Up\/Down<\/code> arrow keys.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/itsfoss.com\/content\/images\/2025\/04\/ctrl-alt-down-arrow-for-multiple-cursor.gif\" class=\"kg-image\" alt=\"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously\" loading=\"lazy\" width=\"484\" height=\"124\" \/><\/figure>\n<p>This aligns cursors in a vertical column, making it easier to apply the same action to adjacent lines.<\/p>\n<h4>Select the next occurrence of the current word<\/h4>\n<p>To select and edit repeated words one by one such as variable names or function calls, place your cursor on the word and use: <code>Ctrl + D<\/code> <\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/itsfoss.com\/content\/images\/2025\/04\/ctrl-d-for-next-occurence-of-word.gif\" class=\"kg-image\" alt=\"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously\" loading=\"lazy\" width=\"800\" height=\"755\" \/><\/figure>\n<p>Each press selects the next matching word and adds a cursor to it. You can press it repeatedly to continue selecting further matches.<\/p>\n<h4>Select all occurrences of a word in the file<\/h4>\n<p>If you want to update every instance of a word across the file at once, for example, replacing a class name or a repeated property, use: <code>Ctrl + Shift + L<\/code><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/itsfoss.com\/content\/images\/2025\/04\/ctrl-shift-l-for-same-occurence.gif\" class=\"kg-image\" alt=\"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously\" loading=\"lazy\" width=\"726\" height=\"210\" \/><\/figure>\n<p>This selects all matching words and places a cursor at each one. It\u2019s powerful, but use with care in large files to avoid unintentional edits.<\/p>\n<h4>Editing with multiple cursors<\/h4>\n<p>Once your cursors are in place, editing works just like usual:<\/p>\n<ul>\n<li>Type to insert text across all cursors.<\/li>\n<li>Use Backspace or Delete to remove characters.<\/li>\n<li>Paste snippets \u2014 they get applied to each cursor position.<\/li>\n<li>Standard commands like cut, copy, undo, and redo all function as expected.<\/li>\n<\/ul>\n<p>Just keep an eye on alignment. If cursors are placed unevenly across lines, your edits might not be consistent.<\/p>\n<p>Since you seem to be interested, check out some of the <a href=\"https:\/\/itsfoss.com\/vs-code-shortcuts\/\">other VS Code keyboard shortcuts<\/a>.<\/p>\n<figure class=\"kg-card kg-bookmark-card\"><a class=\"kg-bookmark-container\" href=\"https:\/\/itsfoss.com\/vs-code-shortcuts\/\">\n<div class=\"kg-bookmark-content\">\n<div class=\"kg-bookmark-title\">15 Best VS Code Keyboard Shortcuts to Increase Productivity<\/div>\n<div class=\"kg-bookmark-description\">Do you want to be highly productive? Get familiar and memorize these VS Code keyboard shortcuts for Linux, Windows, and macOS.<\/div>\n<div class=\"kg-bookmark-metadata\"><img decoding=\"async\" class=\"kg-bookmark-icon\" src=\"https:\/\/itsfoss.com\/content\/images\/icon\/android-chrome-192x192-418.png\" alt=\"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously\" \/><span class=\"kg-bookmark-author\">It&#8217;s FOSS<\/span><span class=\"kg-bookmark-publisher\">Community<\/span><\/div>\n<\/div>\n<div class=\"kg-bookmark-thumbnail\"><img decoding=\"async\" src=\"https:\/\/itsfoss.com\/content\/images\/thumbnail\/vs-code-shortcuts-1.png\" alt=\"Use Multi-Cursor in VS Code to Edit Multiple Lines Simultaneously\" \/><\/div>\n<p><\/p><\/a><\/figure>\n<h2>Wrapping Up<\/h2>\n<p>Multi-cursor editing is one of those small but effective features in VS Code that can make repetitive tasks less of a chore. <\/p>\n<p>You don\u2019t need to learn all the shortcuts right away. Start simple, try placing cursors with <code>Ctrl + D<\/code> or selecting multiple lines vertically and build from there.<\/p>\n<p>As you become more comfortable, these techniques will become second nature and help you focus more on writing logic and less on repeating edits.<\/p>","protected":false},"excerpt":{"rendered":"<p>Working with code often involves repetition, changing variable names, updating values, tweaking class names, or adding the same prefix across several lines. If you find yourself making the same changes&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-474","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-rss"],"_links":{"self":[{"href":"https:\/\/catbradley.io\/index.php?rest_route=\/wp\/v2\/posts\/474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/catbradley.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/catbradley.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/catbradley.io\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/catbradley.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":0,"href":"https:\/\/catbradley.io\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"wp:attachment":[{"href":"https:\/\/catbradley.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/catbradley.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/catbradley.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}