Customizing Settings for a Single Vim Session
In this guide you'll learn how to make custom Vim setting changes that last for a single session. We will walk through how to add line numbers, remove the alert sounds, and other temporary setting changes.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Now if you're like me then the very first thing that you may have noticed when you started using Vim is that it seemed to be missing all kinds of features that not only you would come to expect from a text editor but even things that you'd come to expect even just from a plain vanilla kind of text editor.

So not even like an IDE but just a editor like Sublime Text or something like that. And the reason for that is not because the features are not available, in fact you're gonna see that Vim has literally every single feature you could ever imagine baked into it.

But instead of opening them up and giving you access to all of them it lets you pick and choose the types of settings that you wanna have in order for you to have your own specific kind of setup. I have worked with developers all over the world many of which use Vim and a common thing that I've discovered is that not one of us has an identical Vim setup. We all have something that's a little bit unique to how we like to work, and that's really when the beautiful parts about using Vim.

In this section, we're gonna talk about how we can use those types of settings, how we can set them, and how we can change them. To start off in this guide what I'm gonna do is show you how you can set specific settings on a session basis. So what that means is a session is when ever you have the text editor open the session is over as soon as it closes. So let me show you a basic one.

One of the very first things you may have noticed about Vim and this can be something that's kind of annoying if you don't know how to change it is that by default Vim does not give you line numbers, which is crazy because one of the easiest ways to navigate through to a specific line is by doing something like colon four that takes you to line four, but it doesn't have line numbers which seems kind of counter intuitive. Actually Vim does have line numbers, and what you have to do is just change the setting for it.

So the way you can do that is by typing column and type in set, N-U.

:set nu

And obviously you have to be inside of the command mode in order to do this. So I'm gonna type in set nu which is short for number hit return, and there you go, there are all of our line numbers just like we'd want.

large

So if I wanna navigate to the second to the last paragraph, now I know that's on line 14 and I can type in colon 14 and navigate right to it. Now if I hit save and close out of this and open it back up notice how now all of our line numbers are gone. And that's because whenever you do things like set nu inside of Vim in command mode all it's doing is it's making that change for that session.

In some of the next guides we're gonna walk through how we can add permanent changes and add permanent settings. But it's really important to know the difference because there are many times where I will have a permanent setting that works for most cases but there are certain files that I want to make changes to on the fly and have temporary kind of settings and that's what we can do by doing things like this.

So let's talk about a few other kinds of customizations that you could do. Starting with let's navigate down a few lines onto line 5. Now if I type in the letter I and hit delete, you may hear that in the background that little error message. I am so annoyed by that I hate that little bell so you can get rid of that by typing command and then from there type set visualbell.

Now if I switch back and insert mode I'm hitting delete, but you can't hear anything and that's because visual bell has deactivated that annoying error message. I'm gonna hit escape to go back to command mode and I wanna show you something else. You may be very used to the concept of being able to delete from one line up to the next one, that seems like a very normal thing.

I'm gonna open up Sublime Text here, and I have just a line of some equations and let's say that I came up to this acc line and I wanted to bring it up right here. I could do that very easily in Sublime just by default by hitting delete twice and it takes me right here.

large

Now that may make sense but now watch what happens when I try that in Vim if I switch into insert mode and let's say that I want to come back up one line if I hit delete nothing happens and that's because the delete key is specific by Vim's default just to that one line that it's on, so that's not very helpful.

So let's actually change that up with another setting change. So in order to do that make sure you hit escape to go back into command mode and now type in colon set and this one's a little bit longer one. It's gonna be Backspace equals indent comma eol which stands for end of line and then start.

:set backspace=indent,eol,start

Now if I hit return that setting will be set. And if I switch into insert mode now I can do exactly what I was talking about before where if I hit backspace and I'm at the beginning of a line it takes me all the way back up to the line right in front of it which is exactly what I want. So those are just three different settings.

You're going to see that throughout this entire course on Vim that we are going to be able to have all kinds of settings I believe by the end of it our setting dashboard is gonna be something like 100 or so or even more lines of specific commands just like we did right here that's gonna give us a great and very powerful kind of Vim dashboard to work with.

So those are some ones that are some ways that you can set settings on a session basis but as you may have noticed having to type in something like set Backspace equals indent end of line start if you had to do that every single time you started Vim up you would get very annoyed and eventually you would never wanna use it.

So in the next guide we're gonna walk through how you can make permanent setting changes.