Search code examples
visual-studio-codereplaceedit

How to find-and-replace in Visual Studio code in just the selection (selected text)?


I have the following line in a file I'm editing in VSCode:

...............111.........111.............111..

I want to replace all .s with 0s. However, when I highlight the line and do a find/replace for .s, all the .s in the document are replaced, not just the ones in the line I've select, even when I toggle the "Find in selection" button. Is this a bug? In other editors, if I select a chunk of text and then do a find/replace, it will only find/replace matches within the selected block.

Below is a snippet that you should be able to reproduce the issue with. The ...............111.........111.............111.. line is inside the test_unicode function.

def test_simple2(self):
        """Simple CSV transduction test with empty fields, more complex idx, different pack_size.

        100011000001000 ->
        ..........111....................111..........11111..........111..
        """
        field_width_stream = pablo.BitStream(int('1000110001000001000', 2))
        idx_marker_stream = pablo.BitStream(int('11101', 2))
        pack_size = 4
        target_format = TransductionTarget.JSON
        csv_column_names = ["col1", "col2", "col3", "col4", "col5"]

        pdep_marker_stream = pablo.BitStream(generate_pdep_stream(field_width_stream,
                                                                  idx_marker_stream,
                                                                  pack_size, target_format,
                                                                  csv_column_names))
        self.assertEqual(pdep_marker_stream.value, 63050402300395548)

    def test_unicode(self):
        """Non-ascii column names.

        Using UTF8. Hard coded SON boilerplate byte size should remain the same, column name
        boilerplate bytes should expand.

        100010010000000 ->
        2 + 4 + 9     2 + 4 + 6     2 + 4 + 7
        ...............111.........111.............111..
        """
        field_width_stream = pablo.BitStream(int('100010001000', 2))
        idx_marker_stream = pablo.BitStream(1)
        pack_size = 64
        target_format = TransductionTarget.JSON
        csv_column_names = ["한국어", "中文", "English"]

        pdep_marker_stream = pablo.BitStream(generate_pdep_stream(field_width_stream,
                                                                  idx_marker_stream,
                                                                  pack_size, target_format,
                                                                  csv_column_names))
        self.assertEqual(pdep_marker_stream.value, 1879277596)

I'm using VSCode 1.12.2 in Ubuntu 16.04.


Solution

  • I was able to get it to work but the workflow is poor:

    1. control + H to open Find/Replace
    2. Select your line of text
    3. Click the "Find in selection" icon to the right Alt L or L on macOS)
    4. Enter your find and replace characters in their inputs
    5. Click the Replace all icon

    It works but you have to go through the workflow all over again for each new selection (except for CTR + H of course). BTW I have the exact same behavior in Sublime Text.

    Could you go with a regExp to find your lines? Do they contain only .'s and 1's?