Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to efficiently add parentheses or a string in vim?

Tags:

vim

In traditional text editors, whenever I needed to open a string or parentheses and type something between it I used to do:

  1. Type () or ""
  2. Press left
  3. Type in what I need
  4. Press right

But in vim (that is if I followed the vim way) the process becomes quite tedious as I have to enter the normal mode to move a whole bunch of times:

  1. Type () or ""
  2. Press <ESC>
  3. Press i
  4. Type what I need
  5. Press <ESC>
  6. Press l
  7. Press a

If it is not a good practice to use the arrow keys at any time, is there a more efficient way of doing this kind of task in vim?

like image 508
limeorange8 Avatar asked Oct 26 '25 03:10

limeorange8


1 Answers

No. Doing it in Vim is exactly the same as in your "traditional" editor:

  1. Type () or ""
  2. Press left
  3. Type in what you need
  4. Press right

But… why don't you type the opening character, what you want inside the pair and then the closing character?

  1. Type ( or "
  2. Type what you need
  3. Type ) or "

Too simple?

like image 167
romainl Avatar answered Oct 28 '25 02:10

romainl