Learn more about Vim in our dedicated tutorial: VIM and Python – A Match Made in Heaven
How to Learn More Vim
00:00 Hello! And welcome to this final video about VIM. What you saw so far might have looked like fun to you, or maybe it was a bit intimidating, but it just depends on how you approach this whole thing.
00:12 There’s a lot of nice resources out there that teach you VIM through, essentially, playing games. So I would suggest you to approach this whole thing—if you really want to get into learning VIM, approach it like a game. Okay, so there’s these commands that I can press that do something, they take me somewhere.
00:27 There’s this interesting keyboard command that deletes the whole line, or there’s something else that puts it back there, brings me to the end of the file, et cetera, et cetera. So, think of it as a game, and there are some really nice resources out there that you can Google for.
There’s one that already comes built into VIM. I’ll show you that. Heading over to our editor, if instead of typing
vim, I will type
00:53 and this opens up a little program that teaches us VIM in an interactive way that is similar to a game. If I press Enter to continue, I’m entering VIM Tutor here.
You can read over this—it just tells you we’re going to learn through exercising using VIM, and you can also use characters for navigating additionally to the Down arrow, so
j does the same thing as Down. Here you can see an overview of that.
You can think of those as your buttons on the game controller, for example, and that allows you to move around. So pressing
j, we’re moving down to the next lesson, and here we see
EXITING VIM, something that we already learned about.
:q!, it would exit out of there. I don’t want to do that now, so I’ll keep going. So you see, it’s like an interactive little lesson that just walks you through the most important features of VIM. For example,
x here—so here we see if we go over there—you see me not being very proper, like, I’m actually using the arrow keys instead of using—what would that be?
k to go up and then
h to go to the left. There you go.
So here I am, there’s a double
ccow, and I want to delete it by pressing
x, and then it’s gone. Perfect. Now I can move on. Et cetera, et cetera. So, that’s my suggestion.
02:08 There is a value in having a basic understanding of VIM, really for the fact that you can have access to this editor anywhere, on any Unix system. It’s just built into the command line. And if you get good at it, if you have fun in this kind of interacting with your editor, then go ahead and learn more about it.
02:23 Start off with this VIM Tutor or search on Google for some games that utilize the VIM commands and get familiar with it. And yeah—have fun. That’s what I would suggest for how to learn more about VIM. Okay, and that’s it about this section about VIM. See you in the next one!
Hi @realpython94. Great questions! Here are my takes on the answers/suggestions:
1) Syntax Highlighting
Vim knows Python syntax because it comes with an included script
python.vim that was made to parse Python and highlight pieces of the syntax accordingly.
There’s only one version of Python syntax (that just being the correct way of writing Python), but there are many different ways of highlighting Python syntax.
I didn’t go into the possibilities of extending vim, but there is a huge ecosystem of vim plugins (or “scripts”). You can think of it similar to PyPI, the Python Package Index, in that users share their own scripts they wrote to improve the editor with useful features.
There are several other Python syntax highlighter scripts that you can install, that improve on the one that already comes with vim. Some are also on GitHub, e.g. python-syntax or vim-polyglot, which includes advanced syntax highlighting for a whole list of languages.
1a) Vim Startup Settings
Yes, you define startup settings for vim in a
.vimrc file in your home directory (on Mac and Linux) or
If you don’t have this file, you can simply create it there. A useful starting point that addresses two possible improvements I’ve mentioned in this section, would be to switch on syntax highlighting by default, as well as auto-indentation, by putting these two lines into your
syntax on filetype plugin indent on
You can customize and extend these startup settings a lot. You can read more about it in our article on VIM and Python – A Match Made in Heaven. Feel free to go wild if you want to make your vim a customized power tool. Just keep in mind that when you access it on a different computer (e.g. a server you’re working with), it will again just be the bare-bones default version of vim. Until you add your customized
.vimrc file, that is :)
The nano editor is another great choice that is probably present in all the Unix systems you’re gonna work with. I don’t know 100% whether it will always be present, but e.g. this answer on StackOverflow lists quite a few OSs that come with nano pre-installed.
Nano is often considered easier to use than vim, and fulfills the role as an ever-present CLI editor just like vim. Therefore, if you’re already used to it, you could stick with nano and don’t bother about vim.
3) Vi(m) naming
Thanks for the note. :)
Become a Member to join the conversation.
Walt94 on Feb. 18, 2020
1) How does it know python syntax? Are there different versions of python syntax?
1a) is there a way to default to turning on syntax?
2) Is the Nano editor standard on all Unix’s? (i know its on ubuntu.) I use that one a lot on Raspberry Pis but could see using vim!
3) vim stands for ‘vi improved’. ‘vi’ is an old school unix text editor from the 70’s and is short for ‘visual’.