Skip to main content

Questions tagged [range]

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

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

Get return value of range function

In vimscript, when I want to store the return value of a function, I do let a:foo = Function() But I now have a ranged function. I would like to store its return value, ideally via something like the ...
Feffe's user avatar
  • 1,771
1 vote
2 answers
43 views

Help understanding this :global command

I have this command to prune :verb map down to only my plugin mappings: g!^\~/vimfiles/plugin/^-1d _ It also needs :$d to remove last line that has verbose comment "Last set [...]". Can ...
Tom's user avatar
  • 77
1 vote
2 answers
99 views

Yank current line range

I would like to yank the current selected line range (not the line range content). For example, if my selection goes from line 51 to 67, I looking for a way to yank 51,67 to my default register.
Martin Delille's user avatar
1 vote
1 answer
55 views

Search and replace text in visual range but not entire line [duplicate]

I want to search and replace within a visual range just as was answered in this SO post, which uses :'<,'>. But I don't want this to take place on an entire line, only within the selected subset ...
N. Syiemlieh's user avatar
-2 votes
1 answer
66 views

MacVim: how to prevent :[range]!say to remove text? [duplicate]

I am writing some prose and I find very useful to hear what I wrote from an external voice. I found the command say which I guess is only available on MacOsX (perhaps other OS have some equivalent). ...
Barzi2001's user avatar
  • 650
2 votes
1 answer
706 views

How to add a keymap for a visual mode plugin command and pass it the visually-selected range?

I have the linediff.vim plugin installed. Its main command :Linediff only works for visual mode, to which I'd like to add a keymap for this command. I'm using Neovim's Lua API, so I tried this: vim....
Jethro Cao's user avatar
0 votes
4 answers
55 views

How to repeat substitution on the consequent lines?

Say I want to fix a mistake in the following php code: $line1 = intval($line[$1]); $line2 = intval($line[$2]); $line3 = intval($line[$3]); and do substitution on the first line with: :s/\$\(\d\)/\1/ #...
l00p's user avatar
  • 263
1 vote
2 answers
825 views

How to range format with nvim 0.9.0?

I don't set a mapping to format code because it is not something I do all the time. So previously, I used to have a command to format or range format as follows: " format code command! -range ...
paulodiovani's user avatar
1 vote
0 answers
192 views

How to get both the start and end (row, col) of the visual-selected region in `nvim_create_user_command`?

I want to create a user command that can get the visual-selected text (may across multiple lines) from users when the command is calling upon the v-selected range. (so the cursor columns of both the ...
NeoZoom.lua's user avatar
  • 1,530
0 votes
2 answers
99 views

Can you pass specific text within a line to an external command?

Background Vim uses ranges to specify which lines should be passed to a command. For example, :5,10 will use lines 5-10, :'a,'b will use the lines between mark a and mark b, and :'<,'> will use ...
nullromo's user avatar
  • 270
1 vote
1 answer
302 views

get line numbers /something and ?something

I am moving the first steps in scripting and I am facing this issue. Say that I have a test like the one below 1 bla bla bla 2 3 .. 13 SOME KEYWORK 14 blah blah blah 15 .. .. 21 SOME KEYWORK 22 ...
Barzi2001's user avatar
  • 650
2 votes
2 answers
465 views

Replace characters in relative linespan

I know that I can replace characters in a linespan via something to the effect of :300,305s/foo/bar/g But when I'm deep in the code, and I know that I just want to replace in the next five lines, I'm ...
Yehuda's user avatar
  • 275
0 votes
1 answer
264 views

What happens when giving a backwards range (to yank) in Vim?

If you have: minimum working exampl[e] with [] representing your cursor, and issue :.,-2y, Vim will tell you "Backwards range given" and prompt you to swap. If you don't swap it seems to ...
mcp's user avatar
  • 169
0 votes
1 answer
57 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 ...
Andrew Falanga's user avatar
1 vote
2 answers
332 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 ...
pedyram's user avatar
  • 111
1 vote
3 answers
913 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 ...
markling's user avatar
  • 389
1 vote
1 answer
34 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 ...
markling's user avatar
  • 389
0 votes
2 answers
79 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 ...
Quasímodo's user avatar
  • 2,466
2 votes
1 answer
214 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 ...
Harv's user avatar
  • 219
0 votes
2 answers
166 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 ...
BrianWilson's user avatar
1 vote
2 answers
84 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></...
mkayyash's user avatar
1 vote
2 answers
42 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 ...
Konstantin Glukhov's user avatar
4 votes
1 answer
579 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 ...
PiersyP's user avatar
  • 163
4 votes
1 answer
466 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 ...
WW00WW's user avatar
  • 300
1 vote
1 answer
175 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 "...
Carles Ràfols's user avatar
4 votes
2 answers
2k 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/,...
hwong557's user avatar
  • 143
3 votes
2 answers
476 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 ...
Martín Fixman's user avatar
1 vote
0 answers
52 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 ...
leeand00's user avatar
  • 3,621
3 votes
2 answers
811 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 ...
phonedog365's user avatar
0 votes
0 answers
440 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? ...
Jason's user avatar
  • 121
1 vote
4 answers
911 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 (...
Inian's user avatar
  • 63
1 vote
2 answers
1k 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 ...
cmaughan's user avatar
  • 131
0 votes
1 answer
66 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 ...
Tyler Durden's user avatar
  • 2,131
0 votes
1 answer
936 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, ...
user642832's user avatar
0 votes
3 answers
2k 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()
Tyler Durden's user avatar
  • 2,131
1 vote
0 answers
102 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 ...
Ivan's user avatar
  • 336
1 vote
0 answers
112 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 ...
doraemon's user avatar
  • 1,667
1 vote
1 answer
175 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 ...
Nales's user avatar
  • 308
1 vote
1 answer
1k 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(); ...
magnus's user avatar
  • 427
6 votes
3 answers
739 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><...
oliver's user avatar
  • 98
9 votes
3 answers
8k 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 ...
lewiatan's user avatar
  • 421
1 vote
1 answer
47 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?
kenorb's user avatar
  • 18.6k
2 votes
2 answers
332 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: ...
kenorb's user avatar
  • 18.6k
1 vote
2 answers
106 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 ...
René Nyffenegger's user avatar
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 ...
René Nyffenegger's user avatar
4 votes
1 answer
1k 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>...
kenorb's user avatar
  • 18.6k
4 votes
2 answers
1k 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 ...
kenorb's user avatar
  • 18.6k
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 ...
Christian Rondeau's user avatar
1 vote
1 answer
107 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 ...
Karolis Koncevičius's user avatar
4 votes
3 answers
152 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,...
bgoldst's user avatar
  • 163