Reputation: 95
I want to set it so that when I write a text file and save it - it is saved to a default folder called TEXT which will be in my main Vim folder eg. C:\Program Files\Vim\vim73\TEXT
at the moment they are saved by default in the vim73 folder mixed in with everything else. so if I type :W^M the file gets saved there and I want it to go to the folder named TEXT
Upvotes: 7
Views: 9166
Reputation: 31481
As GWW mentioned, you can add a cd
command to the _vimrc file. I found the proper format to use difficult to find. The path must not be enclosed in quotes, spaces must be escaped with a backslash, backslashes should not be escaped, and the path must end in a backslash. Here is an example:
cd C:\Documents\ and\ Settings\someUser\
I hope this helps.
Upvotes: 0
Reputation: 22226
Another possible approach would be to intercept the writing process with an autocmd for a writing event, probably BufWriteCmd. Have the autocmd function check to see if the file has a .txt extension (or whatever you use) and bypass the normal write process to save however/wherever you want. For docs see:
:h BufWriteCmd
Here's some code you could put in vimrc, not thoroughly tested to make sure behavior is exactly what you'd want, but it does basically work:
function! WriteTextFile()
execute 'write! c:\text\'.expand("%:p:t")
set nomodified
endfunction
au BufWriteCmd *.txt call WriteTextFile()
Upvotes: 3
Reputation: 17117
You can use abbrevations, if executed :w
it's automatically changes to the text below, I think that might help you.
cnorea w w! "C:\Program Files\Vim\vim73\TEXT"
Upvotes: -1
Reputation: 44093
When you save a file vim will default it to your current working directory. You can use the command :pwd
to verify this. To change it you can use :cd SomeDirectoryPath
.
You could also add the cd command to your .vimrc (or the equivalent for windows) to automatically change your current directory every time you start vim.
Upvotes: 10