- 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:
推薦閱讀
- HornetQ Messaging Developer’s Guide
- Building a Game with Unity and Blender
- 軟件架構設計:大型網站技術架構與業務架構融合之道
- Practical DevOps
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Securing WebLogic Server 12c
- Building Minecraft Server Modifications
- Python數據結構與算法(視頻教學版)
- Java語言程序設計教程
- HoloLens與混合現實開發
- Instant jQuery Boilerplate for Plugins
- Get Your Hands Dirty on Clean Architecture
- Python Linux系統管理與自動化運維
- IBM RUP參考與認證指南
- Python Automation Cookbook