More tips on keyboard shortcut tricks for vim text objects and motions and vimari reminders plus brew –force

Well, in the never-ending quest to be efficient, one this that is a pain is that in normal vi, if you want to say change things inside a set of quotes, you have to go backward to the first quote with F” and then change to the next quote with ct” which means Find backward to the first double quote and then Change To the next quote.

But, it turns out that there is vim extension that makes it easier. I saw this in a Medium tip and tricks and confirmed it today, but to review the syntax as Carbon Hacks does, the syntax for vim is:

<number of times to run><command>[<movement action>|<text object>]

In the old vi, it was just an action, but vim introduces this idea of a text object which look like

<command> := [ d | c | v ]
<text object> := [a | i ][ w | s | p | " | ' | ` | (  | ) | [ | ] | | { | } | B | b | < | > | t ]

So to explain this, you can select Around which means includes the surrounding white space, so daw means Delete Around the Word where your cursor is, so all the white spaces go away and Include the wood so diw means Delete in the current word so it is the word where the cursor lives. And V means just select the entire object

And for completeness, there is also a movement that is dw where the normal w command means to move from the current cursor to the end of the word, so a Delete word will delete just from the current cursor to the end of the word.

So what are the other movements well then make sense, they would be Sentence and Paragraph, so cas means change a sentence and all the white space around it.

And finally, there is a really convenient way to change a quoted string with ci" which means change the entire string in double-quotes where the cursor is. Man is this going to save me time. This also works for the backtick and the single quote and also within parentheses with di(. You can also do the same with square brackets. Not that both the right and left parentheses work. Also, you can use b for Block the same way you can use parentheses. And curly braces work as well are equivalent to a capital B. for big block I would guess.

And now for the advanced stuff, you can also do with HTML tags, so you can change in and around angle brackets. Or just t for Tag.

Adding New Text Motions which also work with about and inside

Finally, if you add some plug-ins then you get new motion keys which are pretty useful for moving around but really nice when you are trying to change things.

You can move across words that are in Camel or snake case with CamelCaseMotion, so suddenly a comma, , works so ci,w means change a complete camel or snake case word. And just ,w means move across each Snake cased name part like hello-long-snake-case-variable instead of skipping over the entire variable name.

And adding VimTextObj adds the a text object so that cia means change in an argument and Indent Object adds a text object that works for Python where indents matte so dai means delete around an Indented object

Finally, remembering vimari tab shortcuts w, q, r, x and t

This is a really nice keyboard shortcut thing and a reminder that you can go f to follow and you get vi-like commands like g to go somewhere but some of the other useful things are tab command where:

  • w means next tab
  • q means previous and remember ⌘-W means close tab, so it is a little confusing but makes sense when you look at where the keys are, so q is to the right of the the w key on a QWERTY keyboard
  • r for reload a tab
  • x to close a tab
  • t to open a new one

Finally, Finally, when brew uninstall does not work

I have this problem every so often, for instance brew reinstall --cask wireshark didn’t work because some uninstall was missing, so you can force an install with brew install --cask --force wireshark and it all just works.

I’m Rich & Co.

Welcome to Tongfamily, our cozy corner of the internet dedicated to all things technology and interesting. Here, we invite you to join us on a journey of tips, tricks, and traps. Let’s get geeky!

Let’s connect