How do I replace text in a selection?

2019-03-07 12:48发布

I've just started using Sublime Text 2, coming from emacs.

I have a region of text selected. Within that region, I'd like to replace all text instances of '0' with '255'.

How do I do this kind of text replacement?

11条回答
Bombasti
2楼-- · 2019-03-07 13:10

I know this has been answered many times, and all are correct, but I though I would add another:

Similar to the Ctrl - D method to select individual occurrences of the current selection, you can select all occurrences in the file with Alt+F3 when using Windows or Linux (CMD+CTRL+G in Mac world).

This is helpful for mass-changes.

查看更多
来,给爷笑一个
3楼-- · 2019-03-07 13:13

This frustrated the heck out of me, and none of the above answers really got me what I wanted. I finally found the answer I was looking for, on a mac if you do + option + F it will bring up a Find-Replace bar at the bottom of your editor which is local to the file you have open.

There is an icon option which when hovered over says "In Selection" that you can select to find and replace within a selection. I've pointed to the correct icon in the screenshot below.

enter image description here

Hit replace all, and voila, all instances of '0' will be replaced with '255'.

Note: this feature is ONLY available when you use + option + F.

It does NOT appear when you use + shift + F.

Note: this will replace all instances of '0' with '255'. If you wanted to replace 0 (without the quotes) with 255, then just put 0 (without quotes) and 255 in the Find What: and Replace With: fields respectively.

Note:

option key is also labeled as the alt key.

key is also labeled as the command key.

查看更多
来,给爷笑一个
4楼-- · 2019-03-07 13:15

Some of the answers here haven't really helped.

People are showing you how to find stuff, but now how to replace it.

I just had a look, and it looks like it's Ctrl+H for replace, then you get the find dialog as well as a replace dialog. This worked for me.

查看更多
一纸荒年 Trace。
5楼-- · 2019-03-07 13:25

ST2 has a feature for changing multiple selections at once.

  1. Double click the first instance of 0 that you want to change.
  2. Press the key for Find->Quick Add Next* to select the next instance of 0, and repeat until you've selected all the instances of 0 that you want to change.
    If this method selects an instance that you want to skip, press the key for Find->Quick Skip Next.
  3. Verify that the multiple highlighted fields are what you want to replace. Next, type in '255' and it should modify all of the selected instances simultaneously.

*Look at the Find menu on the menu bar to find the correct shortcut key for your system. For vanilla Windows, the menu tells you that Find->Quick Add Next is Ctrl+D and Find->Quick Skip Next is Ctrl+K,Ctrl+D.

查看更多
做个烂人
6楼-- · 2019-03-07 13:26

First, select the portion of the text containing the bits you want to change. On Windows (sorry) it's Ctrl + H or Find > Replace... This opens up the Find/Replace boxes at the bottom of the file. Enter your details then click Replace All (or Ctrl + Alt + Enter)

查看更多
看我几分像从前
7楼-- · 2019-03-07 13:26

Windows
1- Find: CTRL + F
2- Select-in: Alt + Enter

Now you can change all the selection in one shot like "seen-on-tv" ST homepage Spot.

Credit goes to : https://superuser.com/a/921806/342825

查看更多
登录 后发表回答