I've got a file that looks roughly like the following:
field :t, :type => String, :as => :timestamp
field :b, :type => String, :as => :test
index({ :t => 1 })
index({ :b => 1 })
I put my cursor on line 4, and record the following macro:
/: <CR>
viwyma?field : ctrl-r
0, <CR>
$F:lviwy`aviwpj^
So search for a colon, go there, select the whole word ( t
in this case), create a mark on a
, search backwards for field followed by a colon, the word in register 0 ( t
), then a comma. Go to the end of the line, go one character to the left, select the whole word, yank it, go back to the a
mark, select the whole word, paste what I just yanked ( timestamp
), then go to the next line and to the first non-whitespace character (so I can run the macro again right away).
After that, line 4 is what I expect, index({ :timestamp => 1 })
Then, I try running the macro again, and line 5 becomes index({ :: => 1 })
Thanks!
I found the problem. I had installed vim-hardtime to make movement slower. I had assumed it would be disabled for macros but it turns out that's not the case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.