Vim: Partial Search and Replace Missing Features/Behavior

Created on 19 Apr 2018  路  12Comments  路  Source: VSCodeVim/Vim

First Missing Feature:
https://www.linux.com/learn/vim-tips-basics-search-and-replace

Range for vim search and replace does not work.

The following work in Vim for VSCode:

:%s/Search/Replace/g  //globally search and replace entire doc
:s/Search/Replace     //search and replace first instance of Search on this line
:s/Search/Replace/g   //search and replace globally on this line

The following doesn't work in Vim for VSCode (Missing Behavior):

:[range] s/Search/Replace/       //search and replace first instance of Search on lines in range
:[range] s/Search/Replace/g      //search and replace globally for lines in range

where range is of the format

:1,3 s/Search/Replace/g    //search and replace every instance of Search on lines 1, 2, 3

Second Missing Feature/Behavior:
http://vim.wikia.com/wiki/Repeat_last_colon_command

Repeating previous colon command is not working.

@: //repeat previous colon command
@@ //repeat previous repeated colon command

All 12 comments

The first one works with neovim integration, the second one just hasn't been implemented.

What neovim integration? How do I get it and make it work? Is it an addon or an additional plugin?

I can't install an external application that isn't on the approved software list. Regular Vim and newvim are both not on that list, so it doesn't and won't and can't work for me. I can install packages for visual studio code all day. It doesn't work in Vim for VSCode organically, and it should. Search and replace works most of the way, just need to make it work over a range instead of over a whole file.

For the second, a couple of related issues: #1775, #2617. There are also a few commands - &, :s, :& (synonyms, repeat last substitution without flags) and :&& (repeat last substitution with flags) that would be easy to add if command history was accessible.

@parkovski Perhaps of interest, @kamikazeZirou just did the work to add command line history. https://github.com/VSCodeVim/Vim/pull/2618

@Chillee that merge has helped, but I'm glad you've kept this issue open and separate, because the :s shorthands are one of the very few things I'm missing from vim :)...

So I just wanna mention a few things:

  1. In vim, for :s / :sg / :[range]s / etc ... the memorized replacement is separate from the general history.
    You can see this by doing this:
  • do a :s/this/that/
  • go to the command history, and change the command
  • hit :s again
  • you'll see that the original replacement is attempted, not the new one :)
  1. As I can see it, there are 3 distinctly separate features to implement to get the awesomeness on par (at least for the functionality I commonly use)...
  • the ability to use "." in the range - i.e. :.,.+3s/this/that
  • the shorthand for the last bulletpoint - i.e. 4:s/this/that -> :.,.+3s/this/that
  • the ability to skip the search and replace parts of the s command, with or without options along with the previous two (:s, :sg, 4:sg, :%sg, etc.)

If there's anything I'm missing, lmk.

Would you welcome a PR from someone new to this project? That PR you referenced looks like it would be very helpful to lead me in the right direction, and the time these features would save me would warrant the effort ;).

+1 for the & command. I'm in the same boat as carkat where installing NeoVim on my work computer would be a non-starter. & seems pretty straightforward to implement.

(Edit: I see that :s now works...can we get & added as a synonym?)

I was gravely missing & too as my search and replace workflow usually involves running s/foo/bar/ followed by hopping around matches with n and reapplying the replace with &.

I found you can enable & with a simple config:

      "vim.normalModeKeyBindingsNonRecursive": [
        {
          "before": ["&"],
          "commands": [":s"]
        }
      ]

Would this ticket cover Vim's :g/foo/s//bar/g syntax also or is that a different/new ticket?

Would this ticket cover Vim's :g/foo/s//bar/g syntax also or is that a different/new ticket?

sorry to re activate this thread.
i wanted to known the evolution of :g support in vscodeVim, i found the lack of it was disturbing, as i have to have another vim window with the file to do some command.
thanks

@mirsella I opened #4773 about this if you want to subscribe there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

typeoneerror picture typeoneerror  路  3Comments

spinningarrow picture spinningarrow  路  3Comments

orn688 picture orn688  路  3Comments

gerardmrk picture gerardmrk  路  3Comments

cckowin picture cckowin  路  3Comments