Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [range]

Questions having to do with the range modifier in ex (command-line) commands.

1
vote
2answers
53 views

Search and replace multiple line items within a range?

The following search command will make a range and search/replace within it. Specifically, it looks for 'first' in the text, then stops when it finds 'second' across multiple lines. Then, within that ...
0
votes
1answer
28 views

Unable to copy line with .co

Since dot (.) is the range indicator for the current line I was expecting :.co to copy the current line, but it does not do this. What am I doing wrong? In contrast :.w my_line.txt will write the ...
0
votes
1answer
70 views

Is it possible to return to normal mode in the middle of a vim command?

By simply calling :(range)g/bob/norm Axxx I can add xxx to the to the end of all lines in range containing bob. Is there a way to return to normal mode after having used A/I/a/i to enter insert mode, ...
0
votes
3answers
73 views

How can I echo the result of function with a range?

If I have a function that takes a range, how can I echo the return value of the function? For example, the following does not work: :echo 2,8call MyFunction()
0
votes
0answers
68 views

Is it possible to copy block (given by range) multiple times in a single command?

Is there a way to copy a few times a given block from command-line mode, e.g. with the :t command? For example, how to copy the two lines (block) above the cursor -2,-1 to the current position ., 3 ...
1
vote
0answers
66 views

specify a range for command but not move cursor

In vim, when executing a command with a range specified, the cursor will move to the end of the range. For example, after 10;+4print, cursor will be at line 14 wherever you run this command. Q1: Is ...
1
vote
1answer
72 views

Using range as argument returns a comparison

I am trying to capture the result returned from a function implementing range as an argument but apparently I get a comparison. With the following code: function! GetNumber() range return 4 ...
0
votes
1answer
247 views

Is it possible to chain multiple ex commands together with a single range?

I often want to move and indent code at the same time. Is it possible to do the following. Original text: 1: var x = foo(); 2: bar(x); Desired text: 1: setTimeout(function(){ 2: var x = foo(); ...
6
votes
3answers
260 views

Is it possible to execute a Normal mode command only on the first/last line of a range?

I want to comment out a piece of code. For instance this snippet: foo bar foo Should become this: <!--foo bar foo--> So I type the following sequence: vap:norm '<i<!--<C-v><...
1
vote
2answers
1k views

Passing visual range to a :command as its argument

I have a command: command! -nargs=1 TmuxSession !tmux.session "<args>" and I want to run it in visual mode so that selected text will be passed as argument. By selected text I mean selected in ...
1
vote
1answer
39 views

How to assign a search range selection into a register?

I'd like to assign the result of search range selection into a register, instead of printing it, e.g.: :/pattern1/;,/pattern2/p What syntax I can use to achieve that?
3
votes
2answers
125 views

How to exclude the ending pattern in a search range?

I've the following content: group1 item1 item2 item3 group2 item4 item5 group3 item6 where I'd like to select all items which belong to group2 using a search range. Here is my approach: ...
1
vote
2answers
81 views

Using more than two line specifiers in an ex-range

Under :help [range] it states: Some Ex commands accept a line range in front of them. This is noted as [range]. It consists of one or more line specifiers, separated with ',' or ';'. I am ...
1
vote
2answers
83 views

Current line after :3,7call XYZ()

Executing:3,7y does not change the line which contains the cursor (line('.')). This is what I expected. However, when I execute :3,7call XYZ(), the current line goes to the third line. I didn't ...
4
votes
1answer
423 views

How to avoid 'Backwards range given' warning when invoking search range?

I've got the following sample HTML code: <html><body> <table class="foo"> <tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>...
5
votes
2answers
414 views

How to highlight a search range?

I'd like to test the range pattern, same as Vim highlights the text while searching (e.g. :/), but for the range command instead. So in other words, instead of executing: :/<head/,/\/head>/d ...
5
votes
2answers
642 views

How to pipe *characters* to cmd ( `:!` ) [duplicate]

It is possible to pipe visually selected lines (i.e. selected with uppercase V) using :, after which I can enter a command in vim's command line, e.g.: :'<,'>!python -m base64 -d I'd like to ...
1
vote
1answer
66 views

onoremap: defining a bounded region

I want to craft a custom operator-pending motion if for functions in R language that look like this: doSomething <- function(arg1, arg2, ...) { doStuff(...) } The idea is to be able to press ...
4
votes
3answers
90 views

How to filter discontinuous line sets through an external program (Is it possible to combine :g global command with :range! external program filter)?

Say you have some text like this: ## countries, primary United States,Washington,North America Canada,Ottawa,North America Australia,Canberra,Oceania ## countries, secondary France,Paris,Europe Japan,...
4
votes
3answers
143 views

Define range as: “from first line matching to last line matching a given pattern”

Considerthis text with shopping and todo list First thing in the morning - call Bob - buy carrots - buy bread - text Charlie - buy butter - email Alice only then start the day What I am looking for ...
1
vote
1answer
62 views

Act on lines changed by previous command

Is there a way to target the set of lines changed in the previous command? Say I do a search and replace, bulk indent, or some other command that affects either a series or scattered collection of ...
2
votes
1answer
35 views

specifying a range the last of which is the penultimate line

I have 69 files in which I want to prepend lines 5 to penultimate with a short string. How could I address the penultimate line? :5,61s/^/X/g would do it if I manually look up that the last line is 62,...
3
votes
1answer
31 views

Applying changes to lines in alternating modes

I know I can apply changes to multiple lines by selecting the lines in visual mode (I use ctrl-v) and defining the set of actions and the mode to start in (e.g. norma A, will add a comma at the end of ...
5
votes
2answers
221 views

Invert range selection

I can remove the last 10 lines like this: ex -sc '-9,d|x' f.txt However, I would like to invert the selection, or remove all lines except the last 10. Is this possible?
4
votes
1answer
122 views

How to search and format a text range?

I want to format a block of text and I am using a range to select the leading comment of a function. It's all lines starting with // .... I'm using the range :?^[^\/][^\/]?+1,/^[^\/][^\/]/-1 to ...
17
votes
5answers
707 views

Replace a series of asterisk bullet points with a numbered list

Imagine I have the following text: some random stuff * asdf * foo * bar some other random stuff I want to replace the asterisk bullets with numbers, like so: some random stuff 1. asdf 2. foo 3. bar ...
5
votes
1answer
96 views

Can my mapping/function detect when count/range 1 is given instead of none?

I have a key mapped to a command which runs a function, and I would like to detect whether it has been passed a range (prefixed with a count) or not. The difficultly is that I need to be able to ...
1
vote
1answer
278 views

Search and replace in vimscript using a range?

I was wondering how it is that I would place VIMScript variable values in my regex range and also in the replacement portion of my regex? function! GoogleFormsStep(startnum, endnum) let x = ...
2
votes
2answers
929 views

Creating a Vim function mapping that takes a count

I'm trying to create a function mapping that takes a count, in this case the number of lines to yank to the system clipboard. func! Clipboard() echo 'Clipboard function called' if v:count is 0 ...