Skip to Content

Vim - tempname()

Posted on

Vim supports a function called tempname(), which gives us a random name. So if you want to create a temp file for note/ testing, we can use this function.

" Edit a temporary file
nnoremap <Leader><Leader>tp :exec "e " . tempname()<CR>

And if you want to save this content, you can use this command: :w path/to/file.extension. For example, if you want to save temp file to Desktop, just use command: :w ~/Desktop/test.rb

Readmore with :h tempname()

comments powered by Disqus