Tuesday, April 27, 2010

Re: A 'visible within the window' range?

On Wed, Apr 28, 2010 at 12:24 AM, Duane Johnson <duane.johnson@gmail.com> wrote:
> Thanks for the explanations!
>
>
> Duane
>
> On Apr 27, 2010, at 7:34 PM, Tim Chase <vim@tim.thechases.com> wrote:
>
>> On 04/27/2010 06:36 PM, AK wrote:
>>>
>>> On 04/27/2010 07:22 PM, Duane Johnson wrote:
>>>>
>>>> So the % symbol is a special range that means 'the whole file'. Is
>>>> there a similar special symbol that means 'what is visible in the
>>>> window'?
>>>
>>> HVL
>>
>> For the uninitiated, that terse 3-character response means
>>
>> H    go to the top line displayed on the screen
>> V    go into line-wise visual mode
>> L    go to the last line displayed on the screen
>>
>> at which point, if you press ":", it will prepopulate the command-line
>> with
>>
>>  :'<,'>
>>
>> for the highlighted range (which now covers the lines visible on the
>> screen) at which you can then type your command:
>>
>>  :'<,'>s/foo/bar/g
>>
>> As an interesting side-note, assuming "*" isn't in your 'cpoptions'
>>
>>  set cpoptions?
>>
>> once you've highlighted a range the first time, you can use your original
>> syntax
>>
>>  :*s/foo/bar/g
>>
>> as a shorthand for ":'<,'>s/foo/bar/g", as detailed at
>>
>>  :help cpo-star
>>  :help :star
>>
>> Hope this helps,
>>
>> -tim

Another way:

:set number

Then just do:

:m,ns/search/replace/g

where m and n are the line numbers

To use your original example your see the word three times on your
screen. Pick the line for the first one and the third, that would
capture all the lines in between to include the second one.

--
If we can but prevent the government from wasting the labours of the
people, under the pretence of taking care of them, they must become
happy. - Thomas Jefferson

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: