Hunter & Tiff Eidmann (eithman)

1 reply · posted

Changing colon to left arrow key?

When I am coding in Visual Studio I am constantly having to take my right hand off the keyboard and over to the arrow keys because I need to move the cursor around. I was wondering if I could change the ;: key such that when I click it the key will act as the left arrow key and when I shift click it the key will act as the semicolon key. I downloaded Keyboard Layout Creator and am able to make that key type a semicolon when I shift press it but I am not able to make it act as the left arrow key. Does anyone know a way to go about doing this? I would really appreciate it! Thanks!

  • I find that the Windows open source program Autohotkey is really useful for doing things like this.  I was able to do what you asked with a simple .ahk script containing the following two lines of code

    $`;::Send {left}
    $+`;::Send `;
    


    However, I'd personally recommend using a modifier like ALT plus `j`, `k`, `l`, `;` to send each of your arrow keys instead of replacing the `:` completely:

    ; Home-row Arrows
    !j::Send {Left}
    !k::Send {Down}
    !l::Send {Up}
    !`;::Send {Right}
    


    I'm not sure how this particular setup might interfere with your current use of hotkeys in Visual Studio but you get the idea.


    Like you, I also had an aversion to moving my right hand off the home-row to use the arrows, home/end, or (even worse) the mouse when coding until I found the Vim text editor several years ago.  I immediately fell in love with Vim's modal editing philosophy.  


    If you are unfamiliar, the idea is that there are several "modes" in Vim but the two most important ones to understand are INSERT mode and NORMAL mode.  Most editors we've used are in always in INSERT mode where every letter you type is inserted into the text buffer.  Unlike most editors, Vim's default mode is NORMAL mode where each letter you type is a command instead and to insert text you need to enter INSERT mode by issuing one of several commands (such as `i`, `a`, `o`, and `s`).  In normal mode, you use letters to quickly navigate and edit your code.  For example, `h`, `j`, `k`, and `l` are the arrow keys, but even better, `w` and `b` move the cursor forward and backward around words.  You can quickly jump to any line of code by typing the line number followed by `G`.  Those examples are just the basics and there are tons of other key-stroke-saving commands that you can add to your arsenal when you get more familiar with it.  


    It may seem cumbersome at first but if you think about it, very little of our coding time is spent actually writing brand new code (i.e. in "insert mode").  Our time is mostly spent navigating existing code, copying/pasting, and making small modifications to code we've already written (i.e. in "normal mode") so it makes sense to have a setup that lets you navigate precisely and effortlessly.


    Once you get used to it, you'll wish you had Vim's modal editing everywhere.  Thankfully, since Vim's keybindings are loved by so many, most major editors, including Visual Studio, have plugins (such as VsVim) to provide these bindings.  I even use Vim bindings in Emacs, which is my default editor for everything (except Unity Projects where I stick to Visual Studio with the VsVim plugin).  I also use the FireFox plugin called Vimium for navigating webpages with just the keyboard and the tiling window manager called i3 in Linux so I can go an entire day without ever touching the arrow keys or the mouse! :)


    Good luck!
    Paul