overleaf clopnaz

does :set tabstop=2 and :set softtabs in Overleaf's vim editor

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         overleaf clopnaz
// @namespace    http://tampermonkey.net/
// @version      1.0
// @match        https://www.overleaf.com/project/*
// @grant        none
// @description  does :set tabstop=2 and :set softtabs in Overleaf's vim editor
// ==/UserScript==

// In overleaf's vim editor (see 'ACE'), you can't do many ':' commands
// this script changes the tabwidth to 2 and uses spaces instead of tabs
// there's some additional commented code that should help with remapping as well
(function() {
    'use strict';
    // get the ACE editor so we can modify settings
    const retry = setInterval(() => {
        if (window._debug_editors[window._debug_editors.length -1].session === undefined) return
        clearInterval(retry) // poll until editor is loaded
        // get current editor instance
        const editor = window._debug_editors[window._debug_editors.length -1]
        // vim keyboard plugin
        
        ace.config.on("session", function(session) {
            //    session.setOption("wrap", 80) // This may break auto-completion.
            // session.setWrapLimitRange(80, 80) //Caveat: no more wrap to the pane of size smaler than 80 col.
            session.setOption('tabSize',2) // set the width of tabs to 2 
            session.setOption('useSoftTabs', true) // use soft tabs 
            console.log("Custom tabwidth applied")
        })
        // // add custom keybindings - insert mode applies on insert
        // vimKeyboard.Vim.map("jj", "<Esc>", "insert")
        // // normal mode applies while escaped
        // vimKeyboard.Vim.map("h", "j", "normal")
        // // set the modified keyboard handler for editor
        // editor.setKeyboardHandler(vimKeyboard.handler)
        

    }, 100)
})();