In my codes, I often have to do this kind of text editing:
u(:,:,:) = 0._dp
v(:,:,:) = 0._dp
temp(:,:,:) = 0._dp
To:
grid%u(0:nx,0:ny,0:nz) = 0._dp
grid%v(0:nx,0:ny,0:nz) = 0._dp
grid%temp(0:nx,0:ny,0:nz) = 0._dp
I'm using the record option, which is something that I recently learned how to use and therefore not excel at. Here is how I do it (cursor is placed on "u").
qq
/i grid%
/ESC
(start recording and store in buffer "q", go to insert mode and enter "grid%", escape insert mode)f:
/i 0
/ESC
/;;
/.
/;;
/.
(go to next ":", insert 0, escape insert mode, go to 2nd next ":", repeat last command, go to 2nd next ":", repeat last command);
/a nz
/ESC
/,,
/a ny
/ESC
/,,
/a nx
/ESC
(go to next ":", insert after cursor "nz", escape insert mode, go to 2nd previous ":", insert after cursor "ny", escape insert mode, go to 2nd previous ":", insert after cursor "nz", escape insert mode)j
/SHIFT-^
/@q
(go down one line, go to first non-blank character, apply macro "q")j
/SHIFT-^
/@q
(go down one line, go to first non-blank character, apply macro "q")
The only thing I can think of which can make this code editing more efficient is to use the macro on the two lines in one command. Intuitively, I tried 2@q
but that did not work.
:'<,'>norm @q
. The macroq
should be applied once per line. You won't have to insert the visual range'<,'>
, Vim will do it automatically for you. So, you will only have to type:norm @q
.