Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim setting a default folder to store all txt files, how?

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

like image 586
elwoode Avatar asked Dec 04 '10 19:12

elwoode


2 Answers

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.

like image 149
GWW Avatar answered Nov 19 '22 00:11

GWW


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()
like image 40
Herbert Sitz Avatar answered Nov 18 '22 23:11

Herbert Sitz