0

I've recently refactored vim-colors-solarized and I've stumbled on a code like this

let s:foo = s:bar " used in multiple places
" ... many lines
let s:goo = s:boo " used in multiple places

How can I inline all usages of such variables automatically easily. Of course I can write a function to do that. But maybe something like g/let s:."=\s*s:.*/normal dw"adWdW"vdW" | exe "g/@v/s/@a/@v/g" | d in which I mean find all lines matching a pattern, yank variable name to be inlined into register a it's value into register v. Then inside of this global command execute another global command on all lines after the match substituting variable with its value and removing initially matched line.

  • 1
    Write the function (or a macro). Trying to cram it into one messy line is bound to be error prone and run into edge cases. – D. Ben Knoble Jan 4 at 22:35
  • In other words, I’d argue that your way is one of the more complex, in that it is hard to understand at first glance. A function or macro can be simpler, broken down into pieces, &c. If by simplest you mean something specific, please clarify. – D. Ben Knoble Jan 4 at 22:36
  • You see the problem is that I have a policy of either doing the best thing I possibly can or nothing at all. In this case If I would write a function it would definitely not be done in vimscript and it would be able to do inlining of any variable in vimscript. And to do that I would have to start with a parser. To much work for such a specific and rare case. – user1685095 Jan 5 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.