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:
And to hide line numbers in vi, use this command:
vim - wrap long lines
To wrap long lines in vim, use the vim "set wrap" command, like this:
(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:
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:
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:
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.
Hi Alvin! I like to use:
Linenumbers (short notation):
Line distance relative to the current line.
Now typing a number followed by a move up or down command is very practical
Make your code indentation more pleasant by specifying how many positions a tab character will jump:
combine this with:
So if you type
>> the line the cursor is on will indent by this many spaces
To replace the tabcharacter with actual spaces use: