home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


2.5 Joining Two Lines with J

[J] Sometimes while editing a file you will 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:

Graphic
Keystrokes Results
J Graphic

J joins the line the cursor is on with the line below.

. Graphic

Repeat the last command (J ) with the . to join the next line with the current line.

Using a numeric argument with J joins that number of consecutive lines. In the example above, you could have joined three lines by using the command 3J .

2.5.1 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 J command when you mean j .

    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 ), so all your commands are being 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, then type either U to restore the last line changed or u to undo the last command. You'll probably also have to do some additional editing to fully restore the garbled part of your file.


Previous: 2.4 More Ways to Insert Text Learning the vi Editor Next: 2.6 Review of Basic vi Commands
2.4 More Ways to Insert Text Book Index 2.6 Review of Basic vi Commands

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System