Pencil Tip

Vim line

Here are a bunch of tips and tricks with Vim line numbers, wrapping, count, length and my favorite... modeline.

Vim line numbers

To show line numbers, type:

Hit ENTER. You can also use the abbreviated command:

To hide line numbers, type:

Vim line wrap

To line wrap, type:

To remove line wrap, type:

Vim line count

To determine the line count, go to the end of the file by pressing <SHIFT>+g.

Then press <CTRL>+g. A status line will display at the bottom of the editor window indicating the name of the file and what line you're. Since you're at the end of the file, your current line number is the total number of lines in the file.

Vim line length

To determine the length of a line, go to the end of the line by pressing <SHIFT>+4.

Then press <CTRL>+g. A status line will display at the bottom of the editor window indicating the name of the file, what line you're on and also what column you're on. The column indicates the column index of the last character of your current line. Thus, this is the length of your line.

UPDATE 2/12:

For both line count and line length, Joshua Corbin added a comment below that the ruler setting "...adds two displays to the right side of the status line, one that shows where your cursor is, and the other which shows how far down the file you are." To enable this setting, type:

The end result looks like this:

Set Ruler

Vim modeline

The Vim modeline allows you to customize Vim settings for that specific file. If you're programming in the C language, add this to the bottom of your source code:

Vim will now turn on the autoindent setting. Any Vim setting can be set as needed in this manner.


About the Author

Ray Li

Ray is a software engineer and data enthusiast who has been blogging for over a decade. He loves to learn, teach and grow. You’ll usually find him wrangling data, programming and lifehacking.

Comments 2

  1. Also you can “:set ruler” and never have to hit Ctrl-g again to see where your cursor is. This adds two displays to the right side of the status line, one that shows where your cursor is, and the other which shows how far down the file you are.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.