The feasibility of deleting parts of lines is elusive and a better vimmer than I will have to explain that. If anyone cares to donate an explanation I'd be happy to add it to this answer.
But it's quite possible to delete groups of rows that match a beginning pattern and an ending pattern. The most obvious way, I think, is to combine the :global and :delete ...
Try a global command:
:g/^/exe ".w! line".line('.').".txt"
:g/^/ Do a command for every line (you can adjust this regular expression if you only want to save certain lines, i.e. . for non-empty lines)
exe "" execute the following command
.w! save the current line and overwrite if already exists. (Remove ! if you don't want to auto-overwrite everything)
The easy way: join the lines in the logical blocks before sorting.
mark the lines
join the indented lines to the lines above: :'<,'>s/\n /^A/
mark the lines again: gv
sort them: :'<,'>sort
mark the lines one more time: gv
split the lines back and restore indentation: :'<,'>s/^A/\r /g
^A above is the character Ctrl-A (ASCII SOH)...
You can also use
to convert from
:% range to the next command (whole buffer)
s is a substitute command :s/regexWhat/substituteValue without range will substitute on a current line.
\w\+ is a regexp for a word
& is a whole value of what has been matched with regexpWhat, ...
The two commands below will reduce every line to the first sequence of non-whitespace character followed by a space:
0.453945 -2.14126e-54 3.40152e-49 101325 214.355
0.453945 <-- space
But your question is a little confusing so I'm not sure I understood what you want.
With a substitution:
With a macro:
yes, you can do with the ^M character in your abbrev, for example:
iabbrev Doc #^M# function :^M#^M# returns :^M#
will be transformed into:
# function :
# returns :
To get ^M you need to type <C-v> <CR>.
It turns out something along these lines works (although there might well be better ways) -- using a substitute-without-substituting command instead of a global command:
Starting with the answer here: How to show all unique types of a pattern?
I went with:
There is a :folddoclosed command which iterates over all closed folds (just like :g command for the whole buffer) and executes one or more commands on them. So I would close all folds, convert each fold into one long line by replacing the end-of-line with a unique marker, shuffle the lines around, and replace the markers with line-breaks. Something along
Peter Rincker's SortGroup is the go-to script for this kind of work.
Somewhat differently to vim's :sort, it takes a pattern which is supposed to match the text declaring lines as the start of a group. For example,
will sort all the DeclareAcronym ...
I've released a vim plugin that pretty closely matches this behavior.
Instead of scrolling by exactly N lines, this maps <C-u>, <C-d> (half window) and <C-j>, <C-k> (quarter window) to scroll as close to N lines as possible due to the wrapped lines, then moves the cursor back to the original relative line position in the Vim window. ...
There are a few ways you could do this. The way I would probably do it is this:
Note that the <space> should be a literal space, not the text <space>. This simply applies the set of keystrokes I-<space> to every line in the buffer. Uppercase I enters insert mode on the first non-whitespace character of the current ...
If you wanted to delete entire line starting with a space, This pattern will be useful.
^ - start of the line
\s - space
.* - anything after that
d - delete
If you want the starting whitespace to remain, but delete the remaining content, you can use,
To obtain this result you could use :substitute, for example with the cursor on the first line:
\u\+ one or more uppercase character: equivalent to [A-Z]\+, see:h \u
\0 whole matched pattern, see :h sub-replace-special
g is a flag needed to replace all occurrences in the line unless gdefault is on
To affect more than one line, you can ...
This would be very easy with a macro, but you've stated don't want to use one, so here's a few alternative methods. I think they're all more complicated than a simple macro-based solution, but they show off some interesting features of Vim that readers might want to use in other scenarios.
Using :normal edits
5,7 # On ...
I can't use first backreference (\1) instead of hardcoded string
Well, you haven't captured anything in the search so \1 has no value in the replacement.
You can use a matched text later in the pattern, as a back-reference, as well as in the replacement.
This allows you to find a line (\(.*\)) which has a duplicate line immediately ...
Idea: Let's join the n number of lines under case to a single line.
Follow the process for all cases. Then, use sort to sort the cases. Then, cut those lines back and indent them.
1) Join n lines following case by typing this. (in your case, n is 3)
:g/case / normal! 3gJ
2) Select all such cases using visual mode. Press v ot V to select all cases....
What happens if you run:
after you have your blocks visually selected?
... the idea (even if the above doesn't work) is still to yank-append each visually selected block to the same register. But, since you use a specific plugin, you are the one who should know how to do it (i.e. reading the plugin's help).
:/baa/,/quz/s/baa/bar/ works, but that will only work with the first occurrence of baa. If you want to replace all occurrences of baa with bar that come before quz:
If your scenario calls for replacing all occurrences of baa if quz is found:
That will replace all occurrences of baa with bar if quz is found. This is ...
A macro is certainly capable of doing this. Starting with the first three lines as a template
fields value 1
other section 1 is valid
Place your cursor on the first line and execute:
qq Start a macro in register q
y2Enter Yank three lines
jjoEscp Copy the lines below inserting an extra blank line ...
The short answer is: In Visual Block mode select lines to their ends ($) and use A to append some text at the end of each line.
The longer answer:
gg to go the beginning of the first line.
CTRL-V (or the proper alternative CTRL-Q in e.g. gVim) to start blockwise visual selection.
jjj$ select all four lines down (jjj) and to the right until their individual ...
I am going to suggest using Ctrl + v (<C-v>) to make a block.
It sounds as if putting the second block after the first doesn't do what you want. However, if you put the first block in front of the second block, it should work.
To move the first paragraph to before the second paragraph you can do:
vip # Visually ...
I can think of two solutions to this:
1: Use normal mode mappings only; do not use an operator-pending mode mapping
As @D.Ben Knoble mentioned in his comment, instead of
noremap j gj
noremap k gk
nnoremap j gj
nnoremap k gk
The former maps j and k in normal, visual, and operator-pending modes, while the latter maps j and k only in normal mode. ...
There is no direct functionality for that. (At least non I know of.)
Assuming that none of the field short, long and extra contains any line-breaks:
First join the lines into a single line.
This selects the lines from \Declare to a line that ends with }} and joins those line into a single line.
And finally ...
You can use the :normal command, which allows you to run a sequence of Normal mode commands. When given a range, it repeats the sequence for every line. (It also starts at the beginning of each line, when given a range.)
So you could use the e motion (end of the word, for a definition of word that includes keyword characters) or E (going up to the first ...
I like using a macro recording for this kind of task, since that allows me to use the Vim commands I know already to move and edit, rather than having to write (and debug!) regexps to accomplish the task.
Using a macro recording, you can use the exact commands you'd use for this sequence:
Delete \item (and space after it), add & (and space after it) ...