vim reverse lines
:g/^/m0
vim reverse lines
:g/^/m0
vim reverse range of lines
To reverse lines a to b in vim, use this template:
:a,bg/^/ma_minus_1
Explanation:
- : enters command lines mode
- a,b gives the range of lines to reverse; omit reverse all lines
- g says "apply command to all lines matching this regex"
- /^/ is a regex matching the start of a line, which all lines have
- m is the Ex command for "move"
- a_minus_1 is the move destination, which needs to be one less than the start
of the range to reverse the lines, so a_minus_1 = a - 1
Examples:
- Reverse lines 10-20:
:10,20g/^/m9
a = 10, b = 20, a_minus_1 = 9
- Reverse all lines in the buffer:
:g/^/m0
a = 1, b = (last line), a_minus_1 = 0
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us