caps lock, but for underscores

2 visualizaciones (últimos 30 días)
Conor Sullivan
Conor Sullivan el 28 de En. de 2021
Editada: Adam Danz el 29 de En. de 2021
My organization's parameter naming convention uses lower case letters and underscores. (ex. this_is_my_parm_name)
It's extremely easy to accidentally use a hyphen instead of an underscore (ex. this_is-my_param_name) when working with our parameters
Is there any way to create a simple to use "caps lock" function just for the hyphen/underscore key?
  1 comentario
Adam Danz
Adam Danz el 28 de En. de 2021
Editada: Adam Danz el 28 de En. de 2021
> Is there any way to create a simple to use "caps lock" function just for the hyphen/underscore key?
Not in Matlab.
You can use strrep or regexprep to replace dashes with underscores in text but that's entirely different from changing the behavior of the keyboard.

Iniciar sesión para comentar.

Respuesta aceptada

Conor Sullivan
Conor Sullivan el 29 de En. de 2021
I figured out a solution. I used Microsoft Keyboard Layout Creator to create a new keyboard layout with - mapped to _. After saving, compiling, and installing the layout, after a computer restart, I can now get the behavior I was looking for. To disable my hyphen, I now just press WIN+Space to swap keyboard layouts. The minus key with the numeric keys is unaffected. To switch back to normal behavior, simply press WIN+Space again. Thanks guys!

Más respuestas (1)

David Hill
David Hill el 28 de En. de 2021
Just run this script after completing your function.
filetext = fileread('yourFunction.m');
newText = strrep(filetext,'-','_');
fid = fopen('yourFunction.m', 'w');
fprintf(fid,' %s\n', newText);
fclose(fid);
  2 comentarios
Conor Sullivan
Conor Sullivan el 28 de En. de 2021
Editada: Conor Sullivan el 28 de En. de 2021
Thanks for your reply, but I'm really looking for this functionality in the Command Window in addition to the text editor. In our scripts, both hyphens (minus) and underscores are used, so this brute force method of post processing the text is ill-advised.
My ideal result would be functionality similar to the Caps Lock key, but only for the -_ key.
Press some key, type parameters names without worrying about mistyping with hyphens, press key again, normal behavior.
I've been exploring changing the Windows registry with a Matlab script that could be triiggered with an Fn key, but haven't figured out how to swap - with _ since they're on the same key.
Adam Danz
Adam Danz el 28 de En. de 2021
Editada: Adam Danz el 29 de En. de 2021
Why not just use the search-and-replace feature (ctrl + f) from the editor? That won't help with command line, though.

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by