Joining Two Lines with J
Sometimes while editing a file you end up with a series
of short lines that are difficult to scan. When you want to merge two
lines into one, position the cursor anywhere on the first line, and
press J to join the two
lines.
Suppose your file practice reads:
With a
screen editor
you can
scroll the page, move the cursor| Keystrokes | Results |
J | With a screen editor
you can
scroll the page, move the cursor
|
. | With a screen editor you can
scroll the page, move the cursor Repeat the last command
( |
Using a numeric argument with J joins that number of consecutive lines. In
the example here, you could have joined three lines by using the
command 3J.
Problem Checklist
When you type commands, text jumps around on the screen and nothing works the way it’s supposed to.
Make sure you’re not typing the
Jcommand when you meanj.You may have hit the CAPS LOCK key without noticing it. vi is case-sensitive; that is, uppercase commands (
I,A,J, etc.) are different from lowercase commands (i,a,j), and if you hit this key, all your commands are interpreted not as lowercase but as uppercase commands. Press the CAPS LOCK key again to return to lowercase, press ESC to ensure that you are in command mode, and then type eitherUto restore the last line changed oruto undo the ...