vi and vim set command examples

If you work with the vi editor a lot, you'll find yourself tinkering with various vi configuration settings from time to time. Many times you'll want to modify the configuration of your current vi session, and to do that you'll use one of many available vi set commands. In this vi (and vim) tutorial, I'll share the vi set commands I use most often.

(Note: I'll alternate the names vi and vim freely in this tutorial. If there is ever a time when a command works in vim and doesn't work in vi I'll be sure to note it. vim is newer, or an "improved" version of vi.)

vi - show lines numbers

Whenever I want to show line numbers in vi or vim, I use the vi "set number" command. To show line numbers in vi, use this command:

:set number

And to hide line numbers in vi, use this command:

:set nonumber

vim - wrap long lines

To wrap long lines in vim, use the vim "set wrap" command, like this:

:set wrap

(I believe this is the default setting.)

Conversely, if you don't want to wrap long lines (you're okay with them scrolling off the right side of the screen), use this vim set command:

:set nowrap

This can be very useful when you're editing text files with long lines, and I often use it when looking at Apache log files, or flat files that I use occasionally instead of a database.

vi - ignoring case in searches

If you want to ignore case when performing a search in vi (i.e., you don't care if you match lowercase or uppercase versions of the string you're searching for), use this vi set command:

:set ignorecase

On the other hand, if it is important to distinguish between uppercase and lowercase characters in your searches, just use the opposite version of this command. As you might have guess by now, you just need to precede your command with the letters "no", like this:

:set noignorecase

Other vi and vim set commands

At the moment I can't think of any other vi set commands I use very often. If I think of any others I'll add them here. If you have any vi or vim set commands you'd like to share here, feel free to add them using the comment form below.

Post new comment

The content of this field is kept private and will not be shown publicly.