解决sublime中不移动光标的情况下向上/下翻页

        因为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
import 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"):
        if by == 'pages':
            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})


大功告成!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值