• Link to LinkedIn Link to LinkedIn Link to LinkedIn
  • Link to Facebook Link to Facebook Link to Facebook
  • Link to Bluesky Link to BlueskyLink to Bluesky
  • Link to Mastodon Link to MastodonLink to Mastodon
  • Link to Mail Link to Mail Link to Mail
  • Link to Rss Link to Rss Link to Rss
  • Dogsbody Technology Charity Support 2025
Contact us: 01276 818576
Dogsbody Technology
  • Emergency support
  • Infrastructure Services
    • Infrastructure Design
    • Infrastructure Build
    • Server management and monitoring
    • In-life Support
    • Pen Testing & Audit
    • Hosting Services
      • Plesk Hosting
      • VPS & Dedicated Servers
      • Tor Hosting
  • Happy Customers
  • About Us
  • Careers
    • Write your own job
  • News & Views
  • Contact Us
  • Menu Menu

Tag Archive for: vim

Vim tips
Rob Hooper

5 Vim tips for advanced users

13 Aug 2019/0 Comments/in Knowledge Base/by Rob Hooper

This blog post lists out my top five Vim tips and tricks to bring your Vim game to the next level.

Here at Dogsbody Technology we are connected to servers, editing files and improving configs every day. All of this means that a good text editor is a must. That is why we chose Vim.

I assume you know the basics, If you don’t I recommend starting here.

Tip 1: Use Vim as a file browser

Have you ever accidentally opened a directory in vim? if you had, you would be pleasantly surprised that it creates a nice interface to find and start editing the file you meant.

Well you can get to that menu another way:

:Explore

From this menu you can use your arrow keys to select and open up new files for editing.

Of course if you already know the file name, just open it directly:

:open filename

Phew I was worried I might need to leave vim for a second then.

Tip 2: Try out multi-line inserts

*tap**tap**tap**tap**tap**tap**tap* the sound of a colleague commenting out a code block. Slow, noisy. Vim has a much quicker approach using visual blocks:

ctrl + v # Enter visual block mode and using your arrow keys select all of the lines you wish to edit
ctrl + shift + i # Enter insert mode
"Example text entry"
Esc # Stop entering text

A very similar method can be used to append text to lines.

ctrl + v 
end # Move the cursor to the end of the line - This works even if the line endings are different lengths 
ctrl + shift + a # Enter append insert mode
"Example text entry"
Esc

You can also use visual block mode to quickly delete a large area of text. Just select it and press “d”.

Tip 3: Make the most of macros

Macros are incredibly simple and just as powerful. They are a sequence of Vim inputs and commands that you can re-run at the touch of a button.

Here’s how to start recording your custom macro:

q # Start recording
j # or any other character you want to trigger it
# any collection of commands you want
q # Stop recording

Then to run the macro:

# To run the "j" macro
@
j

To quickly re-run the last macro, you can double tap “@” or just hold it.

Simple to learn, but when you combine it with other commands, you can quickly build something amazing.

For example – I had a JSON blob containing a list of different SSH keys multiple times. I needed to delete the second key that matched the word “frank”. Quickly creating a macro that runs a search, go to next line, delete. Manually this job would have taken half an hour, with Macros, just five mins.

Tip 4: All the things she ‘sed’

…running through my head

Vim has an inbuilt stream editor, this enables you to modify lines in a quick and replicable manner. But did you know that it comes with regex support out of the box?

Lets look at this command:

:% s/\(wibble\)/ --> \1 <-- /g
:g/[Ww]ibble/d

The first command finds the word “wibble” and puts two big arrows around it, not very useful but a good example:

  • The “%” at the beginning tells it to match all lines. Alternatively you could put in specific line numbers (e.x. 5,13 – match lines five to thirteen)
  • “s/$input/$output/g” start a text substitution. Ending g means match multiple times on one line.
  • \(wibble\) create a capture group looking for the word “wibble”.  Notice that the braces need escaping, unlike normal regex.
  • \1 return the contents of capture group one

The second command uses a slightly different function. It deletes all lines with the word wibble in them, matching both with an without a capital letter W.

If you need to brush up on your regex, we find the regexr site an indispensable resource.

Tip 5: Escaping

If you have ever seen this error “E45: 'readonly' option is set” then you have probably seen this work around…

:w ! sudo tee %

But did you know you can expand this to use any bash commands?

:w ! sort | uniq | tee %

These commands sort the file, then remove any duplicate lines before using tee to write the output back into your vim file.

That concludes my top five Vim tips. Vim is an astonishingly advanced tool that rewards you the further you dig into it.

Did you learn something new? Do you have your own Vim tips to share? Leave us a message in the comments below!

https://www.dogsbody.com/wp-content/uploads/artificial-intelligence-3382507-1030x687.jpg 687 1030 Rob Hooper https://www.dogsbody.com/wp-content/uploads/Dogsbody-site-logo-1.png Rob Hooper2019-08-13 11:01:082019-08-13 11:01:085 Vim tips for advanced users

We are Dogsbody. We take the pain away from building, securing and maintaining IT infrastructure.

Find out how we can help your business

Everything we do is about security. Our team is our strength.

Get in touch

Latest thoughts and news

  • Our Trusted Suppliers after 15+ Years
  • Avoid Surprise AWS RDS Charges in 2026
  • A Season of Giving: Dogsbody Technology Charity Support 2025
  • Wrapping Up 2025: Our Christmas Hours
  • PHP 8.1 will go end of life – 31 Dec 2025
Search Search

Useful links

  • About Us
  • Dogsbody News & Views
  • Contact Us

Linux & cloud services

  • Infrastructure Design
  • Infrastructure Build
  • In life Support
  • Infrastructure Audit
  • Penetration Testing
  • Hosting Services

In life support

  • Overview
  • Helpdesk support
  • Server management and monitoring

Careers

  • Working at Dogsbody
  • Write your own job description
© Copyright 2010-2026 Dogsbody Technology Ltd - Registered in England and Wales 07236558
  • Link to LinkedIn Link to LinkedIn Link to LinkedIn
  • Link to Facebook Link to Facebook Link to Facebook
  • Link to Bluesky Link to BlueskyLink to Bluesky
  • Link to Mastodon Link to MastodonLink to Mastodon
  • Link to Mail Link to Mail Link to Mail
  • Link to Rss Link to Rss Link to Rss
  • Contact us
  • Terms of use
  • Privacy policy
Scroll to top Scroll to top Scroll to top