in Education by
I am having a problem with the visual selection and running a regular expression replace. When I select some text that does not contain the whole row, and hit : to bring the command line up, and do something like :s/T/t/ Then the first match on the line (whether it's selected or not) is changed. So, for example, I have the text Test Text here and I visually select the word Text, then run the above substitution, I end up with test Text here which is not what I want. Any ideas how to achieve the right result? Edit: The actual command line is '<,'>s/T/t/ as defaulted by Vim when you press : with a visual selection. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use \%V (see http://vimdoc.sourceforge.net/htmldoc/pattern.html#//%V) \%V Match inside the Visual area. When Visual mode has already been stopped match in the area that |gv| would reselect. This is a |/zero-width| match. To make sure the whole pattern is inside the Visual area put it at the start and end of the pattern, e.g.: /\%Vfoo.*bar\%V Only works for the current buffer. So: :s/\%VT/t/ If you want to replace multiple hits, add /g :s/\%VT/t/g

Related questions

0 votes
    I have this set of data: dump data; This is a sample output: (this dataset is almost a million ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    How do I do a regexp search against a Mandarin string? JavaScript questions and answers, JavaScript questions ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I've been chasing around regular expressions for my .hgignore file, and found several very useful answers on ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I need a expression to extract some alternatives. The input is: asd11sdf33sdf55sdfg77sdf I need the 11 33 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I need a expression to extract some alternatives. The input is: asd11sdf33sdf55sdfg77sdf I need the 11 33 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    The $' present in the RegExp object is called a ____________ (a) character (b) matcher (c) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    What is the purpose of the RegExp method test()? (a) Tests for a match in its float parameter (b ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    I can use vi{ and va{ to select C++ code blocks. It helps me a lot when I need to yank ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    Currently I try to switch from vim to emacs and have some difficulty while editing code. For most of ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    The context is that I am copy pasting React props definition into the function arguments, so that I ... .string.isRequired, formPlaceholder: PropTypes.string.isRequired, };...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am interested in enabling code folding in Vim for Python code. I have noticed multiple ways to do ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I am interested in enabling code folding in Vim for Python code. I have noticed multiple ways to do ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I am interested in enabling code folding in Vim for Python code. I have noticed multiple ways to do ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I've been using Vim exclusively for a few weeks now, and a few things are keeping me from being ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
...