Vim macros and registers that I always forget

So I keep forgetting how useful macros (and registers are) or repetitive things. Basically, Vi has 10 numeric registers and then alphabetic registers.

If you want to see them then type :registers and you can see what is stored there. There are two ways to use them. The first is to stick thinks into a registry, you name register this way with a double quote (get it you are quoting a string and sticking it in). So the way this works is that you name the tag and then yank to copy it and put to paste it in:

  • “ayW – This means <register> is a and then yank a whole word
  • “aP – This means take the contents of register A and put it before the cursor

Then there is a completely different use of the same register which is to record a macro. This is actually just a text string that gets played back, so you do this by q <register> then a string of command and then an ending q. Then play back is @<register>:

  • qadWq. This says start a quote a string put it into register A, then record delete an entire word. Then the second q means the end of the macro
  • @a. This means run macro in register a

Wow Aftershotz Aeropex rocks!

Wow, so glad that Tony recommended these Aftershotz Aeropex and I have to say they are basically awesome. They are lightweight and easy to use. While the audio is going to be thin, they are perfect for a couple of uses:

  1. If you are biking or running and need to hear what is going on they are great.
  2. If you do conference calls while you are on it your ears don’t get tired and because voice sounds great.
  3. This an amazing way to listen to podcasts and then still have a conversation.

So if you want one, they are $159 from BikeTiresDirect as an example with a 10% rebate so not a bad deal.

The miracles of Vim g commands like gx and what heck is * and #?

OK, this is more nerdy, but there are some not so used commands that are super useful all named g for Global or g for Go.

The :g command and it’s reverse :v

This Global command is quicker than the typical :s/old/new/g instead the syntax is [range]g/pattern/cmd which is way more general. For for instance, if you wanted deleted all the lines with with world “hello” in it, you type :g/hello/d

And there is reVerse version so, :v/hello/d means delete all the lines with hello. You can also do this maybe more intuitively with :g!/pattern/d

The cool g command

The there is the Go command so you can do things like gx which means go to the hyperlink underneath, this was broken before on the Mac but works great as of September 2021, but there are bunch to them, more than I think I can remember and you do a :help *g* you will see all the current commands:

  • gf – go to the file name under the cursor
  • gm – go the column in the middle of the screen
  • gq{motion} – go format to the motion, so gq) means wrap lines to the end of the paragraph. You can also do gqq which is short for wrap the current line and for example gqj means wrap down to the next line
  • gu{motion}. Means make lower case (I know, u is lower), so guu means make the current line all lower case.
  • gd. If you loaded and you are in a program file, it will go to the definition of the word under the cursor. It’s not really smart, it basically does an [[ which moves to the beginning of a section and then searches for the word from there.
  • gD. Like gd but starts the search at the top and looks for the first occurrence of the world (it assumes that this is a language where the function is defined before it’s use).

So what the heck are the * and # commands

OK, there commands are really useful for editing html or programs. So, * means go to the next word that is the same as the word the cursor is on. If you are on the say an HTML tag like script then * will get you to the next script tag. and # will send you backwards.

More text stuff: Github command line gh and vim text-objects

OK, it’s taken a while, but in the spirit of typing rather than clicking, here are some notes about how to do all the common things with…


Catching up on dependable pull requests. If you are like me and are getting pull request automatically, here is all you have to do, the only confusing thing is that you need the pull request number or a branch name that you are merging in.

gh pr view
# you will get a set of pull request numbers for instance #16, #17 and #18
# the -r flag says rebase the pull request into the default branch
# normally main (or master in the old days)
# -d means delete the PR when done
gh pr merge 16 -r -d
# if you want it to ask interactively about the flags
gh pr merge 17

If you want to fork a repo into an organization that you control note that since this is github specific, you don’t need git@github.com or the full url, just organization/repo

# to fork the px4-autopilot repo into tong family/px4-autopilot
gh repo fork px4/px4-autopilot --org tongfamily

To create a new repo and the you can add it as a submodule or you can just clone it

# if you want interactive prompts
gh repo create tongfamily/net-px4
# if you know what you want, you can just use flags
gh repo create tongfamily/net-px4 --private --team dev --description "PX4" -g python

Vim motion command and text-objects

Well, that was awesome, but perhaps even more cool is what you can do with the latest VIM and what are called “text-objects”, the documentation is nearly unreadable, but the basic idea is that the old vi had this notion of objects, so if you wanted to deleted an entire word where the cursor is, you can do dw and if you want to change a word, it is cw that is the <command><motion key>.

Well, the latest vim extends this idea with two new operators call around or a and inside or i which means inside, so for instance if you want to change all the text inside a set of parenthesis, you get there and run. The basic idea is that things that are prefixed with a and i are actually “text-objects” rather than motion keys.

ci( - Change inside a parenthesis
ca( - Change everything including the parenthesis
di[ - delete everything inside the brackets there are around the cursor
da[ - delete the brackets too
cas - change everything around the current sentence

Now the really cool thing is that it has the notion of paragraphs (which are things with a blank line) so and like all vim commands, the complete syntax allows a repeat so it is <action> <number of repetitions> <a for around | I for inside> <text-object like (, [, s, p>

c2ap - change for the next 2 paragraphs

And yes they have a very complete list of text objects, just remember for this to work, you have to be inside these objects, so it is helpful to first move there, so you could do say f[ to find the first bracket and then do a ci[ which would change all the text inside of it.

aw - around a word which stops at non-alphanumeric characters like slashes
iw - inside a word 
aW - around a Word which means to the next white space (so an entire URL) 
iW - in a Word delimited by white space
as - around a sentence
is - inside a sentence
ap - around a paragraph (newline separated include white space)
a' - single quote include the quotes
i' - single quotes not including quotes
a" - double quotes (include the quotes)
i" - inside double quotes (leave them there)
a> - around angle brackets (include them), note that a< works too
i> - inside angle brackets
at - around an HTML tag
it - inside an HTML tag
a( - around parenthesis, not that a) and ab also work
i( - inside parentheses, note that that i) and ib also work
a{ - around braces (includes the braces). note that aB works
i{ - inside braces not that i} and iB also work

So some motion commands

f - find to a character landing the cursor on top of it
F - do this searching backwards
t - find a character landing just before the character
T - this is search to going backwards
^ - first character in the line
$ - last character
10| - the vertical bar means go to the 10th character 
w - forward a word delimited non-alphanumerics
W - forward a word delimited by white space
e - go back one word
E - go back a word until the next white space
) - move to the next sentence which is text that ends in ., ! or ? and a space
( - go back a sentence
} - go forward a paragraph which is delimited by a blank line
{ - got backward a paragraph

Finally, if you are really writing paragraphs remember that gqq does a forced word wrap of a paragraph which is really a more general form of the go quote command which takes a motion, so that gqG for example means go format all the way to the end of the document with a G


Finally a note on visual mode. This is actually pretty logical if you think about it, most of the time when you type a one command like say dW you have no idea what running the W command will do. So with visual mode, you reverse the command sequence with vWd and then with the v, you go into highlight mode, then run the motion command, it highlights the text that will be operated on, then it takes the command.

So for instance, if you want so say delete everything to the end of a paragraph, you don’t want to be surprised, you just do a vGGd and then if the GG doesn’t select what you want, you can fix it and then run the command. Nice!

2021-04-29 Of GarageBand, iCloud, Windows Nightmares, Drones setup problems, Mac cleanup, Smart Home and Champagne

Summary

Sorry to be so late doing this, to be truthful, I managed to delete all my GarageBand data when I recreated my machine, so some notes on how to make that that doesn’t happen to you, so you can see more at tongfamily.com, leave me at voice message at anchor.fm or tweet me at @richtong:

  1. GarageBand and backups
  2. Windows nightmares: How to make it work as a developer
  3. Cleaning up a Mac with the ultra-cool System Information > Windows > Storage Management > Reduce Clutter
  4. The latest hints on using the DJI FPV and Skydio V2 drones
  5. Getting a Champagne cork out.

— This episode is sponsored by · Anchor: The easiest way to make a podcast. https://anchor.fm/app — Send in a voice message: https://anchor.fm/richt/message

Transcription

Still working on this

Git madness, buying olive oil, Zoom hacks, Ad Blocks, Mars 2020, being hacked and Tesla Travel

Summary

More fun for posts as for February 28 and back to January 5 2021:

— Send in a voice message: https://anchor.fm/richt/message

Transcription

Well, I need to figure out a way to automatically transcribe, but isn’t this new Anchor publish to WordPress feature great!

Of Podcasts, ISPs, Tesla Model 3, Webscraping, Emojis, and MacBook Airs

Summary

Well continuing the basically weekly podcast. I skipped Sunday because it was Valentine’s day, but hopefully will stay on the every Sunday track. The main thing is that I go through the newest posts and then go through the back catalog of posts (I have 5,000 of them, so this should work for a looong time!). Net, net, here is what is covered and we are current up to January 14, 2021:

  1. Making a Podcast: Noise Gate and Routined. More tips on keeping the room quiet.
  2. Git Bash Completion. I actually skipped this one, it is way too nerdy to write talk about 🙂 but if you care read about Bash completions
  3. Two Internet Providers and Home networking. Making sure your network is fast and should you get another ISP?
  4. Tesla Model 3 Replacement Wipers Blades. Get the Bosch Aerotwin A102s!
  5. Webscraping with Python, Selenium and Beautiful Soup. See this Deepnote Notebook on my trials and tribulations.
  6. Dealing with Emojis in Vim and on the Mac. Using ⌃+⌘+Spacebar and :boom: with vim-emoji and :boom:
  7. Cable Modem High Latency. Covered in the ISP thing above
  8. Flaky monitors. When it turns out it is really just hardware
  9. Notes for Windows Users buying a MacBook Air

— Send in a voice message: https://anchor.fm/richt/message

Rich’s musings on Gamestop, Sony A1 and Tesla Model S Plaid+, Windows to Mac, Easy Logos for startups, cleaning keyboards and more

Summary

Welcome to the February 6 episode of Rich’s Tongfamily Tips, Tricks and Traps in Technology. You can always see the written posts on https://tongfamily.com, but included here are:

Understanding Robinhood, Gamestop and settlements

Anaconda is a great virtual environment with a big leak

Distributing your podcast manually when Anchor.fm doesn’t

Moving to Jupyter, Python and Pandas when Excel is too small

Moving from Windows to Mac, what’s all this then about Computer Accounts

Drooling over the Sony A1 camera and the Tesla Model S Plaid +

Updating your HomePod manually and using Airplay 2 to control the speakers

Easy Logo creating for startups 

Installing a Ubiquiti Unifi network for noobs

Cleaning your Yucky mechanical keyboard

Send in a voice message: https://anchor.fm/richt/message

Rich Tong on Windows to Mac, Voice Phishing, JAMStacks and Apple Watch

Summary

Here the latest from https://tongfamily.com including:

Some more tips and tricks for moving from Windows to the Mac.  There are lots of differences, so here’s a decoder ring.

Voice phishing. Hopefully you are not that person who answers the call and loses your bank account. here is what to do about it.

Moving to JAMStack. An overview of the move from WordPress to Jamstack with Hugo and Netlify and the reasons why.

Apple Watch. What to look forward to and all the new health features they added since Series 3.

Send in a voice message: https://anchor.fm/richt/message

Tips and Tricks on getting your new company up and run-in non the web

Summary

It’s been a while, but reading from last week, the main focus has been getting a website up and running. From finding a new name on Namecheap to connecting it to Digital Ocean or AWS Route 53 and then GSuite. See https://tongfamily.com for the text posts. For the Amazon book list https://www.amazon.com/hz/wishlist/ls/1O229YTA3ZUGG?ref_=wl_share

Send in a voice message: https://anchor.fm/richt/message