Questions tagged [range]
Questions having to do with the range modifier in ex (command-line) commands.
47
questions
0
votes
1
answer
26
views
Appending text to lines maintaining context
I'm trying to write some script (a function) which I can use to add some additions to a BASH script I'm modifying. This BASH script automates the building of a series of packages. The part of the ...
0
votes
2
answers
41
views
Vim: How to open a new tab containing range/selected text from current tab?
I'm in a file and want to copy and edit part of the file content in a new tab temporarily.
I know that I can write it in a file using :'<,'> w /tmp/list.txt, then :tabnew /tmp/list.txt.
But what ...
1
vote
3
answers
211
views
How supply range to normal mode key-binding?
I've created a mapping to a function that accepts a range. Like this:
command! -range Test call TestFunc(<range>,<line1>,<line2>)
nnoremap <leader>t :Test<CR>
How do I ...
1
vote
1
answer
30
views
Apply next non-blankline function as one part of multi-part user-command
Why do I seem to get different results when I apply this function from the vim command line than when I apply it as part of a user-command?
" advance to next non-blank line only if current line ...
0
votes
2
answers
76
views
Print lines between the first "sta" and last "end" (boundaries included); fallback to file boundaries if missing
Requirements
In a batch manner, i.e., with ex, vim -e or vim -E, I want to print all lines between line b1 and line b2, boundaries included.
b1 is:
The first line with a "sta" match, if ...
2
votes
1
answer
68
views
How to move marked line to current location
Say I put a mark down somewhere with ma. Then I jump somewhere else, GG3k. I want to move what's at my mark to the current line.
I could have just dd'd it if I'd had some forethought, but is it ...
0
votes
2
answers
77
views
Yanking range into register while ignoring blank lines
I’m trying to yank a range into a register while ignoring blank lines. My range is from line 10 to the end of the file.
:10,$v/./"*y
Looking at my registers in :reg I see that my text is not in ...
1
vote
2
answers
55
views
Why is my global command coupled with a range command matching more lines than expected?
I have this file over here.
<ul class="social-icons">
<li><a href=""><span class="social_linkedin_square"></span></a></...
1
vote
2
answers
36
views
Why does a range search ":[range]/pattern/action" not work the same way as ":[range]g/pattern/action"?
Can someone explain why range search :[range]/pattern/action does not work the same way as :[range]g/pattern/action?
Also :'a,'b/pattern/action gives a warning that the range is 'backward', even ...
2
votes
1
answer
197
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
...
3
votes
1
answer
213
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
1
answer
89
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 "...
4
votes
2
answers
708
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
2
answers
284
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
0
answers
22
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 ...
3
votes
2
answers
324
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 ...
0
votes
0
answers
281
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
4
answers
595
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 (...
1
vote
2
answers
303
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
1
answer
46
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
1
answer
516
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
3
answers
859
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
0
answers
95
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
0
answers
89
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
1
answer
158
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
1
answer
846
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
3
answers
627
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><...
8
votes
3
answers
6k
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
1
answer
45
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?
2
votes
2
answers
238
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
2
answers
96
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
2
answers
116
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
1
answer
915
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>...
4
votes
2
answers
964
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
...
6
votes
2
answers
2k
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
1
answer
94
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
3
answers
124
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
3
answers
176
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
1
answer
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
1
answer
49
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,...
2
votes
1
answer
38
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
2
answers
585
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?
3
votes
1
answer
245
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
5
answers
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
...
4
votes
1
answer
111
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 ...
2
votes
1
answer
815
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 = ...
6
votes
2
answers
3k
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
...