Skip to content

Instantly share code, notes, and snippets.

@wixo
Last active July 22, 2021 04:22
Show Gist options
  • Save wixo/7076679 to your computer and use it in GitHub Desktop.
Save wixo/7076679 to your computer and use it in GitHub Desktop.
caps-lock to soft-tab

caps-lock to soft-tab

Well, some time ago I decided to use smart-tabs as my solution for the tabs vs spaces holy war. And more recently I decided to override the capslock in my macbook because, well, who uses caps-lock anymore? so I said: why not to override caps-lock to a fixed soft-tab (2 spaces), after some hours googling how to make something like this to work I came up with a hacky way to make it work with sublime text, I will share the links and steps if you want to get the same functionality

  1. First you need to disable the caps-lock key as showed here: (http://stackoverflow.com/a/8437594)
  2. In that same text they mention to install PCKeyboardHack, install it too, also we will need a complementary app named KeyRemap4MacBook they are from the same publisher
  3. Next, with PCKeyboardHack you will tick the Change Caps Lock and insert the 110 keycode ( PC Application Key )
  4. Now in KeyRemap4Macbook you will filter for PC Application Key or in For PC Users > Change PC Application Key and then tick Application Key to Option_L+Space ( you can choose from the other options but for me Option_L+space did work )
  5. From now on, everytime you press caps-lock will be the same as if you press option_left + spacebar
  6. Enter Sublime Text, you will need a macro so you want to open one, first Tools > record macro ( ^Q ), there you will press the spacebar twice, then Tools > stop recording and then Tools > save macro.
  7. Finally you will create a key binding to run the macro everytime you press alt (option) + space, so you go Preferences > Key Binding User and paste the next snippet
{ "keys": ["alt+space"], "command": "run_macro_file",
 "args": { "file": "Packages/User/smart-spaces.sublime-macro" }
}

check if the file address is correct and if everything is ok now you will be able to use smart-tabs like a boss remembet that smart-tabs rules as tabs for indentation and spaces for alignment, now with caps-lock you can use the soft-tabs instead of smashing the spacebar.

@PuercoPop
Copy link

Well, some time ago I decided to use smart-tabs stop using tabs as my solution for the tabs vs spaces holy war. Fix'd ^_^'

@wixo
Copy link
Author

wixo commented Oct 21, 2013

NO

@PuercoPop
Copy link

I can not see how using two distinct whitespace characters could benefit anyone, could we please move on to actual problems?

@wixo
Copy link
Author

wixo commented Oct 21, 2013

It benefits me, now I can align my code twice as fast. This gist is more like a future note to myself if I need to do the same thing with a fresh install of OSX.
with my mind on my problems and my problems on my mind.

@PuercoPop
Copy link

Align code by hand? Doesn't you editor do that for you? Even go-lang comes with gofmt

@wixo
Copy link
Author

wixo commented Oct 21, 2013

yup I align my code by hand because I care and no other solution could convince me. even more, pseudo refactors can tell me how much time did I spend working on that part of the code.

@acccounttest
Copy link

I did a similar approach to replace the key tab by caps lock without breaking any combination, adding double tab trigger to switch windows in metro context under Windows 8 but it's mandatory, can be commented out.
https://github.com/acccounttest/Sublime-Tab-for-SublimeText-Metro-and-Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment