因为sublime的高亮显示及易于安装插件等特性,所以个人一直比较喜欢用sublime编写代码,但是在昨天升级了一下sublime,导致sublime中不移动光标的情况下向上/下翻页功能失效,经过一番Google和折腾,终于恢复了快捷键功能,下面附上解决方案
步骤一:打开sublime,点击工具栏的preferences>key bindings,将如下代码保存到default(Linux).sublime-keymap-User中
[ { "keys": ["ctrl+up"], "command": "scroll_lines_fixed", "args": {"amount": 1.0 } }, { "keys": ["ctrl+down"], "command": "scroll_lines_fixed", "args": {"amount": -1.0 } }, { "keys": ["pageup"], "command": "scroll_lines_fixed", "args" : {"by": "pages", "amount": 1.0 } }, { "keys": ["pagedown"], "command": "scroll_lines_fixed", "args" : {"by": "pages", "amount": -1.0 } } ]步骤二:点击菜单栏中的Tools>Developer>New plugin 选项,将下列代码保存到.config/sublime-text-3/packages/User下
命名为ScrollLinesFixed
import sublime, sublime_plugin class ScrollLinesFixedCommand(sublime_plugin.TextCommand): """Must work exactly as builtin scroll_lines command, but without moving the cursor when it goes out of the visible area.""" def run(self, edit, amount, by="lines"): # only needed if one empty selection if by != "lines" or (len(self.view.sel()) == 1 and self.view.sel()[0].empty()): maxy = self.view.layout_extent()[1] - self.view.line_height() curx, cury = self.view.viewport_position() if by == "pages": delta = self.view.viewport_extent()[1] else: delta = self.view.line_height() nexty = min(max(cury - delta * amount, 0), maxy) self.view.set_viewport_position((curx, nexty)) else: self.view.run_command("scroll_lines", {"amount": amount})
大功告成!!!