28

As the title suggests, I would like to find out if there's a way to prevent ST2 from opening binary files when I click on them. For example when I click on an image, there's no point displaying the hex representation inside the text editor.

One additional note: I'm not interested in hiding binary files from the sidebar.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Panos Spiliotis
  • 801
  • 1
  • 9
  • 18

4 Answers4

53

Files containing null bytes are opened as hexadecimal by default In your User or Default Settings file:

"enable_hexadecimal_encoding": false
Steven Teo
  • 687
  • 6
  • 6
10

Unfortunately I'm not aware of a way to disabled previewing of specific formats, but if you want to avoid accidental clicks on enormous binary files that may slow down the editor you could disable all previewing from sidebar clicks.

In your User or Default Settings file(s):

"preview_on_click": false
Terry
  • 14,099
  • 9
  • 56
  • 84
8

I have similar situation like you. I dont want sublime open editor for binary like jpg png files. Instead open system default application is more reasonable.

  1. Create one Build. Refer to Sublime Text 2 keyboard shortcut to open file in specified browser (e.g. Chrome) It will both open default application and hex editor.
  2. Plugin OpenDefaultApplication https://github.com/SublimeText/OpenDefaultApplication It will have context right click menu OpenInDefaultApplication. But It will both open default application and hex editor as well
  3. Plugin: Non Text Files https://packagecontrol.io/packages/Non%20Text%20Files Add config in the user setting

    "binary_file_patterns": ["*.JPG","*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],
    "prevent_bin_preview": true,
    "open_externally_patterns": [
       "*.JPG",
       "*.jpg",
       "*.jpeg",
       "*.JPEG",
       "*.png",
        "*.PGN",
       "*.gif",
        "*.GIF",
        "*.zip",
        "*.ZIP",
        "*.pdf",
        "*.PDF"
    ]
    

I choose the third way, it's quite suitable for me. It will open jpg file in system default application and quickly close the edit mode automatically.

Community
  • 1
  • 1
Victor Choy
  • 4,006
  • 28
  • 35
0

For Sublime Text 3

file_exclude_patterns Setting

If your binary files have a file extension, then yes.

In your Sublime Settings you can use this setting to prevent you from seeing the files in the left project folders:

"file_exclude_patterns":
[
    "*.db",
    "*.dll",
    "*.ds_store",
    "*.egg",
    "*.enc",
    "*.eot",
    "*.exe",
    "*.ko",
    "*.otf",
    "*.pdb",
    "*.pdf",
    "*.pgn",
    "*.plist",
    "*.psd",
    "*.pxm",
    "*.pyc",
    "*.rdb",
    "*.sqlite",
    "*.sublime-workspace",
    "*.ttf",
    "*.woff",
    "*.woff2",
    "*.zip",
],

Just modify this to your needs, and then you will not see this in your project folders in Sublime.

Toggle

Maybe you just want to turn it off or on for the current file?

Try Sublime Command Palette using CTRL OR Command + Shift + P

and type:

HexViewer: Toggle Hex View

and press Enter or Return then the file will switch between HEX and TEXT.

Extra

If you don't want any-file to be converted to HEX then please use @steven-teo's answer.

If you want to learn more about the HEX Viewer you can see the Code Here & Documentation Here.

**Note: Keys vary for the Sublime Command Palette more info on that.

JayRizzo
  • 3,234
  • 3
  • 33
  • 49