# how to save current new buffer (opened with :new) to other location, outside of current working location

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 folder structure like this:

~/Desktop > 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.

• Why not just :w /path/to/file.txt ? Or on Windows :w c:\path\to\file.txt Aug 26 '20 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 ".. Aug 27 '20 at 19:56
• 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. Aug 27 '20 at 21:39
• @BLayer thank you. that works. Aug 28 '20 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. Aug 28 '20 at 21:15

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 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. Sep 1 '20 at 10:48
• I usually go with :saveas so that Vim remembers the position and name the next time the file is sved Sep 1 '20 at 11:44
• @ChristianBrabandt ':saveas' same as ':w' ? btw, how to make vim command as "code" like what you all made ? Sep 3 '20 at 22:39
• :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). Sep 4 '20 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. Sep 4 '20 at 6:44