From the course: Learning Vim
Read command - vi Tutorial
From the course: Learning Vim
Read command
- [Instructor] Say you're writing some Python code, vim hello.py. You decided to license your code under the Apache license. I need to add a header to every file. An easy solution is to write such a header and then read it into a file. To read the file, use :r. Since :r inserts the text under the current line, we first need to insert a new line. So, Shift + o and then escape and then :r and license header.txt and end. And now the delete the new line. So, K to move one line up and DD to remove the line. You can make it simpler if you use a motion command. We can use the minus one line, the previous line, as the location to insert the new line. Let's undo with :e! and enter. This will reload the file from the disk disregarding any changes we made to it. And now, :-1 and then read and then license header.txt and enter. If you start to find imperfects and hit Tab vim will complete the name for you. So, :-1r li and tab and we got the file name.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Windows and buffers1m 54s
-
(Locked)
Challenge: Buffer12s
-
(Locked)
Solution: Buffer28s
-
(Locked)
Edit files2m 12s
-
(Locked)
Challenge: Edit files10s
-
(Locked)
Solution: Edit files23s
-
(Locked)
Move between buffers1m 28s
-
(Locked)
Challenge: Switch buffer9s
-
(Locked)
Solution: Switch buffer22s
-
Read command1m 29s
-
(Locked)
Challenge: Insert file6s
-
(Locked)
Solution: Insert file13s
-
(Locked)
-
-
-