Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Search and Replace Missing Features/Behavior #2549

Closed
carkat opened this issue Apr 19, 2018 · 14 comments
Closed

Partial Search and Replace Missing Features/Behavior #2549

carkat opened this issue Apr 19, 2018 · 14 comments

Comments

@carkat
Copy link

carkat commented Apr 19, 2018

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
@carkat carkat changed the title Partial Search and Replace Missing Features Partial Search and Replace Missing Features/Behavior Apr 19, 2018
@Chillee
Copy link
Member

Chillee commented Apr 19, 2018

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

@carkat
Copy link
Author

carkat commented Apr 19, 2018

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

@Chillee
Copy link
Member

Chillee commented Apr 19, 2018

@carkat
Copy link
Author

carkat commented Apr 19, 2018

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.

@parkovski
Copy link
Contributor

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.

@Chillee
Copy link
Member

Chillee commented May 7, 2018

@parkovski Perhaps of interest, @KamikazeZirou just did the work to add command line history. #2618

@captaincaius
Copy link
Contributor

@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 ;).

@sobjornstad
Copy link

sobjornstad commented Jan 24, 2019

+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?)

@carkat carkat closed this as completed Jan 25, 2019
@carkat carkat reopened this Jan 25, 2019
@jussih
Copy link

jussih commented May 4, 2019

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"]
        }
      ]

@brianjmurrell
Copy link

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

@mirsella
Copy link

mirsella commented Apr 28, 2020

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

@brianjmurrell
Copy link

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

@J-Fields
Copy link
Member

This has been fixed for a little while

@brianjmurrell
Copy link

This still does not implement the g/foo/s//bar/g syntax when #4773 was closed as a duplicate of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants