Member-only story

Vim — Improve Your Speed

alpha2phi
2 min readNov 28, 2020

--

Vim provides many ways of moving around documents as well as jumping between buffers. In this article, we are going to focus on some useful tricks to improve your speed even further.

Operate with Search Motion

E.g. in the below sentence if we want to delete the words in bold. Other than using f{char} or t{char} another easier option is to use the search motion.

The task takes a lot of time but at the end is still completed on time.    ^ - cursor here

Type d/is<CR> and it becomes

The task is still completed on time.
^ - cursor here

To expand on this further, you can use vim-sneak which lets you jump to or operates on any location with 2 characters.

E.g.

This qt is qt qt is a test.
^ - cursor here

Type 2dzis and it becomes

This is a test.
^ - cursor here

You can also use this with other modifiers, e.g. “v” for selection or “c” to change the words.

Performing Operations with Text Objects

This should sound familiar to any Vim users.

print("hello world")
^ - cursor

Type ci” then you can change the words inside the double quotes even though your cursor position is not within “”

However, this will not work for the following cases if your cursor is not within the braces or brackets.

This is a line with {braces}
^ - cursor here
This is a line with [brackets]
^ - cursor here
This is a line with <angle brackets>
^ - cursor here

Here come targets.vim. Targets.vim adds various text-objects to give you more targets to operate on. Once installed “ci{“, “ci[“, “ci<” should work correctly for the above scenarios.

On top of that, you can use “cin<text-object>” to select the next pairs.

E.g.

This is line 1
^ - cursor here
This is line 2 with {braces}

Type cinB or cin{ you can now change the words within {}

This is line 1
This is line 2 with { }
^ - cursor here

--

--

alpha2phi
alpha2phi

Written by alpha2phi

Software engineer, Data Science and ML practitioner.

No responses yet

Write a response