Help: Terminal Copy and Paste Macros

I do a lot of programming on Linux and copy/paste from the Linux terminal is Ctrl + Shift + C / Ctrl + Shift + V. I’d like to map that combination to Fn + C/ Fn + V to simplify the needed keypresses.

I tried to extend the basic Macro function to achieve this, but it didn’t do anything:

const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  switch (macroIndex) {

  case MACRO_VERSION_INFO:
    versionInfoMacro(keyState);
    break;

  case MACRO_ANY:
    anyKeyMacro(keyState);
    break;

  case MACRO_TERMINAL_COPY:
    MACRO(D(LeftControl), D(LeftShift), T(C), U(LeftControl), U(LeftShift));
    break;
  
  case MACRO_TERMINAL_PASTE:
    MACRO(D(LeftControl), D(LeftShift), T(V), U(LeftControl), U(LeftShift));
    break;
  }
  return MACRO_NONE;
}

I’m referencing them like this:
M(MACRO_TERMINAL_COPY), M(MACRO_TERMINAL_PASTE)

Can anyone give me advice on how to get this done?

1 Like

I just realized that I need to return the MACRO() to get it working. Now it is repeatedly spamming the paste each time I use it. Is there an easy way to stop the spamming?

As a lazy guy, I certainly first try to use something like LCTRL(LSHIFT(Key_C)) or LCTRL(LALT(Key_V)) directly on the Fn layer, but I may not catch what you need to achieve (I use the mouse middle button shortcut to paste my register).

Macros will fire every cycle while the key is held. You can return MACRODOWN instead of MACRO instead, which will only fire when the key has just been pressed. Alternatively you can check the keyState yourself for that purpose like if (keyToggledOn(keyState)).

But yeah, for such simple cases, you don’t need a macro at all, just define the key with modifiers in the keymap like Rom1deTroyes proposed :wink:

Wow. I don’t know why I never thought of using my key that’s bound to middle mouse button, instead of using Shift+Ins (which is 3 keys, since Ins is on the Fn layer). Thanks!

That solved my problem perfectly! Thank you!

To be honest, I start to use it after having a hard time to understand why my primary register was sometimes pasted instead of my X clipboard… Just discovering the power of the palm key, and the meticulous crafting of the Model01 layers !