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.

 

你可能还喜欢下面这些文章

Sublime 自定义快捷键

sublime插件丰富,当我们安装了诸多插件之后,发现要使用其中的功能还得用鼠标去点,这岂不是太麻烦了,让我们来自定义快捷键吧!写在前面在写这篇文章之前,我也为自定义快捷键感到无从下手,而在网上搜索千篇一律的都是打开Preferences->key bindings user,添加一些东西进去,比如等等,这个command是什么玩意?比如下面{ "keys": , "command":"duplicate_line" },等等,这个command是什么?我要去哪儿找?我安装了一个新的插件,能使用快捷键吗?等等一系列的疑问,从未有人解答过,可能一些文章都是抄袭拼凑吧。如何查找Command

让sublime支持c/c++语言的编译

sublime只是一个编辑器,让sublime支持c或者c++则是通过设定sublime快捷键调用相关的命令,达到编辑和执行c代码的目的。首先需要下载一个c语言的编译器,对于 Windows 和 Linux 来说可以采用 gcc 。For Windows:下载安装MinGW,然后在系统环境变量中添加(假设你把 MinGW安装在 C 盘),你安装到哪个路径就写哪个路径,别傻乎乎的直接复制啦,不然没用哦。验证一下是否成功。win+r(win就是徽标),输入cmd,打开cmd窗口之后输入gcc -v看看,如果有gcc的信息说明成功了,如果显示gcc不是内部或外部命令,也不是可运行的程序那就是环境变量

让sublime支持php,python等脚本的执行

sublime有自己的Build系统,默认的快捷键是ctrl+b。只需要定制对应语言的执行命令,就可以支持各个语言的编译,执行了。这里对几种主流的脚本语言执行做一些教程。打开Tools->Build System -> New Build System  ...插入对应的json格式的配置即可php保存为php.sublime-build,这下执行php不用老是跑去刷网页了,也不用老是开cmd窗口了。python保存为python.sublime-build不过貌似里面自带了python的,不过如果你看到有build system里面有python的话,那么就可以不用加了。这些执行

sublime安装package control,让插件安装更简单

package control是什么东东?sublime要如何安装package control呢?且往下看。package control就是sublime的插件管理中心,你可以通过这个东西来安装,更新或者卸载插件。插件能够增强sublime的功能,这个就不废话了安装package control1.使用快捷键 Ctrl+` (这个就是键盘Esc下面的那个), 打开sublime的控制台(这个控制台可以输入并且执行python代码)sublime text3sublime text2手动安装可能由于各种原因,无法使用代码安装,那可以通过以下步骤手动安装Package Control: 点击

序言:我的sublime

多年以前有朋友推荐我用sublime,那大概是2011年的时候吧,我用tango notpad2,曾觉得这是用的最舒服的编辑器,高亮,秒开,太舒服。当我无意中看到好多人在用sublime的时候,我好奇的试一试,这一试,就是几年了,或许我以后也将会一直用下去。开始,相当长的一段时间内仅仅将sublime当做一个编辑器用,我想的是看的舒服,打开快,界面够酷就可以了,而且我用的也确实很舒服。但后来,我觉得要是sublime能够直接f5来运行程序是多方便啊,实际上,这对于sublime就是小case,sublime灵活的配置,快捷键你想怎么定义就怎么定义,只要机器上面安装了编译器或者各种语言的解释器就

sublime安装插件的方法

sublime安装插件非常简单。主要方式有两种1.直接安装打开菜单栏里的“Preferences”--->"Browse Packages",打开包的位置 2.通过Package Control来安装如果没有安装package control,那么可以查看这篇文章:sublime安装package control,让插件安装更简单已经安装package control的,点击菜单栏的“Preferences”-->"Package Control",或者可以使用快捷键ctrl+shift+p 打开(mac使用cmd+shift+p)。在打开的终端窗口,输入“install

php开发者的sublime插件和配置

作为一个php开发者,换工作环境的时候可能会重新配置编辑器,这里给出一个比较好的环境(也是我的常用环境)。配置篇每家公司都会有内部的规范,但是只要公司不是特别奇葩,那么规范一般是大同小异。根据规范来设定编辑器,那么写出来的代码则很容易符合规范了。此外,一个设置好的编辑器能够大大提高编码效率!下面是我的配置,可以根据注释自行调整{ // 粗体文本 "bold_folder_labels": true, // 显示所有的空白字符,这样可以看出空格和tab "draw_white_space": "all", // 设置字体 "font_size": 15,

赞赏

微信赞赏支付宝赞赏

发表回复

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