Greasy Fork is available in English.

Vim Movements

vim movements

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

Advertisement:

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Vim Movements
// @namespace    http://tampermonkey.net/
// @version      2024-06-01
// @description  vim movements
// @author       You
// @match        https://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT 
// ==/UserScript==

(function() {
    'use strict';
    document.documentElement.style.scrollBehavior = 'smooth';
    console.log("vim motions loaded");
    const scrollAmt = 500;

    // define function to see if current element is a text box
    function checkTextBox() {
        const tag = document.activeElement.tagName;
        console.log(tag);
        if (tag == 'TEXTAREA' || tag == 'INPUT') {
            return true;
        }
        return false;
    }
    // functions for keys h, j, k, and l
    document.addEventListener('keypress', (event) => {
        if (!checkTextBox()) {
            if (event.key == 'j') {
                // document.activeElement.scrollBy(0, scrollAmt);
                window.scrollBy(0, scrollAmt);
            }
            else if (event.key == 'k') {
                // document.activeElement.scrollBy(0, scrollAmt);
                window.scrollBy(0, -scrollAmt);
            }
            else if (event.key == 'u') {
                history.go(-1);
            }
            else if (event.key == 'R' && event.shiftKey) {
                history.go(1);
            }

        }
    });
})();