# vi editor and temporary swap files



## geodni (Oct 29, 2015)

Hello,
I am using FreeBSD 10.1-RELEASE-p6 in a VMWare 5.5 environment.
I have a problem configuring (my favorite editor) `vi` to use an alternate temporary directory when editing large files instead of full filling /var.
I created a alternate directory /opt/tmp on a big filesystem with same permissions drwxrwxrwt as /var/tmp owned by root:wheel.
I tried setting $TMPDIR environment variable in `sh`, `csh` and `tcsh` as normal user (inside wheel group) and as superuser root before editing file and making searches inside : no temporary file is created in /opt/tmp, all is done in /var/tmp/vi.recover/.
I tried setting into ~/.exrc

```
dir=/opt/tmp
"or
directory=/opt/tmp
```
and then editing the file, same result : no temporary file is created in /opt/tmp, all is done in /var/tmp/vi.recover/.
I opened the file with `vi` then immediately setting `dir`

```
:set dir=/opt/tmp
```
one empty temporary file is created in /opt/tmp but swap files are created in /var/tmp/vi.recover/.
Man page says :

```
directory, dir [environment variable TMPDIR, or /tmp]
  The directory where temporary files are created.
```
I read man pages and several articles about `vi` I used for years now, I found nothing about this strange behaviour. I tried many possibilities without success, is there another possibility or could it be an abnormal behaviour for FreeBSD 10 ?
I agree that `vi` is not the best way to make searches, `egrep` and `awk` are my favorites but sometimes I don't take time to use them.
Regards
Denis
PS : redited my post to use forum html editor, it's much more readable now.


----------



## tobik@ (Oct 29, 2015)

It works for me if I add this to ~/.nexrc:

```
:set recdir=/opt/tmp
```
 Got it from vi(1) where it says:

```
recdir [/var/tmp/vi.recover]
             The directory where recovery files are stored.
```
vi seems to use two kinds of temporary directories for whatever reason.


----------



## geodni (Oct 29, 2015)

Hi,
I use ~/.exrc
This option works well, thank you.
It seems `directory` directive has no effect, except writing an empty vi.aBcDeF inside the alternate temporary directory.
Denis


----------

