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

  • Mastering Vim
  • Ruslan Osipov
  • 281字
  • 2021-06-10 18:51:25

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:

主站蜘蛛池模板: 申扎县| 湘乡市| 固阳县| 万盛区| 扬中市| 乃东县| 昌都县| 庐江县| 磴口县| 沂源县| 漠河县| 河北省| 宁德市| 文水县| 高青县| 两当县| 新泰市| 鄱阳县| 视频| 桃园县| 平谷区| 化德县| 确山县| 同心县| 古浪县| 马山县| 怀柔区| 怀宁县| 丹巴县| 柘城县| 吉木乃县| 丰宁| 瑞金市| 江津市| 泉州市| 玛曲县| 泾川县| 阿拉善左旗| 安图县| 西安市| 斗六市|