Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

sublimetext2 - Sublime Text modifying Linux mousemap to use 4th mouse button

Using Sublime Text 3 (Build 3059) on Linux.

In Sublime Text column selection can be used to select a rectangular area of a file. When using the mouse to do this different mouse buttons are used on each platform. On both OS X and Windows the middle mouse button can be used to select the rectangle of text. On Linux you need to use the right mouse button + shift, I find that combination inconvenient so instead wanted to use the 4th button on my mouse to do it without the hassle of a modifier key.

Easy enough I just need to change the column selection mouse mapping in my default mousemap file.

Here are the relevant sections of the 3 (Linux, OS X, and Windows) default mousemap files:

// Column select Linux default mousemap file
{
    "button": "button2", "modifiers": ["shift"],
    "press_command": "drag_select",
    "press_args": {"by": "columns"}
},

// Column select is the same in the default OS X and Windows mousemap files:
{
    "button": "button3",
    "press_command": "drag_select",
    "press_args": {"by": "columns"}
},

So I figured all I needed to do is to use the same code as OS X and Windows but to set "button4" instead of "button3". So I ended up with this:

// ~/.config/sublime-text-3/Packages/User/Default (Linux).sublime-mousemap

[
    // Map column select to 4th mouse button.
    {
        "button": "button4",
        "press_command": "drag_select",
        "press_args": {"by": "columns"}
    }
]

All very logical and straightforward except that it does not work. Pressing the 4th mouse button does not do column selection, it just does nothing. What's wrong?!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It took me a while to figure this out but...

In Linux the 4th mouse button is not necessarily referenced by "button4". In fact on my system the 4th mouse button is referenced by "button8". All that was needed was to use "button8" where before I had used "button4".

[
    // Map column selection to 4th mouse button ("button8").
    {
        "button": "button8",
        "press_command": "drag_select",
        "press_args": {"by": "columns"}
    }
]

Hope this helps someone.


EDIT: UNIX/Linux users can use xev, which prints the contents of X events, to get their mouse button numbers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...