Next: Viewing the Buffer, Previous: Buffers and Windows, Up: Vi Commands [Contents][Index]

### 2.4 Files

We have the following commands related to files. They are used to visit, save and insert files.

`v file RET`

  Visit specified file in the current window (`vip-find-file`).

`V file RET`

  Visit specified file in another window (`vip-find-file-other-window`).

`X S`

  Save current buffer to the file associated with the buffer. If no file is associated with the buffer, the name of the file to write out the content of the buffer will be asked in the minibuffer.

`X W file RET`

  Write current buffer into a specified file.

`X I file RET`

  Insert a specified file at point.

`g`

  Give information on the file associated with the current buffer. Tell you the name of the file associated with the buffer, the line number of the current point and total line numbers in the buffer. If no file is associated with the buffer, this fact will be indicated by the null file name ‘`""`’.

In Emacs, you can edit a file by visiting it. If you wish to visit a file in the current window, you can just type `v`. Emacs maintains the default directory which is specific to each buffer. Suppose, for instance, that the default directory of the current buffer is `/usr/masahiko/lisp/`. Then you will get the following prompt in the minibuffer.

    visit file: /usr/masahiko/lisp/

If you wish to visit, say, `vip.el` in this directory, then you can just type ‘`vip.el`’ followed by `RET`. If the file `vip.el` already exists in the directory, Emacs will visit that file, and if not, the file will be created. Emacs will use the file name (`vip.el`, in this case) as the name of the buffer visiting the file. In order to make the buffer name unique, Emacs may add a suffix (see Uniquify in The GNU Emacs Manual). As file name completion is provided here, you can sometimes save typing. For instance, suppose there is only one file in the default directory whose name starts with ‘`v`’, that is ‘`vip.el`’. Then if you just type `v TAB` then it will be completed to ‘`vip.el`’. Thus, in this case, you just have to type `v v TAB RET` to visit `/usr/masahiko/lisp/vip.el`. Continuing the example, let us now suppose that you wished to visit the file `/usr/masahiko/man/vip.texinfo`. Then to the same prompt which you get after you typed `v`, you can enter ‘`/usr/masahiko/man/vip.texinfo`’ or ‘`../man/vip.texinfo`’ followed by `RET`.

Use `V` instead of `v`, if you wish to visit a file in another window.

You can verify which file you are editing by typing `g`. (You can also type `X B` to get information on other buffers too.) If you type `g` you will get an information like below in the echo area:

    "/usr/masahiko/man/vip.texinfo" line 921 of 1949

After you edited the buffer (‘`vip.texinfo`’, in our example) for a while, you may wish to save it in a file. If you wish to save it in the file associated with the buffer (`/usr/masahiko/man/vip.texinfo`, in this case), you can just say `X S`. If you wish to save it in another file, you can type `X W`. You will then get a similar prompt as you get for `v`, to which you can enter the file name.

Next: Viewing the Buffer, Previous: Buffers and Windows, Up: Vi Commands [Contents][Index]