官术网_书友最值得收藏!

Saving and closing files

Let's save our file! Execute the following command:

:w
Don't forget to hit Enter at the end of a command to execute it.

:w stands for write.

The write command can also be followed by a filename, making it possible to write to a different file, other than the one that is open. This will save the changes in a new file, and will change the current open file to a new one. Try it, using the following command: :w animal_farm_2.py .

Let's exit Vim and check if the file was indeed created. :q stands for quit. You can also combine write and quit commands to write and exit by executing :wq.

:q

If you made changes to a file and want to exit Vim without saving the changes, you'll have to use :q! to force Vim to quit. Exclamation mark at the end of the command forces its execution.

Many commands in Vim have shorter and longer versions. For instance, :e, :w, and :q are short versions of :edit, :write, and :quit. In the Vim manual, the optional part of the command is often annotated in square brackets ( []). For example, :w[rite] or :e[dit].

Now that we're back in our system's Command line, let's check the contents of a current directory, as seen in the following code:

$ ls
$ python3 animal_farm.py
$ python3 animal_farm.py cat dog sheep
In Unix,  ls lists contents of a current directory. python3 animal_farm.py executes the script using a Python 3 interpreter, and python3 animal_farm.py cat dog sheep passes three arguments (cat, dog, sheep) to our script.

The following screenshot shows what the three preceding commands should output:

主站蜘蛛池模板: 兰州市| 江西省| 丘北县| 江华| 道真| 米易县| 彩票| 洛阳市| 扎兰屯市| 隆子县| 静海县| 彭州市| 达拉特旗| 徐闻县| 唐海县| 上饶县| 师宗县| 棋牌| 白玉县| 富顺县| 合江县| 团风县| 偏关县| 叙永县| 泌阳县| 昌黎县| 靖西县| 原阳县| 海兴县| 平舆县| 施甸县| 抚宁县| 黄冈市| 岫岩| 黑山县| 醴陵市| 蒙山县| 乳源| 横山县| 张家口市| 纳雍县|