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

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:

主站蜘蛛池模板: 长顺县| 邢台县| 得荣县| 内江市| 桦川县| 手机| 民乐县| 双鸭山市| 沐川县| 西青区| 武穴市| 巴林左旗| 璧山县| 乐东| 东台市| 祥云县| 务川| 安图县| 大足县| 雅安市| 海晏县| 象山县| 江源县| 宁城县| 吉林省| 天津市| 临猗县| 南部县| 哈尔滨市| 清水县| 枞阳县| 香格里拉县| 大英县| 陆丰市| 和平县| 五寨县| 吉首市| 德惠市| 阳西县| 景谷| 固始县|