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
- [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…
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)
Configuration files1m 57s
-
(Locked)
Challenge: Set line numbers5s
-
(Locked)
Solution: Set line numbers15s
-
(Locked)
Map keys1m 14s
-
(Locked)
Challenge: Map key6s
-
(Locked)
Solution: Map key19s
-
(Locked)
Abbreviations1m 47s
-
(Locked)
Challenge: Abbreviate email14s
-
(Locked)
Solution: Abbreviate email27s
-
(Locked)
Add commands1m 35s
-
Challenge: Create command15s
-
(Locked)
Solution: Create command27s
-
(Locked)
Various settings2m 46s
-
(Locked)
Challenge: Edit .vimrc10s
-
(Locked)
Solution: Edit .vimrc34s
-
(Locked)
-
-