How to remove the redundant encoding style for Sublime Text - sublimetext2

I am beginning to use Sublime Text and have fallen in love with it at the first sight. I really enjoy this powerful editor. I am en editor from China,so I think I only need UTF-8 and GBK encoding option,but each time when I want to save the file with the specified encoding option,there will be a lot of options ,such as
Western (Windows 1521)
Western (ISO 8859-1)
Western (ISO 8859-3)
...
Vietnamese (Windows 1258)
So my question is how do I remove the redundant encoding option for Sublime Text?

You can edit this section of ~/Library/Application Support/Sublime Text 2/Packages/Default/Main.sublime-menu and remove all of the encoding that you do not wish to appear in the Save with Encoding menu.
{
"caption": "Save with Encoding",
"children":
[
{ "caption": "UTF-8", "command": "save", "args": {"encoding": "utf-8" } },
{ "caption": "UTF-8 with BOM", "command": "save", "args": {"encoding": "utf-8 with bom" } },
{ "caption": "UTF-16 LE", "command": "save", "args": {"encoding": "utf-16 le" } },
{ "caption": "UTF-16 LE with BOM", "command": "save", "args": {"encoding": "utf-16 le with bom" } },
{ "caption": "UTF-16 BE", "command": "save", "args": {"encoding": "utf-16 be" } },
{ "caption": "UTF-16 BE with BOM", "command": "save", "args": {"encoding": "utf-16 be with bom" } },
{ "caption": "-" },
{ "caption": "Western (Windows 1252)", "command": "save", "args": {"encoding": "Western (Windows 1252)" } },
{ "caption": "Western (ISO 8859-1)", "command": "save", "args": {"encoding": "Western (ISO 8859-1)" } },
{ "caption": "Western (ISO 8859-3)", "command": "save", "args": {"encoding": "Western (ISO 8859-3)" } },
{ "caption": "Western (ISO 8859-15)", "command": "save", "args": {"encoding": "Western (ISO 8859-15)" } },
{ "caption": "Western (Mac Roman)", "command": "save", "args": {"encoding": "Western (Mac Roman)" } },
{ "caption": "DOS (CP 437)", "command": "save", "args": {"encoding": "DOS (CP 437)" } },
{ "caption": "Arabic (Windows 1256)", "command": "save", "args": {"encoding": "Arabic (Windows 1256)" } },
{ "caption": "Arabic (ISO 8859-6)", "command": "save", "args": {"encoding": "Arabic (ISO 8859-6)" } },
{ "caption": "Baltic (Windows 1257)", "command": "save", "args": {"encoding": "Baltic (Windows 1257)" } },
{ "caption": "Baltic (ISO 8859-4)", "command": "save", "args": {"encoding": "Baltic (ISO 8859-4)" } },
{ "caption": "Celtic (ISO 8859-14)", "command": "save", "args": {"encoding": "Celtic (ISO 8859-14)" } },
{ "caption": "Central European (Windows 1250)", "command": "save", "args": {"encoding": "Central European (Windows 1250)" } },
{ "caption": "Central European (ISO 8859-2)", "command": "save", "args": {"encoding": "Central European (ISO 8859-2)" } },
{ "caption": "Cyrillic (Windows 1251)", "command": "save", "args": {"encoding": "Cyrillic (Windows 1251)" } },
{ "caption": "Cyrillic (Windows 866)", "command": "save", "args": {"encoding": "Cyrillic (Windows 866)" } },
{ "caption": "Cyrillic (ISO 8859-5)", "command": "save", "args": {"encoding": "Cyrillic (ISO 8859-5)" } },
{ "caption": "Cyrillic (KOI8-R)", "command": "save", "args": {"encoding": "Cyrillic (KOI8-R)" } },
{ "caption": "Cyrillic (KOI8-U)", "command": "save", "args": {"encoding": "Cyrillic (KOI8-U)" } },
{ "caption": "Estonian (ISO 8859-13)", "command": "save", "args": {"encoding": "Estonian (ISO 8859-13)" } },
{ "caption": "Greek (Windows 1253)", "command": "save", "args": {"encoding": "Greek (Windows 1253)" } },
{ "caption": "Greek (ISO 8859-7)", "command": "save", "args": {"encoding": "Greek (ISO 8859-7)" } },
{ "caption": "Hebrew (Windows 1255)", "command": "save", "args": {"encoding": "Hebrew (Windows 1255)" } },
{ "caption": "Hebrew (ISO 8859-8)", "command": "save", "args": {"encoding": "Hebrew (ISO 8859-8)" } },
{ "caption": "Nordic (ISO 8859-10)", "command": "save", "args": {"encoding": "Nordic (ISO 8859-10)" } },
{ "caption": "Romanian (ISO 8859-16)", "command": "save", "args": {"encoding": "Romanian (ISO 8859-16)" } },
{ "caption": "Turkish (Windows 1254)", "command": "save", "args": {"encoding": "Turkish (Windows 1254)" } },
{ "caption": "Turkish (ISO 8859-9)", "command": "save", "args": {"encoding": "Turkish (ISO 8859-9)" } },
{ "caption": "Vietnamese (Windows 1258)", "command": "save", "args": {"encoding": "Vietnamese (Windows 1258)" } },
{ "caption": "-" },
{ "caption": "Hexadecimal", "command": "save", "args": {"encoding": "Hexadecimal" } }
]
},

For Sublime 3:
1. Go to Packages directory (in my case it is /opt/sublime_text/Packages)
3. Make a backup of Default.sublime-package
2. In Midnight Commander open archive Default.sublime-package (it is
simply a zip archive) by pressing Enter key
4. Copy Main.sublime-menu and Encoding.sublime-menu to temp directory
5. Edit copied files and remove unnecessary encodings
6. Copy changed files back to Default.sublime-package archive (i.e.
with archive management abilities of Midnight Commander)
7. Restart Sublime 3
p.s. sorry for my English as of it is not my native language

Related

How to increase number of recent files in Sublime Text 2?

Currently, Sublime 2 displays 8 items under File > Open Recent. I was hoping to double that to 16. I've searched and haven't found anything yet, except for increasing the Open Projects list, and this isn't the correct solution since I don't utilize projects. Can anyone offer any help?
As far as I'm aware, there is no setting that controls this. However by modifying the menu contents you can extend the number of items that are shown there.
To do this, you can follow these steps:
Install PackageResourceViewer if it is not already installed
From the Command Palette, select PackageResourceViewer: Open Resource
Select the Default package
Select the Main.sublime-menu resource
This opens up the file that controls what the menu contains. Near the top you will see something similar to this:
{
"caption": "Open Recent",
"mnemonic": "R",
"children":
[
{ "command": "reopen_last_file", "caption": "Reopen Closed File" },
{ "caption": "-" },
{ "command": "open_recent_file", "args": {"index": 0 } },
{ "command": "open_recent_file", "args": {"index": 1 } },
{ "command": "open_recent_file", "args": {"index": 2 } },
{ "command": "open_recent_file", "args": {"index": 3 } },
{ "command": "open_recent_file", "args": {"index": 4 } },
{ "command": "open_recent_file", "args": {"index": 5 } },
{ "command": "open_recent_file", "args": {"index": 6 } },
{ "command": "open_recent_file", "args": {"index": 7 } },
{ "caption": "-" },
{ "command": "open_recent_folder", "args": {"index": 0 } },
{ "command": "open_recent_folder", "args": {"index": 1 } },
{ "command": "open_recent_folder", "args": {"index": 2 } },
{ "command": "open_recent_folder", "args": {"index": 3 } },
{ "command": "open_recent_folder", "args": {"index": 4 } },
{ "command": "open_recent_folder", "args": {"index": 5 } },
{ "command": "open_recent_folder", "args": {"index": 6 } },
{ "command": "open_recent_folder", "args": {"index": 7 } },
{ "caption": "-" },
{ "command": "clear_recent_files", "caption": "Clear Items" }
]
},
From here you can extend the number of recent files out to 16 by adding additional lines for open_recent_file with indexes from 8 to 15 (since the indexes are 0 based), and then save the file.
As a side note, this will work for both Sublime Text 2 and Sublime Text 3.
In Sublime Text 3 this creates a package override for Default/Main.sublime-menu, which Sublime will use instead of the shipped version of the menu. If a future version of ST3 updates the main menu in any way, you won't be told and may potentially miss other menu changes and features. You can install OverrideAudit, which will warn you if that ever happens.
This is potentially also a worry for Sublime Text 2 (although OverrideAudit is ST3 only and cannot help you here), but it is unlikely that ST2 will be updated any further so this is probably of no real consequence.
I found you don't actually need to override the main menu;
just add your own menu which will appear in the end.
Create this new file (path for me in linux, in Sublime Text 3):
~/.config/sublime-text-3/Packages/User/Main.sublime-menu
In that file put something similar to OdatNurd previous answer;
(and I copy paste the same content into the files:
Context.sublime-menu
Side Bar.sublime-menu
to have the same submenu show up there)
I just made my own submenu from my own initials "elm" and put all stuff I personally use there with various "children" subtrees.
As a bonus, it will automatically show keyboard shortcuts to the same command behind it,
so I also use it as a reminder for actions that I don't use very often and forget the keyboard shortcut of.
Caveat: after posting this I realised I this works for Sublime Text 3, while the question was for Sublime Text 2. Perhaps someone can test if this also works for Sublime Text 2?
My file looks something like this:
(also added some more ideas (beside plenty recent files) for inspiration)
[
{
"caption" : "elm",
"mnemonic": "M",
"children": [
{
"caption": "Open Recent",
"mnemonic": "R",
"children": [
{ "command": "reopen_last_file", "caption": "Reopen Closed File" },
{ "caption": "-" },
{ "command": "open_recent_file", "args": {"index": 0 } },
{ "command": "open_recent_file", "args": {"index": 1 } },
// ... etc.
{ "command": "open_recent_file", "args": {"index": 29 } },
],
},
{
"caption": "Multi Line/Caret editing",
"children": [
{
"caption": "split_selection_into_lines",
"command": "split_selection_into_lines",
},
{
"caption": "Add caret above (select_lines)",
"command": "select_lines",
"args": {"forward": false},
},
{
"caption": "Add caret below (select_lines)",
"command": "select_lines",
"args": {"forward": true},
},
]
},
{
"caption": "Bookmarks",
"children": [
{
"caption": "toggle_bookmark",
"command": "toggle_bookmark",
},
{
"caption": "prev_bookmark",
"command": "prev_bookmark",
},
{
"caption": "next_bookmark",
"command": "next_bookmark",
},
]
},
{
"caption": "paste_from_history",
"command": "paste_from_history",
},
{
"caption": "Jump to matching bracket",
"command": "move_to", "args": {"to": "brackets"},
},
// ... etc. etc.
],
},
]
Bit off topic for just more recent files, but I thought this approach might also improve other usability and maintainability aspects at the same time :)

How to navigate in sublime through keypad keys?

Sublime 'alt+ numeric keys' work to switch between least 10 tabs opened
but same option doesn't work with keypad keys doesn't work.
does anybody have idea how to make it work?
thanks :)
Just add this to your User keybindings file:
{ "keys": ["alt+keypad1"], "command": "select_by_index", "args": { "index": 0 } },
{ "keys": ["alt+keypad2"], "command": "select_by_index", "args": { "index": 1 } },
{ "keys": ["alt+keypad3"], "command": "select_by_index", "args": { "index": 2 } },
{ "keys": ["alt+keypad4"], "command": "select_by_index", "args": { "index": 3 } },
{ "keys": ["alt+keypad5"], "command": "select_by_index", "args": { "index": 4 } },
{ "keys": ["alt+keypad6"], "command": "select_by_index", "args": { "index": 5 } },
{ "keys": ["alt+keypad7"], "command": "select_by_index", "args": { "index": 6 } },
{ "keys": ["alt+keypad8"], "command": "select_by_index", "args": { "index": 7 } },
{ "keys": ["alt+keypad9"], "command": "select_by_index", "args": { "index": 8 } },
{ "keys": ["alt+keypad0"], "command": "select_by_index", "args": { "index": 9 } },
open preferences keybinding and add this lines.
and now alt+keypad 0-9 keys work to swtich tabs
[{ "keys": ["alt+keypad1"], "command": "select_by_index", "args": { "index": 0 } },
{ "keys": ["alt+keypad2"], "command": "select_by_index", "args": { "index": 1 } },
{ "keys": ["alt+keypad3"], "command": "select_by_index", "args": { "index": 2 } },
{ "keys": ["alt+keypad4"], "command": "select_by_index", "args": { "index": 3 } },
{ "keys": ["alt+keypad5"], "command": "select_by_index", "args": { "index": 4 } },
{ "keys": ["alt+keypad6"], "command": "select_by_index", "args": { "index": 5 } },
{ "keys": ["alt+keypad7"], "command": "select_by_index", "args": { "index": 6 } },
{ "keys": ["alt+keypad8"], "command": "select_by_index", "args": { "index": 7 } },
{ "keys": ["alt+keypad9"], "command": "select_by_index", "args": { "index": 8 }}]

Move tab from one column to another in Sublime Text using only keys

Does anyone know this shortcut? I'm looking for it online, but I can't seem to find it
To move it is CTRLSHIFT1 to move to Group 0, CTRLSHIFT2 to Group 1, and so on - that's on Linux, Windows, and OSX.
Text buffers can also be moved to their neighbouring groups:
Linux, Windows:
CTRLk + CTRLSHIFTLEFT
CTRLk + CTRLSHIFTRIGHT
OSX
SUPERk + SUPERSHIFTLEFT
SUPERk + SUPERSHIFTRIGHT
Here's the whole group section of my Default (Linux).sublime-keymap - the Windows keys are all exactly the same, while the OSX keys are the same in the top section but differ in the bottom section, below where I have placed an explanatory comment.
// The keys BELOW are for Linux, Windows, and OSX.
{ "keys": ["ctrl+1"], "command": "focus_group", "args": { "group": 0 } },
{ "keys": ["ctrl+2"], "command": "focus_group", "args": { "group": 1 } },
{ "keys": ["ctrl+3"], "command": "focus_group", "args": { "group": 2 } },
{ "keys": ["ctrl+4"], "command": "focus_group", "args": { "group": 3 } },
{ "keys": ["ctrl+5"], "command": "focus_group", "args": { "group": 4 } },
{ "keys": ["ctrl+6"], "command": "focus_group", "args": { "group": 5 } },
{ "keys": ["ctrl+7"], "command": "focus_group", "args": { "group": 6 } },
{ "keys": ["ctrl+8"], "command": "focus_group", "args": { "group": 7 } },
{ "keys": ["ctrl+9"], "command": "focus_group", "args": { "group": 8 } },
{ "keys": ["ctrl+shift+1"], "command": "move_to_group", "args": { "group": 0 } },
{ "keys": ["ctrl+shift+2"], "command": "move_to_group", "args": { "group": 1 } },
{ "keys": ["ctrl+shift+3"], "command": "move_to_group", "args": { "group": 2 } },
{ "keys": ["ctrl+shift+4"], "command": "move_to_group", "args": { "group": 3 } },
{ "keys": ["ctrl+shift+5"], "command": "move_to_group", "args": { "group": 4 } },
{ "keys": ["ctrl+shift+6"], "command": "move_to_group", "args": { "group": 5 } },
{ "keys": ["ctrl+shift+7"], "command": "move_to_group", "args": { "group": 6 } },
{ "keys": ["ctrl+shift+8"], "command": "move_to_group", "args": { "group": 7 } },
{ "keys": ["ctrl+shift+9"], "command": "move_to_group", "args": { "group": 8 } },
{ "keys": ["ctrl+0"], "command": "focus_side_bar" },
// The keys BELOW are for Linux and Windows only.
//
// The OSX keys all use 'super' instead of 'ctrl'.
//
// e.g. In the top command use: ["super+k", "super+up"]
// e.g. In the bottom command use: ["super+k", "super+shift+right"]
{ "keys": ["ctrl+k", "ctrl+up"], "command": "new_pane" },
{ "keys": ["ctrl+k", "ctrl+shift+up"], "command": "new_pane", "args": {"move": false} },
{ "keys": ["ctrl+k", "ctrl+down"], "command": "close_pane" },
{ "keys": ["ctrl+k", "ctrl+left"], "command": "focus_neighboring_group", "args": {"forward": false} },
{ "keys": ["ctrl+k", "ctrl+right"], "command": "focus_neighboring_group" },
{ "keys": ["ctrl+k", "ctrl+shift+left"], "command": "move_to_neighboring_group", "args": {"forward": false} },
{ "keys": ["ctrl+k", "ctrl+shift+right"], "command": "move_to_neighboring_group" },
Hope this helps.
If you mean rearranging the tabs within the same group, there's a good plugin called MoveTab
My keybindings Sublime Text --> Preferences --> Key Bindings (User) -->
{
"keys": ["super+alt+shift+["],
"command": "move_tab",
"args": { "position": "-1" }
},
{
"keys": ["super+alt+shift+]"],
"command": "move_tab",
"args": { "position": "+1" }
}
Allows CMD+Shift+Option+[ and CMD+Shift+Option+]
If you have Package Control you can install via CMD+Shift+P --> Install Package --> MoveTab
import sublime, sublime_plugin
class DualViewMoveTo(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('set_layout', { "cols": [0.0, 0.5, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] })
self.window.run_command('focus_group', { "group": 0 })
self.window.run_command('move_to_group', { "group": 1 })
There's an excellent plugin offered by Sublime Text itself called Origami, it allows you to create new panes(Columns), delete panes, move and clone views(Tabs) from pane to pane. You can easily shift tabs between a split view using this plugin. Also if you just reorder the tabs in a single pane then Sublime Text offers another good plugin called Move​Tab.

sublime text 2 - add visual mode without vintage mode

My problem is that I would like to be able to use a visual selection without being in vintage mode. Here are my key bindings:
[
{ "keys": ["ctrl+k"], "command": "move", "args": {"by": "lines", "forward": false} }
, { "keys": ["ctrl+j"], "command": "move", "args": {"by": "lines", "forward": true} }
, {"keys":["ctrl+h"], "command": "move", "args": {"by": "characters", "forward": false}}
, {"keys":["ctrl+l"], "command": "move", "args": {"by": "characters", "forward": true}}
, {"keys":["ctrl+e"], "command": "move", "args": {"by": "characters", "forward": true}}
,{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol", "extend": false} }
,{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol", "extend": false} }
, {"keys": ["ctrl+y"], "command": "copy"}
, {"keys": ["alt+y"], "command": "paste"}
, { "keys": ["ctrl+v"], "command": "enter_visual_mode"}
]
As you can see I have vi-like commands except with ctrl modifier. I want it this way. I would like ctrl+v to enter visual mode. I saw in the Vintage mode default key bindings file, the command was defined like I have it defined. Obviously "enter_visual_mode" is a command defined somewhere else in Vintage mode, but I don't know how to include that into my default editor. If anyone could give some guidance on setting this up it would be appreciated!
You will need to use a plugin to support the behavior you want. I don't know of one that is fully flushed out, but I know this was a start to define different keyboard modes (like visual). Take a look at https://github.com/KonTrax/MultiBind. Untested but add the following to your key binding file should work.
// Toggle "visual" layout
{ "keys": ["ctrl+v"],
"command": "multibind_toggle",
"args" : { "layout": "visual" }
},
// Show current layout in statusbar
{ "keys": ["ctrl+shift+\\"],
"command": "multibind_show",
"args" : { }
},
{ "keys": ["ctrl+k"], "command": "move", "args": {"by": "lines", "forward": false, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{ "keys": ["ctrl+j"], "command": "move", "args": {"by": "lines", "forward": true, "extend": true}, "context": [{ "key": "multibind.visual" }] },
{"keys":["ctrl+h"], "command": "move", "args": {"by": "characters", "forward": false, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{"keys":["ctrl+l"], "command": "move", "args": {"by": "characters", "forward": true, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{"keys":["ctrl+e"], "command": "move", "args": {"by": "characters", "forward": true, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol", "extend": true}, "context": [{ "key": "multibind.visual" }]},
{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol", "extend": true}, "context": [{ "key": "multibind.visual" }] }
You have ctrl+e defined twice, so I'm not sure which behavior you want.

Increase number of recent projects in Sublime Text 2?

Is it possible to increase the number of recent projects that appear in the Projects -> Recent Projects menu in Sublime Text 2? I have searched through the settings and I haven't found anything.
Edit this file:
~/Library/Application Support/Sublime Text 2/Packages/Default/Main.sublime-menu
At around line 715 you'll see this:
"caption": "Recent Projects",
"mnemonic": "R",
"children":
[
{ "command": "open_recent_project", "args": {"index": 0 } },
{ "command": "open_recent_project", "args": {"index": 1 } },
{ "command": "open_recent_project", "args": {"index": 2 } },
{ "command": "open_recent_project", "args": {"index": 3 } },
{ "command": "open_recent_project", "args": {"index": 4 } },
{ "command": "open_recent_project", "args": {"index": 5 } },
{ "command": "open_recent_project", "args": {"index": 6 } },
{ "command": "open_recent_project", "args": {"index": 7 } },
{ "command": "open_recent_project", "args": {"index": 8 } },
{ "command": "open_recent_project", "args": {"index": 9 } },
{ "caption": "-" },
{ "command": "clear_recent_projects", "caption": "Clear Items" }
]
Add additional lines of
{ "command": "open_recent_project", "args": {"index": n } },
I.E.
"caption": "Recent Projects",
"mnemonic": "R",
"children":
[
{ "command": "open_recent_project", "args": {"index": 0 } },
{ "command": "open_recent_project", "args": {"index": 1 } },
{ "command": "open_recent_project", "args": {"index": 2 } },
{ "command": "open_recent_project", "args": {"index": 3 } },
{ "command": "open_recent_project", "args": {"index": 4 } },
{ "command": "open_recent_project", "args": {"index": 5 } },
{ "command": "open_recent_project", "args": {"index": 6 } },
{ "command": "open_recent_project", "args": {"index": 7 } },
{ "command": "open_recent_project", "args": {"index": 8 } },
{ "command": "open_recent_project", "args": {"index": 9 } },
{ "command": "open_recent_project", "args": {"index": 10 } },
{ "caption": "-" },
{ "command": "clear_recent_projects", "caption": "Clear Items" }
]
Now you have 11 recent projects
For sublime text 3 I would recommend (based on https://stackoverflow.com/a/34512015/3061838) to add a new file Main.sublime-menu to your %APPDATA%\Sublime Text 3\Packages\User folder with the following content
[
{
"caption": "Project",
"id": "project",
"mnemonic": "P",
"children":
[
{
"caption": "Open Recent More",
"children":
[
{ "command": "open_recent_project_or_workspace", "args": {"index": 0 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 1 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 2 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 3 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 4 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 5 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 6 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 7 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 8 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 9 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 10 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 11 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 12 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 13 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 14 } },
{ "command": "open_recent_project_or_workspace", "args": {"index": 15 } },
{ "caption": "-" },
{ "command": "clear_recent_projects_and_workspaces", "caption": "Clear Items" }
]
},
]
},]
The advantage of this solution is that it will survive Sublime Text updates. The disadvantage is that you will have 2 open-recent menus.
You may choose to remove the lines with index 0-7 since they are present in the original menu.