Sublime Text:選擇變量的所有實例並編輯變量名稱

本文翻譯自:Sublime Text: Select all instances of a variable and edit variable name

I'm new to Sublime, and I just discovered that if I select a variable (not just any string) in my code, all other instances of that variable get a stroke (white outline) around them: 我是Sublime的新手,我剛剛發現,如果我在代碼中選擇一個變量 (不僅僅是任何字符串),該變量的所有其他實例都會在它們周圍得到一個筆劃(白色輪廓):

在此輸入圖像描述

Is there a keyboard shortcut that will let me select all of those instances of the variable and edit them all at once? 是否有鍵盤快捷鍵可以讓我選擇變量的所有實例並一次編輯它們?


Things I've tried: 我試過的事情:

Using D , K , and U lets me select them one-by-one, but I have to manually exclude the non-variable string matches: 使用⌘d,⌘K⌘ü讓我一個接一個地選擇它們,但我必須手動排除非可變字符串匹配:

在此輸入圖像描述

And using Ctrl G simply selects all the string matches: 並用Ctrl⌘ 簡單地選擇所有的字符串匹配:

在此輸入圖像描述

Clearly, Sublime is able to differentiate between variable- and string-matches. 顯然,Sublime能夠區分變量匹配和字符串匹配。 Is there no way to select just the variable matches? 有沒有辦法只選擇變量匹配?


#1樓

參考:https://stackoom.com/question/18g41/Sublime-Text-選擇變量的所有實例並編輯變量名稱


#2樓

Despite much effort, I have not found a built-in or plugin-assisted way to do what you're trying to do. 儘管付出了很多努力,但我還沒有找到內置或插件輔助的方式來做你想做的事情。 I completely agree that it should be possible, as the program can distinguish foo from buffoon when you first highlight it, but no one seems to know a way of doing it. 我完全同意它應該是可能的,因爲當你第一次突出它時,程序可以區分foobuffoon ,但似乎沒有人知道這樣做的方法。


However, here are some useful key combos for selecting words in Sublime Text 2: 但是,這裏有一些有用的關鍵組合,用於在Sublime Text 2中選擇單詞:

Ctrl G - selects all occurrences of the current word ( Alt F3 on Windows/Linux) Ctrl⌘ -選擇當前單詞的所有出現(Alt鍵 F3在Windows / Linux的)

D - selects the next instance of the current word ( Ctrl D ) ⌘d -選擇當前字的下一個實例(Ctrl鍵 d)

  • K , D - skips the current instance and goes on to select the next one ( Ctrl K , Ctrl D ) ⌘K,⌘d -跳過當前實例並繼續選擇下一個( 按Ctrl K,Ctrl d)
  • U - "soft undo", moves back to the previous selection ( Ctrl U ) ⌘ü - “軟撤消”,移回到先前的選擇(Ctrl鍵 U)

E , H - uses the current selection as the "Find" field in Find and Replace ( Ctrl E , Ctrl H ) ⌘E,⌘^ h -使用當前的選擇作爲“查找”字段中查找和替換( 按Ctrl E, 按Ctrl 1H)


#3樓

1. PUT THE CURSOR IN THE VARIABLE 1.將光標放在變量中

⚠️ the key is to start with an empty selection ⚠️ – don't highlight; ⚠️關鍵是從一個空的選擇開始⚠️ - 不要突出顯示; just move your cursor there. 只需光標移動到那裏。

文本光標在變量上

2. PRESS D as needed. 2.按 ⌘d根據需要。 Not on a Mac? 不在Mac上? Ctrl D Ctrl D

突出顯示更多變量實例

🤔 didn't work? 🤔沒用 Try again, making sure you started with an empty selection . 再試一次,確保以空選擇開始。

🥕 more commands: 🥕 更多命令:

Find All: Ctrl G Selects all occurences at once. 查找所有 :Ctrl⌘ 選擇所有出現一次。 Not on a Mac? 不在Mac上? Alt F3 Alt F3

Undo Selection: U Steps backwards. 撤消選擇:⌘ü向後退。 Not on a Mac? 不在Mac上? Ctrl U Ctrl U.

Quick Skip Next: K D Skips the next occurence. 快速跳過,下一步:⌘ķ⌘d跳到下一個occurence。 Not on a Mac? 不在Mac上? Ctrl K Ctrl D Ctrl K Ctrl D.

📙 Sublime Docs 📙 崇高文件


h/t adzenith . h / t adzenith


#4樓

This worked for me. 對我有用。 Put your cursor at the beginning of the word you want to replace, then 將光標放在要替換的單詞的開頭,然後

Ctrl K , Ctrl D , Ctrl D ... Ctrl KCtrl DCtrl D ...

That should select as many instances of the word as you like, then you can just type the replacement. 這應該選擇任意數量的單詞實例,然後你可以輸入替換。


#5樓

I know the question is about Macs, but I got here searching the answer for Ubuntu, so I guess my answer could be useful to someone. 我知道這個問題是關於Mac的,但我在這裏搜索Ubuntu的答案,所以我想我的答案可能對某人有用。

Easy way to do it: Alt F3 . 簡單的方法: Alt F3


#6樓

魔術是,你必須從一個空的選擇開始,所以把你的光標放在想要多選的單詞/字符的前面,然後按Ctrl + D

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章