From the course: Learning Vim

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add commands

Add commands - vi Tutorial

From the course: Learning Vim

Start my 1-month free trial

Add commands

- [Instructor] I write a lot of Python code and love to quickly test the code I'm writing. Switching to a terminal and writing Python in the name of the file gets annoying and I'd like to do it from inside Vim. To do this, you'll add a new command. First, let's see how you can ran an external command from Vim using the exclamation mark. Let's open Vim. Hello.py and now colon exclamation mark and the name of the command that we'd like to run. In our case I'm going to run the ls command which lists the files in the directory. If you're on Windows, instead of ls write dir, D-I-R. And we run the ls and we see the input and once we hit enter, we're back to Vim. And now let's define our command. So colon com exclamation mark. This means define a command and override an existing one. Py is the name of the command and then exclamation mark to run an external command python, which is a command to run and give it the parameter percent. Percent is expanded to the name of the file. And Enter. And…

Contents