1
00:00:00,050 --> 00:00:02,040
- [Instructor] Vim can run external commands

2
00:00:02,040 --> 00:00:04,070
and capture their output.

3
00:00:04,070 --> 00:00:06,060
I'll be showing you commands that work

4
00:00:06,060 --> 00:00:08,070
mostly on Mac or Linux.

5
00:00:08,070 --> 00:00:10,090
To follow along on Windows you should install

6
00:00:10,090 --> 00:00:15,020
packages such as msys32 or Cygwin.

7
00:00:15,020 --> 00:00:16,090
We'll open Vim.

8
00:00:16,090 --> 00:00:20,070
I usually work in full screen mode to reduce distractions.

9
00:00:20,070 --> 00:00:22,040
To quickly see what the time is,

10
00:00:22,040 --> 00:00:24,030
I can use the date utility.

11
00:00:24,030 --> 00:00:26,080
So colon exclamation mark for running

12
00:00:26,080 --> 00:00:29,060
an external command and date.

13
00:00:29,060 --> 00:00:33,010
And I can see now that it's 10:57 in the morning.

14
00:00:33,010 --> 00:00:35,000
Say you would like to prepare an index file

15
00:00:35,000 --> 00:00:36,050
with a list of all the files.

16
00:00:36,050 --> 00:00:39,070
You can tell Vim to read the output of the command.

17
00:00:39,070 --> 00:00:44,010
In this case it will be ls or on Windows dir.

18
00:00:44,010 --> 00:00:45,070
So let's start.

19
00:00:45,070 --> 00:00:49,020
Edit, index.txt

20
00:00:49,020 --> 00:00:53,080
and then I for insert mode and list of files.

21
00:00:53,080 --> 00:00:57,060
And now escape to get back to normal mode.

22
00:00:57,060 --> 00:01:00,030
And now we do :r for read.

23
00:01:00,030 --> 00:01:02,030
But this time instead of reading from a file,

24
00:01:02,030 --> 00:01:03,040
we'll read from a command.

25
00:01:03,040 --> 00:01:06,040
So read :ls.

26
00:01:06,040 --> 00:01:07,040
And enter.

27
00:01:07,040 --> 00:01:09,060
And we have the list of files.

28
00:01:09,060 --> 00:01:13,010
Lets say vid:w then enter.

29
00:01:13,010 --> 00:01:16,050
Another option is to run a tool on the current file.

30
00:01:16,050 --> 00:01:18,050
For example when working with JSON

31
00:01:18,050 --> 00:01:21,050
sometimes you get everything in one line.

32
00:01:21,050 --> 00:01:24,030
E tebeka.json.

33
00:01:24,030 --> 00:01:26,060
This is the output from GitHub's rest api.

34
00:01:26,060 --> 00:01:28,010
It's hard to read.

35
00:01:28,010 --> 00:01:30,020
Let's use the jq utility

36
00:01:30,020 --> 00:01:32,090
which is a utility for working with JSON files.

37
00:01:32,090 --> 00:01:35,000
And you will need to install it first.

38
00:01:35,000 --> 00:01:40,020
So :current file, run it through the command

39
00:01:40,020 --> 00:01:43,010
jq. and enter.

40
00:01:43,010 --> 00:01:46,070
And now everything is indented and much easier to read.

41
00:01:46,070 --> 00:01:51,000
Once you're done looking you can use u to undo the changes.

42
00:01:51,000 --> 00:01:52,050
This is very handy.

43
00:01:52,050 --> 00:01:55,030
You can use the tidy utility for xml files.

44
00:01:55,030 --> 00:01:58,060
And Vim comes with the utility code xxd which will

45
00:01:58,060 --> 00:02:01,080
let you edit binary files inside Vim.

46
00:02:01,080 --> 00:02:03,080
There are many useful external commands

47
00:02:03,080 --> 00:02:05,080
on the Mac Linux system.

48
00:02:05,080 --> 00:02:09,000
Get to know them and Vim will be even more powerful.

