How to save current new buffer (opened with :new) to other location, outside of vim_data (which is default vim working location)?

My default Vim working location in vimrc is set to ~/Desktop/vim_data

Let's visualize the folder structure like this:

 |- vim_data
 |  |- sub1                             
 |  |- sub2
 |- general data folder1
 |- general_data_folder2

Inside vim_data folder there are subfolders called: sub1 & sub2 current :pwd is in vim_data.

I want to save my current new buffer to general data folder1. How to I do that?

To open a file in other location is easy, I can just type :e .. or :Explore, but to save I have tried the method does not work.

  • 2
    Why not just :w /path/to/file.txt ? Or on Windows :w c:\path\to\file.txt
    – B Layer
    Commented Aug 26, 2020 at 23:41
  • yes, that works, but i have type and tap such a long nested location. since i am there in "sub1" , can't i use "..
    – andrew_ysk
    Commented Aug 27, 2020 at 19:56
  • 1
    If vim's CWD (current working dir) is vim_data then you should just be able to do :w ../general\ data\ folder1/filename. Note that the spaces are escaped with backslashes. If you use Tab completion you shouldn't even have to enter any of that. Start with :w ../g<Tab> for example.
    – B Layer
    Commented Aug 27, 2020 at 21:39
  • @BLayer thank you. that works.
    – andrew_ysk
    Commented Aug 28, 2020 at 20:55
  • Good to hear. I shouldn't leave an answer in the comments so I'll transfer it to a proper answer when I get a chance. Please check back so you can accept it and, if you'd like, upvote it. Thanks.
    – B Layer
    Commented Aug 28, 2020 at 21:15

2 Answers 2


if vim's CWD (current working dir) is vim_data then you should just be able to do

:w ../general\ data\ folder1/filename


*that the spaces between general data folder1 are escaped with backslashes. *If you use Tab completion (:w ../g<Tab>) you shouldn't even have to enter any of that backslashes \.

  • :w ../ dot dot here means "up one level" , same as in any os system. then type in the folder name that is located "outside" of CWD (of vim).
  • If you plan to keep working on more files in that directory, you can also use :cd ../general\ data\ folder1 command from inside Vim, then after that just :w filename will do.
    – filbranden
    Commented Sep 1, 2020 at 10:48
  • 3
    I usually go with :saveas so that Vim remembers the position and name the next time the file is sved Commented Sep 1, 2020 at 11:44
  • @ChristianBrabandt ':saveas' same as ':w' ? btw, how to make vim command as "code" like what you all made ?
    – andrew_ysk
    Commented Sep 3, 2020 at 22:39
  • 1
    :saveas is much like "Save as..." in most GUI apps. Whatever you specify becomes the new filename of the document you're editing (In Vim parlance it becomes the buffer's new filename). That doesn't happen with :w. BTW, I encourage you to get in the habit of using help as your primary source of info (:h :saveas, in this case). The answers are almost always there and you won't have to wait for someone's reply (if they even do reply). And the way to make "code" is surround the text with back-tics (usually same key as tilde '~'...at least for U.S. keyboards).
    – B Layer
    Commented Sep 4, 2020 at 6:04
  • @andrew_ysk the difference between :w some_other_file and :saveas some_other_file becomes apparent if you want to save again later. With :w some_other_file a following :w will write to the original file name, while after a :saveas some_other_file a following :w will continue to write as some_other_file. Commented Sep 4, 2020 at 6:44

I have windows so: :write .\filename.py will save the open buffer to the root of where you open nvim.

For example if you opened nvim like this:

C:\Users\Admin\Desktop\MyProject> nvim .

Then saving the file like this will save it to the MyProject folder: :write .\file.py.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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