开发者

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 w开发者_开发问答ill 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


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.


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()


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.


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜