Hot answers tagged

7

To close the quickfix window, you use :cclose, as @statox mentioned in the comments. This won't affect which code buffer you're viewing, though. Vim doesn't distinguish between the buffer you were looking at originally and the buffers you navigated to via the quickfix, so to go back you are going to have to use Vim's regular buffer switching commands. If ...


5

In the very general case, the :g command cannot be called recursively. There is one exception: Since Vim patch 8.0.0630, one can call a recursive :g command, if it operates only within a single line. So you can do something like (quoting the help): When the command is used recursively, it only works on one line. Giving a range is then not allowed. This ...


3

Add space between pattern, cmd: g /\v\{/ +1,/\v}/-1 sort ^------------------separation between pattern and command It's a good habit to leave space between pattern and cmd if your cmd takes a range. +1,/\v}/-1 Is a range start from next line until previous line of /\v/. Check :h :range If you have doubts. This range is used for cmd, not for global....


2

You've explained in a comment your requirements: I have many occurrences of the pattern {ab] in the file, where a and be a numbers between 0-9, I want to change each such occurrence to [ab], and ignore the myriad occurrences of {'s that occur on the same lines as the {ab]'s. This expression only includes two digits \d between the { and ] characters and ...


2

I think rather than trying to base things on the current cursor position, you'd be better off formulating your search pattern to be more specific to what you're looking for. From what I can tell, you're trying to replace the { before a number that's followed by a ]. I would do something like this: :%s/{\ze\d\+\]/[/gc The :g command wasn't really ...


1

You could instead try this: :g/begin/,/end/ s/^$//. I don't think g works recursively, so using s instead seems to do the job.


1

One way to do it would be to: use :args to populate the arglist with all the files in which you're interested use search() to check whether your pattern can be found in each file, and if it does not, add its path to a list give that list to getqflist() to transform it into a quickfix list, and invoke setqflist() to add it onto the stack of quickfix lists ...


Only top voted, non community-wiki answers of a minimum length are eligible