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

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:

主站蜘蛛池模板: 新疆| 常山县| 新蔡县| 华蓥市| 自贡市| 宁远县| 冷水江市| 衡阳市| 同江市| 临夏市| 乌拉特后旗| 常德市| 北宁市| 东方市| 涟水县| 巴马| 泸西县| 新余市| 渑池县| 枞阳县| 新田县| 内江市| 汶上县| 台北市| 麦盖提县| 高清| 蕲春县| 祁东县| 曲周县| 济南市| 仁布县| 上杭县| 达尔| 永泰县| 呼伦贝尔市| 专栏| 延寿县| 米泉市| 浮梁县| 区。| 桃园市|