Questions tagged [range]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
36 views

Deleting folds over a range

Working in an index with mucked up manual folds. Would like to delete folds from current line to end of file. Have tried: :.,$zd and :.,$df So far I've just done a visual selection from current ...
2
votes
1answer
14 views

What does the command option '-range=N' do?

I can't understand the vim help for :command-range, it states -range=N A count (default N) which is specified in the line number position (like :split); allows for zero line ...
1
vote
1answer
24 views

How to check whether a command is run with range or not?

For example, I have the following code command! -range Test call TestFunc() function! TestFunc() abort " if run with range " get selected content " else " get current word under the ...
1
vote
1answer
27 views

Yank inside quotes of a range of lines to a register and separate them with a new line character

I would like to populate a register with the text inside quotes for a range of lines. The register should contain all yanked text separated with new line characters. Example lines: The "black" cat A "...
3
votes
3answers
3k 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 ...
3
votes
2answers
253 views

Delete blank lines within range

Suppose I have the file: begin asdf asdf end begin asdf end begin asdfasdf end How can I use something like the global command to delete every empty line in between 'begin' and 'end'? :/begin/,...
3
votes
2answers
153 views

How can I use a range as input for an external command without deleting it?

I'm executing an external command that takes as input a range of lines within my file. :'<,'>!copy_stuff Running this runs copy_stuff correctly with the currently selected visual range (and it ...
1
vote
0answers
11 views

How to list the hex range of an a fileencoding in vim?

Is there any way to take a fileencoding setting (for instance utf8 or cp1252) that you might set and find out what it's valid hex range is? When a character falls outside the range, it is displayed ...
0
votes
0answers
66 views

Move/copy range to start of current line

I just learned about the shortcuts that allow you to manipulate ranges, e.g. :+5,+10co. to copy after the current line. I wondered if there is a way to copy and move at the start of the current line? ...
1
vote
4answers
255 views

In Vim ex mode how to re-use a string from the default buffer in the command

I'm trying to modify this file, by extracting the very first line in the file and prepend it to each of the consecutive lines until end of the file black widow card Friday berry I used ex command (...
0
votes
3answers
365 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()
1
vote
2answers
103 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
40 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
165 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, ...
4
votes
3answers
101 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
1answer
102 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 ...
3
votes
2answers
2k 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 ...
0
votes
0answers
75 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 ...
16
votes
5answers
1k 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 ...
1
vote
0answers
77 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
42 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?
1
vote
1answer
109 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 ...
1
vote
1answer
553 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
337 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><...
2
votes
2answers
181 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
86 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
114 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
2answers
655 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 ...
3
votes
1answer
637 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
1k 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
73 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
149 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 ...
1
vote
1answer
500 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
1answer
38 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
146 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 ...
2
votes
1answer
33 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 ...
6
votes
2answers
354 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?