Skip to main content
Share Your Experience: Take the 2024 Developer Survey
12 votes
Accepted

How can I add text to the end of words on each line?

You can also use :%s/\w\+/`&` to convert from Lorem ipsum dolor sit amet to `Lorem` `ipsum` `dolor` `sit` `amet` :% range to the next command (whole buffer) s is a substitute command :s/...
Maxim Kim's user avatar
  • 13.5k
11 votes
Accepted

How to write each line into separate file?

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 ...
Tumbler41's user avatar
  • 7,756
10 votes
Accepted

Visual Block Mode: How to insert text to multiple lines after line ending?

It could be done with virtualedit=ALL: set virtualedit=all select visually vertical part of the text A\<ESC> return set virtualedit=block See the screen:
Maxim Kim's user avatar
  • 13.5k
10 votes
Accepted

Sort every few lines

The easy way: join the lines in the logical blocks before sorting. In detail: mark the lines join the indented lines to the lines above: :'<,'>s/\n /^A/ mark the lines again: gv sort them: :'&...
Sato Katsura's user avatar
  • 4,009
10 votes
Accepted

delete entire line after first whitespace on every line

The two commands below will reduce every line to the first sequence of non-whitespace character followed by a space: from 0.453945 -2.14126e-54 3.40152e-49 101325 214.355 to 0.453945 <-- space ...
romainl's user avatar
  • 41.1k
8 votes
Accepted

How to create multi-line abbreviations

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 ...
nobe4's user avatar
  • 16.1k
8 votes
Accepted

How can I sort multiline blocks in vim?

Peter Rincker's SortGroup is the go-to script for this kind of work. https://gist.github.com/PeterRincker/582ea9be24a69e6dd8e237eb877b8978 Somewhat differently to vim's :sort, it takes a pattern ...
Mass's user avatar
  • 14.1k
8 votes
Accepted

How to delete line endings in Vim?

You can remove line endings by joining lines together. There are a few commands that can accomplish this, for instance the J Normal-mode command will join the current line and the next, or you can use ...
filbranden's user avatar
  • 29k
6 votes
Accepted

How to store all occurrences of a multiline search in a register?

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:...
Jonathan's user avatar
  • 141
6 votes

Visual Block Mode: How to insert text to multiple lines after line ending?

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 (...
salchint's user avatar
  • 206
6 votes

Shuffle multiline folds

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 ...
Jürgen Krämer's user avatar
6 votes
Accepted

Paste append multiple lines

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 ...
Rich's user avatar
  • 32.1k
5 votes

Replace capitalized letters in matching lines

To obtain this result you could use :substitute, for example with the cursor on the first line: :s/\u\+/{\0}/g \u\+ one or more uppercase character: equivalent to [A-Z]\+, see:h \u \0 whole matched ...
LEI's user avatar
  • 1,636
5 votes
Accepted

Keep the full visual selection after indenting in easy mode vim

Think of it like this. aaaa bbbb cccc If you select these 3 lines, then each line has 4 characters selected. Now, you indent them and use gv to reselect the whole thing. Here is the new text: <...
DJMcMayhem's user avatar
  • 17.7k
5 votes
Accepted

Visual scrolling/visual <C-e> and <C-y> across wrapped lines?

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 ...
Luke Davis's user avatar
  • 1,397
5 votes
Accepted

multi-line insert after indentation whitespace

There are a few ways you could do this. The way I would probably do it is this: :%norm I-<space> Note that the <space> should be a literal space, not the text <space>. This simply ...
DJMcMayhem's user avatar
  • 17.7k
5 votes
Accepted

Repeating multi-lines and increment numbers in specific sections?

A macro is certainly capable of doing this. Starting with the first three lines as a template entry 100/1/1 fields value 1 other section 1 is valid Place your cursor on the first line and ...
Tumbler41's user avatar
  • 7,756
5 votes

delete entire line after first whitespace on every line

If you wanted to delete entire line starting with a space, This pattern will be useful. :g/^\s.*/d g -global ^ - start of the line \s - space .* - anything after that d - delete If you want the ...
SibiCoder's user avatar
  • 3,412
5 votes

How can I delete lines fit a pattern to a register or a new file?

Use a Dedicated Register to Which You Append Note delete overwrites the unnamed register "" for each match. Therefore, only the last line matching the pattern is still available in "". Also the ...
Hotschke's user avatar
  • 4,780
5 votes

Paste append multiple lines

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 ...
Thomas F's user avatar
  • 256
5 votes
Accepted

Deletion in multi-line edit mode

It seems you're using the backspace key in insert mode to delete the comments. As you found out, this will not really work at all in visual block mode. Instead, you can simply use the x or d commands ...
filbranden's user avatar
  • 29k
5 votes

How can I add text to the end of words on each line?

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, ...
filbranden's user avatar
  • 29k
4 votes
Accepted

How to change text in other line when the pattern is found?

:/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: ,/quz/s/baa/bar If your scenario ...
Tommy A's user avatar
  • 6,790
4 votes

Sort every few lines

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. Steps: 1) Join n ...
SibiCoder's user avatar
  • 3,412
4 votes
Accepted

How can I stagger text in vim?

vimscript option For the result: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 Next "commands" solves it: :for i in range(6)|call setline(i, repeat(' ', (i-1)*2).getline(i))...
Maxim Kim's user avatar
  • 13.5k
4 votes
Accepted

Break logical lines

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 ...
husB's user avatar
  • 2,113
4 votes

How can I sort multiline blocks in vim?

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. g/^\\...
Ralf's user avatar
  • 9,257
4 votes

How can I sort multiline blocks in vim?

The standard trick for doing this is to convert your blocks into single lines not by removing the linebreaks, but instead by replacing them with something you can find again easily after the sort. e....
Rich's user avatar
  • 32.1k
4 votes

Yank multiple lines without using visual mode

yank is an operator like d and c, which means it works on all motions and text-objects (see the relevant help sections). That means that yip, y), ygg, yib, y/pattern<CR>, yfc etc., all work (and ...
D. Ben Knoble's user avatar
  • 26.4k
4 votes

How to delete line endings in Vim?

I think there’s a substitute command that works, but the first thing that comes to mind is :%join Which translates to “join the whole file.”
D. Ben Knoble's user avatar
  • 26.4k

Only top scored, non community-wiki answers of a minimum length are eligible