1

The problem:

I am getting nothing in return for the tempname() function in Vim. More specifically, I kept getting only ".do" assigned to the variable temp using the following statement.

 let temp = tempname() . ".do"
  • The complete function that fails to get itself a "temp name":

    let selectedLines = getbufline('%', line("'<"), line("'>"))
    if col("'>") < strlen(getline(line("'>")))
        let selectedLines[-1] = strpart(selectedLines[-1], 0, col("'>"))
    endif
    if col("'<") != 1
        let selectedLines[0] = strpart(selectedLines[0], col("'<")-1)
    endif
    let temp = tempname() . ".do"
    call writefile(selectedLines, temp)
    " *** CHANGE PATH AND NAME TO REFLECT YOUR SETUP. USE \\ INSTEAD OF \ ***
    exec "!start C:\\Vim\\vimfiles\\ftplugin\\Stata-Vim-Suite\\rundo.exe " . temp
    " Delete the temp file after Vim closes
    au VimLeave * exe "!del -y" temp
    

    (The above codeblock is supposed to be the body of function define withfun! RunDoLines() on line-1, and endfun on the last line.

Remark

This functions has been running very well for years, and it was only today that it should have failed on both of my Windows machines. (I use this function to send commands from Vim to the terminal of a statistical software.)

Things that I tried, but did not work

Related problems

  • Additionally, here goes the error message I get when trying to run PlugInstall through Vim-Plug. I think this should also be related with my setting for the TEMP files.

enter image description here

Minimal replication case:

Issuing the following set of commands does not get me any output.

:let temp_file = tempname()
:echo temp_file

Here goes a screenrecord demonstrating the problem:

enter image description here

  • What if you set $TMP? let $TMP = $HOME or some other convenient path? – muru Apr 4 '17 at 5:32
2

Simple and short solution

In .vimrc, drop the following line; and create temp_dir in the home directory.

let $TMP=$HOME . "/temp_dir"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.