How to efficiently remove word, colon and comma in VIM

I often have a piece of code:

it "should do something", :focus do ... end 

When I want to remove , :focus , I usually do

  • Go to line 1: 1G
  • Go to the colon: f:
  • Delete the colon (using around the word so I can repeat it): daw
  • Delete focus (just repeat the previous one):. .
  • Delete the comma (move left and replace it with a space): hr<SPACE> .

Is there a way that steps 3-5 can be achieved more efficiently?

+6
source share
4 answers

You can go:

  • 1G go to the first line
  • f, comma
  • dE to delete to the next end of WORD (WORD in capital letters is any sequence of characters that is not space).
+8
source

With the cursor , you can do v , e , e , d .

or d , 2 , e

+3
source

Using the cursor or colon, you can do d F , d E. Part d F will delete back to the comma and include it. Then d E will be deleted until the next space character. The best part about this is that if there is no preceding comma, it will still do the same. So with the code

 if :focus, "should do something" do 

If the cursor is in a colon, this macro will remove only the :focus, part, although it will leave two spaces.

+1
source

Better show where your cursor is, but assuming this after the "end", I will do the following:

 ?",<CR>ldt<space>. 
0
source

Source: https://habr.com/ru/post/905172/


All Articles