1
00:00:00,050 --> 00:00:02,060
- [Instructor] I write a lot of Python code

2
00:00:02,060 --> 00:00:05,040
and love to quickly test the code I'm writing.

3
00:00:05,040 --> 00:00:07,080
Switching to a terminal and writing Python

4
00:00:07,080 --> 00:00:10,010
in the name of the file gets annoying

5
00:00:10,010 --> 00:00:12,080
and I'd like to do it from inside Vim.

6
00:00:12,080 --> 00:00:15,010
To do this, you'll add a new command.

7
00:00:15,010 --> 00:00:17,040
First, let's see how you can ran an external command

8
00:00:17,040 --> 00:00:20,080
from Vim using the exclamation mark.

9
00:00:20,080 --> 00:00:22,020
Let's open Vim.

10
00:00:22,020 --> 00:00:26,060
Hello.py and now colon exclamation mark

11
00:00:26,060 --> 00:00:29,010
and the name of the command that we'd like to run.

12
00:00:29,010 --> 00:00:31,070
In our case I'm going to run the ls command

13
00:00:31,070 --> 00:00:34,060
which lists the files in the directory.

14
00:00:34,060 --> 00:00:39,070
If you're on Windows, instead of ls write dir, D-I-R.

15
00:00:39,070 --> 00:00:42,010
And we run the ls and we see the input

16
00:00:42,010 --> 00:00:45,000
and once we hit enter, we're back to Vim.

17
00:00:45,000 --> 00:00:47,020
And now let's define our command.

18
00:00:47,020 --> 00:00:51,040
So colon com exclamation mark.

19
00:00:51,040 --> 00:00:55,050
This means define a command and override an existing one.

20
00:00:55,050 --> 00:01:00,030
Py is the name of the command and then exclamation mark

21
00:01:00,030 --> 00:01:03,000
to run an external command python,

22
00:01:03,000 --> 00:01:06,070
which is a command to run and give it the parameter percent.

23
00:01:06,070 --> 00:01:10,000
Percent is expanded to the name of the file.

24
00:01:10,000 --> 00:01:11,040
And Enter.

25
00:01:11,040 --> 00:01:13,010
And now we can use it.

26
00:01:13,010 --> 00:01:15,080
So colon Py, Enter.

27
00:01:15,080 --> 00:01:20,070
And we see that the output of hello Vim from our program

28
00:01:20,070 --> 00:01:24,000
and when we hit Enter, we're back in our code.

29
00:01:24,000 --> 00:01:25,000
Very handy.

30
00:01:25,000 --> 00:01:27,070
Don't forget to add this to your vimrc.

31
00:01:27,070 --> 00:01:29,060
You can do much more with commands.

32
00:01:29,060 --> 00:01:32,030
Write functions, accept arguments and more.

33
00:01:32,030 --> 00:01:35,000
With accommodation it is excellent.

