C/C++/Arduino/Java VSCode Editor SemiColon + NewLine Time Saver Hack - Page 1
Forum section: electronics / general

author: Altair8800
author_rank: Regular Contributor
timestamp: May 05, 2025, 08:29:54 am
content: For those that program in languages that use semicolons (C/C++/Arduino/Java/Etc.) and use the free opensource VS Code Editor, this is a hack to possibly speed up coding.What this will do is:• Move cursor to end of line,• Insert a semicolon ( ; ),• Jump to a new line.Now to do this you need to sacrifice (by remapping) a key on your keyboard (remap to unused function key F15). In Windows this can be done with a GitHub opensource program called SharpKeys here:https://github.com/randyrants/sharpkeys/releasesNow you would need to restart your computer for the remapping of your keyboard key to take effect.Then in VSCode add an Extension calledmulti-commandby ryuta46Then Open Keybindings:Ctrl + K → Ctrl + S (or File > Preferences > Keyboard Shortcuts).Click the keybindings.json link (top right).In this JSON file add and then save the following code (between the square brackets [])Code:{"key": "f15","command": "extension.multiCommand.execute","args": {"sequence": ["cursorEnd",{ "command": "type", "args": { "text": ";" } },"editor.action.insertLineAfter"]},"when": "editorTextFocus && (editorLangId == c || editorLangId == cpp || editorLangId == arduino || editorLangId == javascript || editorLangId == java)"}Hope someone can find this useful.Additional Notes:I tried doing this a long long time ago with earlier version of VSCode but couldn't get it to work. DeepSeek helped me figure it out (it did take a few prompts and trial and errors but eventually got DeepSeek to show me how to do it). Thought I'll would share...I sacrificed my CAPS LOCK key, you can pick a different key. This is an OS level key remapping but you can remapped your key back to original state if need be.I used the ZIP Portable version of Windows OS program SharpKeys. DeepSeek suggested these other programs for macOS and Linux (have not tested, but for reference):macOS (Using Karabiner-Elements)Install Karabiner-Elements → Remap Caps Lock to F15 (or another unused key).Linux (Using setxkbmap or xmodmap)Run:bashsetxkbmap -option caps:none # Disable Caps Lockxmodmap -e "keycode 66 = F15" # Map Caps Lock to F15

author: brucehoult
author_rank: Super Contributor
timestamp: May 05, 2025, 10:37:11 am
content: If the speed of typing ';', 'return' instead of some single special key on some inconvenient part of the keyboard (or a key combination) is limiting your programming speed in any way then you are doing something very very wrongOr even if the speed of typing is limiting you at ALL. At least assuming that you have the median number of normally functioning fingers.Even assuming I wanted this in emacs:- type 'C-x (' (or 'M-x start-kbd-macro')- type 'C-e ; ret'- type 'C-x )' (or 'M-x end-kbd-macro')You can now already try it out on the spot by typing 'C-x e'. I do this -- defining a keyboard macro -- multiple times per hour almost any time I'm doing any repetitive editing task, and then usually just throw it away because it only took seconds to make it.Now- type 'M-x insert-kbd-macro ret` and the following Lisp code will be inserted into your current document:Code:(setq last-kbd-macro(kmacro "C-e ; RET"))Give it a better name and add it to your .emacs file, along with:Code:(global-set-key  `insert-magic-semicolon)(or whatever you called it)Or just do the whole thing inline:Code:(global-set-key  (kmacro "C-e ; RET"))Or you could add it to c-mode-common-hook so it only works in C and C-derived languages.It's incredible how much JSON you need to do the same thing in your newfangled VS Code vs a 1970s editor.

author: JPortici
author_rank: Super Contributor
timestamp: May 05, 2025, 11:10:12 am
content: Why would anyone really need this? I agree with bruce.Also, for the keyboard, you can use microsoft's official remapping tools, without relying on third party software. At most power toys, but not third party

author: Altair8800
author_rank: Regular Contributor
timestamp: May 05, 2025, 06:04:23 pm
content: This is mainly a Windows OS and popular VSCode IDE based solution.With Unix/Linux OS or Mac OS they have their own and maybe more direct or different solution(s).The advantages are as such:After successful setup, it just works (one and done)One does not need to have another program running before going into VSCode and/or running all the time. Programs like AHK (Auto Hot Keys) or MS PowerToys or other.With C-Based code (C, C++, Arduino, Java, etc.) about 60%-80% of the lines of code you type require a SemiColon ( ; )In VSCode IDE (depending how you have things set up), VSCode (or Extensions) will IntelliSense and add the ending parenthesis but one has to get out of or jump over the Right parenthesis to be able to get to the end of the line of code. Either by typing the Right Arrow Key ( -> ) repeatedly or holding down Right Arrow Key, OR typing the END Key, OR using the mouse to move the cursor to the end of the line of code. Then one has to type the SemiColon Key ( ; ) AND then have to type ENTER keyI know that it might not be hard to do these three steps (move cursor to end of line, type semicolon, then type Enter/New Line) but since you’re doing it ~70% of the time you write a line of code it adds up and no harm to automate it.

author: NE666
author_rank: Frequent Contributor
timestamp: May 05, 2025, 06:29:16 pm
content: If you're really that serious about increasing the speed with which you can make your most frequently used key presses (and tbf, you should be more concerned about the ergonomics and lifetime impact of how this affects your use), then the last thing you want to be doing is mapping that function to some random key that's halfway across the width or length of your keyboard, by merit of the fact that one is 'unused'.Speed, accuracy and typing 'health' are best served by having to move your fingers as little as possible over the keyboard. So, if you're that concerned about typing speeds and macros, perhaps consider something like the programable keyboards from the likes of ZSA/Kinesis/et al, and program the semi-colon key to add a CR/LF on double-tap, or tap-n-hold etc.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 05, 2025, 06:37:14 pm
content: I too am always puzzled by the idea that "typing speed" should even matter for programming, but I guess, to each their own.Also, it may not be for speed, but for "convenience". Like - I find autocompletion for identifiers useful as a convenience. Not for speed, but for added comfort. (But I hate autocompletion that pops up on its own, it's very distracting. I prefer triggering it myself when needed - a common keyboard shortcut for this is CTRL+SPACE.)So yeah, I'm sure we all have a different idea of what we find comfortable. Now comfort and speed are two different things, and if you are after that just for speed, you're indeed probably barking at the wrong tree.

author: NE666
author_rank: Frequent Contributor
timestamp: May 05, 2025, 06:50:50 pm
content: Quote from: SiliconWizard on May 05, 2025, 06:37:14 pmExactly. If you need to be able to touch-type at 80+ wpm to get your coding productively to an acceptable level, you're certainly doing it wrong.The best code you'll ever write is the code you didn't write because you thought it through properly first. That might equate to low double digit typing speed, or less.

author: u666sa
author_rank: Frequent Contributor
timestamp: May 05, 2025, 08:57:41 pm
content: Quote from: Altair8800 on May 05, 2025, 08:29:54 amI don't get the point here. You are already at the end of line and typing semi colon and when you press ENTER you are on new line, indented where needed.Code:int a(5);there, writing that statement means being at the end of line where you type semicolon and press enter to be on the new line, where needed to be next.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: May 06, 2025, 04:22:14 am
content: Why don’t try the Roo Code extension, pointing to Openrouter for the MAI DS R1 free model, and try Vibe Coding with AI?It the semicolon hack was good, this should blow your mind.

author: krish2487
author_rank: Frequent Contributor
timestamp: May 06, 2025, 07:21:49 am
content: At this point, it is a much more worthwhile exercise to learn touch typing. The point of touch typing ( my opinion anyway) is not to (just) increase your typing speed. It is to remove the lag or the type-delete-retype loop when you are in the "zone" so to speak.. aka looking, hunt and pecking, correcting.. Typing is not the bottleneck when one is programming.All said and done, it s a good exercise anyway.. to learn touch typing. and vim.

author: NE666
author_rank: Frequent Contributor
timestamp: May 06, 2025, 08:29:41 am
content: Quote from: dobsonr741 on May 06, 2025, 04:22:14 amWait until they discover Python..

author: SteveThackery
author_rank: Super Contributor
timestamp: May 06, 2025, 09:59:23 am
content: Quote from: krish2487 on May 06, 2025, 07:21:49 amTotally agree. For me, learning touch typing was probably one of the best and most impactful things I ever did in my life. It transformed my productivity.Probably the biggest benefit for me was the reduction in fatigue. The hunt-and-peck style of typing requires your eyes to flick between the keyboard and the screen, which gets tiring after a while. Even the semi-touch-typing I've seen some people evolve for themselves still requires some of that.With real touch-typing your eyes never leave the screen. The reduction in fatigue is remarkable. Also, the continuous gaze somehow lets your brain get into, and stay in, "the zone".I'm not a very fast touch typist, despite decades of practice; I struggle to reach 60 words per minute and I think I'm usually slower. However, it doesn't matter because my real typing rate is around 1000 words per hour, which is actually determined by how fast my brain can compose the prose I am writing. (I haven't measured my programming speed because it is WAY lower and completely limited by my thinking time - nevertheless, the continuous gaze touch-typing offers is still a major help.)1000 words per hour isn't even close to the remarkable speed some copy typists can achieve, but I've never done copy typing. When composing something like a degree dissertation it is more than fast enough.I learned touch typing using "Mavis Beacon Teaches Touch-Typing", and my brother used "KAZ" (Keyboard A to Z). Both worked. I imagine there are more modern alternatives.I have a tip to learning touch typing: practice for no more than ten minutes per day. Yes, really, as little as that. It is really weird what goes on in your head, because it's like you learn it when you arenotpractising. During the daily practice, your typing speed does not improve and in fact is more likely to get slower. But the next day you will find a noticeable improvement in speed and accuracy. What you struggled with yesterday is noticeably easier today. It's almost as if the practice sessions tell your brain what is required, and your brain goes away and works on it in the background.There is another reason for the suggested 10 minute limit: learning to touch type is exceedingly tedious and boring, and I don't believe anyone enjoys it. Keeping it down to 10 minutes per day stops it becoming a "thing" with its own emotional baggage.

author: tggzzz
author_rank: Super Contributor
timestamp: May 06, 2025, 10:22:45 am
content: Quote from: dobsonr741 on May 06, 2025, 04:22:14 amTry any Java IDE. The strongly typed language means that most typingisn'tnecessary. cntl-space is the most used key, autocomplete is notably effective, and better than it can possible be in C/C++.

author: u666sa
author_rank: Frequent Contributor
timestamp: May 06, 2025, 01:11:27 pm
content: Quote from: dobsonr741 on May 06, 2025, 04:22:14 amAsking Ai to give you ideas is too OP, especially if you know what you doing. One guy designed a hybrid squelch this way for walkie-talkie. That thing is butter and a dream and source of envy for many. Ai is the future. It's like 50 additional IQ to what you already posses from birth.

author: Altair8800
author_rank: Regular Contributor
timestamp: May 06, 2025, 04:45:37 pm
content: Quote from: SteveThackery on May 06, 2025, 09:59:23 am

author: hans
author_rank: Super Contributor
timestamp: May 07, 2025, 02:06:15 pm
content: Quote from: u666sa on May 06, 2025, 01:11:27 pmI have been using AI tools more and more to assist writing code, and in some cases its a bliss.I was writing some C# in Rider the other day, and the amount of times it could predict what I wanted to do next was amazing. Hit TAB, return, and on to the next line of code.Sometimes I'm also a bit lazy and just ask ChatGPT to create some scaffolding for me. There are often some obvious bugs that require some convincing to have them fix. But it can be decent, especially if there is some mental block in where to start.But that is assuming you've already learned code and understand how things piece together. Using these tools more, in my view they are as useful as using Mathematica or WolframAlpha for solving math equations. Yes you could get mechanical as in highschool/university days to solve everything by hand, but its faster to have a computer do it. Good AI tools are the Mathematica for programming. You still have to conceptualize everything in the proper way, but it can then just do it for you.Those tools have far more impactful productivity boosts than an alternative keyboard layout or fancy shortcuts IMO.Unfortunately, a lot of people see AI as a quick way to get into programming because they couldn't master it before (it requires some attention span or abstract thinking after all). But I don't think that's how that works and it gives these tools a questionable reputation from 'vibe coding' and such.

author: brucehoult
author_rank: Super Contributor
timestamp: May 07, 2025, 02:22:42 pm
content: Quote from: tggzzz on May 06, 2025, 10:22:45 amIn other words it's incredibly verbose and redundant and there are close to 0 bits of information in each character of code.

author: tggzzz
author_rank: Super Contributor
timestamp: May 07, 2025, 03:33:10 pm
content: Quote from: brucehoult on May 07, 2025, 02:22:42 pmNope. There is sufficient to be able to verify some very useful properties.There is sufficient to show what C++ IDEscannotdo due the fundamental language design.I'm waiting for the less widely educated to jump on "AI vibe coding" as a way of reducing C++ typing, and not being bothered by (or noticing) bizarre hallucinations that need to be corrected and security holes eliminated. A decent language vastly reduces those problems and the supposed need for AI.Some people may choose to have excessively long names, but thinking that is part of the language would indicate unreasonable bias.

author: brucehoult
author_rank: Super Contributor
timestamp: May 07, 2025, 03:38:45 pm
content: Quote from: tggzzz on May 07, 2025, 03:33:10 pmEvery time that ctrl-space successfully auto-completes something, that means by definition that there are zero bits of information content in the characters that were autocompleted.

author: tggzzz
author_rank: Super Contributor
timestamp: May 07, 2025, 03:45:32 pm
content: Quote from: brucehoult on May 07, 2025, 03:38:45 pm(N.B. my edits crossed you reply in the aether; such is life)Ctrl-space shows all the alternatives.Ctrl-space significantly reduces typing (keyboard) mistakes. (Other typing mistakes are reduced/increased by different language characteristics).Ctrl-space makes it very apparent AI vibe coding is not uniquely wonderful.Even without autocomplete, many trivial errors are highlighted without compilation (which is a standard C++ pain point).Also works well in the debugger; try that with a void* variable!

author: brucehoult
author_rank: Super Contributor
timestamp: May 07, 2025, 03:52:50 pm
content: Quote from: tggzzz on May 07, 2025, 03:45:32 pmThen the number of bits of information that are in all the text that is autocompleted is the log2 of the number of alternatives presented.I can't imagine that autocomplete is very useful if there are too many alternatives presented. 256 would be almost totally useless, for example. Or even 16.

author: tggzzz
author_rank: Super Contributor
timestamp: May 07, 2025, 03:57:22 pm
content: Quote from: brucehoult on May 07, 2025, 03:52:50 pmMerelyknowingthere are similar alternatives can be very useful.16 is rare but OK - and will be significantly pruned by the next character typed. 256 is unlikely to occur in practice, since the language's fundamental design will have eliminated many possibilities.