sublime text自定义快捷键的方法

sublime text如何定义快捷键呢?下面来给出方法

sublime text2和sublime text3自定义快捷键的方法是一样的。打开Preferrences -> Key Bindings-User  这个就是用户自定义快捷键的配置文件了。可以参照  Preferrences -> Key Bindings-Default 这个系统默认的快捷键配置,里面就是一个大大的json啦。

不懂json?那不行,必须得学!

{ "keys": ["ctrl+shift+n"], "command": "new_window" }

keys对应的就是快捷键啦,而command对应的就是sublime的命令。如果想要修改快捷键,直接修改对应的keys里面的快捷键就可以啦。

如何查看command请查阅 http://imhuchao.com/965.html

定义快捷键例子

打开Preferrences -> Key Bindings-User,发现里面是一个[],如果没有,没关系,反正都要从头开始写

比如我要自定义一个添加项目的快捷键(当然只是测试一下,并没多多大价值,一般添加项目直接用鼠标拖过来)

那么在这个文件可以加上这些。

[
    {
        "keys":["ctrl+alt+f"],
        "command":"prompt_add_folder"
    }
]

另外我们还可以使用宏来自定义一些复杂的功能,然后快捷键来实现。

创建宏的方法很多:

  1. 用Tools->Record Macro 录制宏,Tools->Save Macro 将缓存的宏存到本地;
  2. 在Packages/User 文件夹下面建立 [文件名].sublime-macro  的宏文件。
{ "keys": ["ctrl+shift+m"], "command": "run_macro_file", "args": {"file": "Packages/User/goto.sublime-macro"} }

sublime快捷键命令

下面是从sublime官网找到的一些明令列表,对应的就是command,可以从里面找到一些有用的明令,配合参数,你一定能够调试到你最好用的sublime

build
Runs a build system.

variant [String]: Optional. The name of the variant to be run.
set_build_system
Changes the current build system.

file [String]: Path to the build system. If empty, Sublime Text tries to automatically find an appropriate build systems from specified selectors.
index [Int]: Used in the Tools | Build System menu but otherwise probably not useful.
new_build_system
Creates a new buffer and inserts a build system template.
toggle_save_all_on_build
Toggles whether all open files should be saved before starting the build.
run_macro_file
Runs a .sublime-macro file.

file [String]: Relative path to the macro file.
insert_snippet
Inserts a snippet from a string or .sublime-snippet file.

contents [String]: Snippet as a string to be inserted. Remember that backslashes \ have to be escaped, like in every other JSON string.
name [String]: Relative path to the .sublime-snippet file to be inserted.
insert
Inserts a string.

characters [String]: String to be inserted.
append
Inserts a string at the end of the view.

XXX

characters [String]: String to be inserted.
force [Bool]:
scroll_to_end [Bool]:
move
Advances the caret by predefined units.

by [Enum]: Values: characters, words, word_ends, subwords, subword_ends, lines, pages, stops.
forward [Bool]: Whether to advance or reverse in the buffer.
word_begin [Bool]
empty_line [Bool]
punct_begin [Bool]
separators [Bool]
extend [Bool]: Whether to extend the selection. Defaults to false.
move_to
Advances the caret to predefined locations.

to [Enum]: Values: bol, eol, bof, eof, brackets.
extend [Bool]: Whether to extend the selection. Defaults to false.
open_file
Opens the specified file.

file [String]: Absolute or relative path to the file to be opened. Relative paths will originate from the recently
contents [String]: This string will be written to the new buffer if the file does not exist. accessed directory (e.g. the directory of the currently opened file).
open_dir
Opens the specified directory with the default file manager.

dir [String]: The directory to open.
open_file_settings
Opens the syntax-specific user settings file for the current syntax.
new_window
Opens a new window.
close_window
Closes the active window.
switch_file
Switches between two files with the same name and different extensions.

extensions [String]: Extensions (without leading dot) for which switching will be enabled.
close
Closes the active view.
close_file
Closes the active view and, under certain circumsances, the whole application. XXX Sounds kinda wrong.
exit
Exits the whole application with all open windows.
reopen_last_file
Reopens the last closed file.
save
Saves the active file.

encoding [String]: The file encoding to save as.
prompt_save_as
Prompts for a new file name and saves the active file.
save_project_as
Prompts for a new file name and saves the current project.
prompt_select_project
Opens a popup with recently accessed projects where you can fuzzy-search.
prompt_open_project
Prompts for a project file to open as a project.
close_project
Closes the current project.
prompt_add_folder
Prompts for a folder to add to the current project.
close_folder_list
Removes all folders from the current project.
refresh_folder_list
Reloads all folders in the current project and updates the side bar.
toggle_sidebar
Shows or hides the sidebar.
toggle_show_open_files
Shows ot hides the open files in the sidebar.
toggle_status_bar
Shows or hides the status bar.
toggle_full_screen
Toggles full screen mode on or off.
toggle_distraction_free
Toggles distraction free mode on or off.
toggle_tabs
Shows or hides the tab bar.
toggle_minimap
Shows or hides the minimap.
left_delete
Deletes the character right before the caret.
right_delete
Deletes the character right after the caret.
undo
Undoes the latest action.
redo
Reapplies the latest undone action.
redo_or_repeat
Performs the latest action again.
soft_undo
Undoes each action stepping through granular edits.
soft_redo
Redoes each action stepping through granular edits.
cut
Removes the selected text and sends it to the system clipboard. Put differently, it cuts.
copy
Sends the selected text to to the system clipboard.
paste
Inserts the clipboard contents after the caret.

clipboard [String]: May be selection. XXX what other values are allowed?
paste_and_indent
Inserts the clipboard contents after the caret and indents contextually.
select_lines
Adds a line to the current selection.

forward [Bool]: Whether to add the next or previous line. Defaults to true.
scroll_lines
Scrolls lines in the view.

amount [Float]: Positive values scroll lines down and negative values scroll lines up.
prev_view
Switches to the previous view.
next_view
Switches to the next view.
next_view_in_stack
Switches to the most recently active view.
prev_view_in_stack
Switches to the view that was active before the most recently active view.
select_all
Select the view’s content.
split_selection_into_lines
Splits the selection into multiple selections, one on each line.
single_selection
Collapses multiple selections into a single selection.
clear_fields
Breaks out of the active snippet field cycle.
hide_panel
Hides the active panel.

cancel [Bool]: Notifies the panel to restore the selection to what it was when the panel was opened. (Only incremental find panel.)
hide_overlay
Hides the active overlay. Show the overlay using the show_overlay command.
hide_auto_complete
Hides the auto complete list.
insert_best_completion
Inserts the best completion that can be inferred from the current context.
XXX Probably useless. XXX
default [String]: String to insert failing a best completion.
replace_completion_with_next_completion
XXX Useless for users. XXX
reindent
Corrects indentation of the selection with regular expressions set in the syntax’s preferences. The base indentation will be that of the line before the first selected line. Sometimes does not work as expected.
indent
Increments indentation of selection.
unindent
Unindents selection.
detect_indentation
Guesses the indentation from the current file.
next_field
Advances the caret to the text snippet field in the current snippet field cycle.
prev_field
Moves the caret to the previous snippet field in the current snippet field cycle.
commit_completion
Inserts into the buffer the item that’s currently selected in the auto complete list.
XXX Probably not useful for users. XXX
toggle_overwrite
Toggles overwriting on or off.
expand_selection
Extends the selection up to predefined limits.

to [Enum]: Values: bol, hardbol, eol, hardeol, bof, eof, brackets, line, tag, scope, indentation.
close_tag
Surrounds the current inner text with the appropiate tags.
toggle_record_macro
Starts or stops the macro recorder.
run_macro
Runs the macro stored in the macro buffer.
save_macro
Prompts for a fiel path to save the macro in the macro buffer to.
show_overlay
Shows the requested overlay. Use the hide_overlay command to hide it.

overlay [Enum]:
The type of overlay to show. Possible values:

goto: Show the Goto Anything overlay.
command_palette: Show the Command Palette.
show_files [Bool]: If using the goto overlay, start by displaying files rather than an empty widget.
text [String]: The initial contents to put in the overlay.
show_panel
Shows a panel.

panel [Enum]: Values: incremental_find, find, replace, find_in_files, console or output.<panel_name>.
reverse [Bool]: Whether to search backwards in the buffer.
toggle [Bool]: Whether to hide the panel if it’s already visible.
find_next
Finds the next occurrence of the current search term.
find_prev
Finds the previous occurrence of the current search term.
find_under_expand
Adds a new selection based on the current selection or expands the selection to the current word.
find_under_expand_skip
Adds a new selection based on the current selection or expands the selection to the current word while removing the current selection.
find_under
Finds the next occurrence of the current selection or the current word.
find_under_prev
Finds the previous occurrence of the current selection or the current word.
find_all_under
Finds all occurrences of the current selection or the current word.
slurp_find_string
Copies the current selection or word into the “find” field of the find panel.
slurp_replace_string
Copies the current selection or word into the “replace” field of the find and replace panel.
next_result
Advance to the next captured result.
prev_result
Move to the previous captured result.
toggle_setting
Toggles the value of a boolean setting. This value is view-specific.

setting [String]: The name of the setting to be toggled.
set_setting
Set the value of a setting. This value is view-specific.

setting [String]: The name of the setting to changed.
value [*]: The value to set to.
set_line_ending
Changes the line endings of the current file.

type [Enum]: windows, unix, cr
next_misspelling
Advance to the next misspelling
prev_misspelling
Move to the previous misspelling.
swap_line_down
Swaps the current line with the line below.
swap_line_up
Swaps the current line with the line above.
toggle_comment
Comments or uncomments the active lines, if available.

block [Bool]: Whether to insert a block comment.
join_lines
Joins the current line with the next one.
duplicate_line
Duplicates the current line.
auto_complete
Opens the auto complete list.
replace_completion_with_auto_complete
XXX Useless for users. XXX
show_scope_name
Shows the name for the caret’s scope in the status bar.
exec
Runs an external process asynchronously. On Windows, GUIs are supressed.

exec is the default command used by build systems, thus it provides similar functionality. However, a few options in build systems are taken care of by Sublime Text internally so they list below only contains parameters accepted by this command.

cmd [[String]]
file_regex [String]
line_regex [String]
working_dir [String]
encoding [String]
env [{String: String}]
path [String]
shell [Bool]
kill [Bool]: If True will simply terminate the current build process. This is invoked via Build: Cancel command from the Command Palette.
quiet [Bool]: If True information less running about prints the command.
See also

Arbitrary Options for build systems
Detailed documentation on all other available options.
transpose
Makes selections or characters swap places.

With selection: The contents of the selected regions are circulated.
Without selection: Swaps adjacent characters and moves the caret forward by 1.
sort_lines
Sorts lines.

case_sensitive [Bool]: Whether the sort should be case sensitive.
sort_selection
Sorts lines in selection.

case_sensitive [Bool]: Whether the sort should be case sensitive.
permute_lines
XXX

operation [Enum]: reverse, unique, shuffle …?
permute_selection
XXX

operation [Enum]: reverse, unique, shuffle …?
set_layout
Changes the group layout of the current window. This command uses the same pattern as Window.set_layout(), see there for a list and explanation of parameters.
focus_group
Gives focus to the top-most file in the specified group.

group [Int]: The group index to focus. This is determined by the order of cells items from the current layout (see Window.set_layout()).
move_to_group
Moves the current file to the specified group.

group [Int]: The group index to focus. See focus_group command.
select_by_index
Focuses a certain tab in the current group.

index [Int]: The tab index to focus.
next_bookmark
Select the next bookmarked region.
prev_bookmark
Select the previous bookmarked region.
toggle_bookmark
Sets or unsets a bookmark for the active region(s). (Bookmarks can be accessed via the regions API using “bookmarks” as the key.)
select_bookmark
Selects a bookmarked region in the current file.

index [Int]
clear_bookmarks
Removes all bookmarks.
select_all_bookmarks
Selects all bookmarked regions.
wrap_lines
Wraps lines. By default, it wraps lines at the first ruler’s column.

width [Int]: Specifies the column at which lines should be wrapped.
upper_case
Makes the selection upper case.
lower_case
Makes the selection lower case.
title_case
Capitalizes the selection’s first character and turns the rest into lower case.
swap_case
Swaps the case of each character in the selection.
set_mark
Marks the position of each caret in the current file. If any marks have already been set in that file, they are removed.
select_to_mark
Selects the text between the current position of each one of the current carets and the marked position. Each caret is matched with each mark in order of occurrence, and is moved to the beginning of its selection.

If any number of selections overlap, they are joined and, of all the carets corresponding to each one of the joined selections, only the one occurring first in the file is preserved.

If the number of current carets is less or equal to the number of marks, the remaining marks in order are ignored. Conversely, if currently there are more carets than marks, the first relevant selections are produced. Of all extra marks, those contained in the selections are removed, and the rest of them are left where they are, without triggering a selection from their position.
delete_to_mark
Deletes the text that select_to_mark would select.
swap_with_mark
Marks all the current carets’ positions, removes those carets, and sets new carets at the previously marked positions, if any.
clear_bookmarks
If no name argument, or the name “bookmarks” is specified, it removes all bookmarks set in the current file, but not the marks. If the name “mark” is specified as an argument, it removes all marks set in the current file, but not the bookmarks.

name [String]: e.g. “mark”, “bookmarks”.
yank
XXX
show_at_center
Scrolls the view to show the selected line in the middle of the view and adjusts the horizontal scrolling if necessary.
increase_font_size
Increases the font size.
decrease_font_size
Decreases the font size.
reset_font_size
Resets the font size to the default

Note: This essentially removes the entry from your User settings, there might be other places where this has been “changed”.
fold
Folds the current selection and displays … instead. Unfold arrows are added to the lines where a region has been folded.
unfold
Unfolds all folded regions in the selection or the current line if there is none.
fold_by_level
Scans the whole file and folds everything with an indentation level of level or higher. This does not unfold already folded regions if you first fold by level 2 and then by 3, for example. Sections with cursors are not folded.

level [Int]: The level of indentation that should be folded. 0 is equivalent to running unfold_all.
fold_tag_attributes
Folds all tag attributes in XML files, only leaving the tag’s name and the closing bracket visible.
unfold_all
Unfolds all folded regions.
context_menu
Shows the context menu.
open_recent_file
Opens a recently closed file.

index [Int]
open_recent_folder
Opens a recently closed folder.

index [Int]
open_recent_project
Opens a recently closed project.

index [Int]
clear_recent_files
Deletes records of recently accessed files and folders.
clear_recent_projects
Deletes records of recently accessed projects.
reopen
Reopens the current file.

encoding [String]: The file encoding the file should be reopened with.
clone_file
Clones the current view into the same tab group, both sharing the same buffer. That means you can drag one tab to another group and every update to one view will be visible in the other one too.
revert
Undoes all unsaved changes to the file.
expand_tabs
XXX

set_translate_tabs [Bool]
unexpand_tabs
XXX

set_translate_tabs [Bool]
new_plugin
Creates a new buffer and inserts a plugin template (a text command).
new_snippet
Creates a new buffer and inserts a snippet template.
open_url
Opens the specified url with the default browser.

url [String]
show_about_window
I think you know what this does.

 

赞赏

微信赞赏支付宝赞赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注