When typing natural language text, you may find yourself wanting to rewrite a sentence you’ve already written. To delete the characters to the left of the cursor, press backspace several times or press Ctrl-W. Ctrl-W in Insert mode deletes from the cursor to the beginning of the previous word.

If, instead, you type in Ctrl-U, you will delete everything to the left of the cursor on that line (everything before it), and preserve everything to the right of the cursor (everything after it).

Let’s try this out. Open a test file in Vim and enter Insert mode by hitting a or i or o. Then type in the following sentence (don’t hit <ESC>):

A slow brown cow lazed

Then hit Ctrl-W twice. You’ll see that each time you hit Ctrl-W, you delete the word to the left of the cursor. After hitting Ctrl-W twice, you should see:

A slow brown

Then continue with the rest of the sentence. Type in ‘fox jumps over a lazy dog.’ After typing that in, still in Insert mode, use the arrow keys to move your cursor just before the ‘b’ in ‘brown’:

A slow brown fox jumps over a lazy cow
^
Your cursor should be just to the left of the 'b'

The hit Ctrl-U. Everything to the left of the cursor will be deleted, leaving you with:

brown fox jumps over a lazy dog

Then you an continue typing in ‘The quick’ , which will get you:

The quick brown fox jumps over a lazy dog

I’ve found that learning these little shortcuts really helps me type efficiently and keep my typing in sync with my thoughts.

--

--

braindead
braindead

Written by braindead

A passionate programmer, I am eager to challenge myself to do things I’ve never accomplished before and I strive to learn and improve on my skills every day

No responses yet