windows Vim:更改启动目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1180955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:51:52  来源:igfitidea点击:

Vim: Change start up directory?

windowsvimworking-directory

提问by Nope

When I start GVim and start writing my little program I'd like to save the file to the Desktop but it seems that Vim is starting the command line in:

当我启动 GVim 并开始编写我的小程序时,我想将文件保存到桌面,但似乎 Vim 正在启动命令行:

C:\Windows\System32

How would I go about changing that to:

我将如何将其更改为:

C:\Users\Casey

so then I could just:

那么我可以:

:w Desktop\my_program.py

Thank you

谢谢

回答by Alex Martelli

Assuming you're starting gvim from an icon/shortcut in Windows (from the kind of paths you supply), you can change the starting directory (completely independent from the fact that it IS gvim: it would be the same from any other app!) by editing the "starting directory" property of that Windows icon/shortcut.

假设您从 Windows 中的图标/快捷方式启动 gvim(从您提供的路径类型),您可以更改起始目录(完全独立于它是 gvim 的事实:它与任何其他应用程序相同! ) 通过编辑该 Windows 图标/快捷方式的“起始目录”属性。

回答by Greg Hewgill

Within vim, you can change the current directory with the :cdcommand:

在 vim 中,您可以使用以下:cd命令更改当前目录:

:cd c:\users\casey

回答by Aaron

I found this way to be better:

我发现这种方式更好:

  1. Open gVim
  2. :cd $vim
  3. :e _gvimrc
  4. Add the following line:

    :cd c:\users\user\desktop\
    
  1. 打开 gVim
  2. :cd $vim
  3. :e _gvimrc
  4. 添加以下行:

    :cd c:\users\user\desktop\
    

I found that :Exis slow on large directories like c:\windows\system32\(where gVim usually starts).

我发现这:Ex在像c:\windows\system32\(gVim 通常开始的地方)这样的大目录上很慢。



Also, here is my full _gvimrcin case anyone is interested. I prefer Consolas for coding. The tabstop setting helps when coding especially in Python, and Ctrl+Tab/Ctrl+Shift+Tabis great for switching between buffers:

另外,这是我的完整_gvimrc,以防有人感兴趣。我更喜欢使用 Consolas 进行编码。tabstop 设置在编码时很有帮助,尤其是在 Python 中,并且Ctrl+ Tab/ Ctrl+ Shift+Tab非常适合在缓冲区之间切换:

set guifont=Consolas:h12:cANSI
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
map <C-Tab> :bnext<cr>
map <C-S-Tab> :bprevious<cr>
:cd c:\users\user\desktop\

回答by user3386110

How about changing your starting position?

改变你的起始位置怎么样?

vim icon -> right click -> property -> shortcut -> Start in -> your path you want to change.

vim icon -> right click -> property -> shortcut -> Start in -> your path you want to change.

but it works perfectly.

但它工作得很好。

I think :cd yourpath also works. but it will change when you don't want to change.

我认为 :cd yourpath 也有效。但是当你不想改变的时候它就会改变。

回答by octopusgrabbus

I found the following to be very useful. I am on Windows 7 and vim 7.3.46, and am using gVim.

我发现以下内容非常有用。我使用的是 Windows 7 和 vim 7.3.46,并且正在使用 gVim。

I edited startup settings, which wound up altering the _vimrc in c:\Users\me\.

我编辑了启动设置,最终改变了c:\Users\me\.

I also tried using :versionand editing the _vimrc files I found at $VIM, as well as the _vimrcI found at c:\windows\system32.

我还尝试使用:version和编辑我在 中找到的 _vimrc 文件$VIM,以及_vimrc我在c:\windows\system32.

Editing those files to include :cd c:\Users\medid not result in my default startup directory changing after starting vim. I wanted my default directory to be c:\Users\me\, and editing c:\Users\me\_vimrcachieved that. That is I entered

编辑这些文件以包含:cd c:\Users\me在启动 vim 后不会导致我的默认启动目录发生变化。我希望我的默认目录是c:\Users\me\,并通过编辑c:\Users\me\_vimrc实现了这一点。那是我进入

:e $MYVIMRC

:e $MYVIMRC

and added

并添加

cd c:\Users\cnorton.Arlington1\

cd c:\Users\cnorton.Arlington1\

to that file.

到那个文件。

回答by nightingale2k1

Use :cd c:\users\casey, after that save into session (in gVim there is button up and down in red, click on it and save as mySessionProject.vim). Next time you need to go to that directory, open that session (you can also use :source mySessionProject.vim)

使用:cd c:\users\casey,然后保存到会话中(在 gVim 中有红色的上下按钮,单击它并保存为mySessionProject.vim)。下次您需要转到该目录时,打开该会话(您也可以使用:source mySessionProject.vim

for command line:

对于命令行:

:mksession! yourdir/yourVimConfName.vim

to load

装载

:source yourDir/yourVimConfName.vim 

回答by RJ-

Just to to put this up incase anyone needs it: vimrc accepts enironmental parameters. you can put cd $USERPROFILEin your vimrc

只是为了以防万一有人需要它:vimrc 接受环境参数。你可以把cd $USERPROFILE你的vimrc