简体   繁体   English

vim和NERD树扩展 - 添加文件

[英]vim and NERD Tree extension - adding a file

When using the vim editor with the NERDTree plugin to navigate through the tree of your project, is there an easy way to create a new source code file under the currently highlighted directory? 当使用带有NERDTree插件的vim编辑器浏览项目树时,是否有一种简单的方法可以在当前突出显示的目录下创建新的源代码文件?

Currently I go into my shell, add the file and then refresh the tree. 目前我进入我的shell,添加文件,然后刷新树。 There must be a better way. 肯定有更好的办法。

Activate the NERDTree and navigate to the directory in which the new file should live. 激活NERDTree并导航到新文件应存在的目录。 Then press m to bring up the NERDTree Filesystem Menu and choose a for "add child node". 然后按M键调出NERDTree文件系统菜单并选择 “附加子节点”。 Then simply enter the file's (or directory's name) and you're done. 然后只需输入文件(或目录的名称)就可以了。

From vim you can run shell commands. 从vim你可以运行shell命令。 So in this case I use: 所以在这种情况下我使用:

:!touch somefile.txt

and then hit r to reload the nerdtree window. 然后按r重新加载nerdtree窗口。

The other thing to do is to just start the new file from within vim. 另一件事是从vim中启动新文件。

:e somefile.txt

One handy thing for this is that in my .vimrc I auto change the cwd to the directory my current file is in: 一个方便的事情就是在我的.vimrc中我自动将cwd更改为我当前文件所在的目录:

" Auto change the directory to the current file I'm working on

autocmd BufEnter * lcd %:p:h 

This way if I'm editing a file and want another one in the same place the path is changed right there. 这样,如果我正在编辑文件并希望在同一个地方有另一个文件,那么路径就会在那里进行更改。 Opening any file from NERDTree sets the directory to the one that file is in. 从NERDTree打开任何文件会将目录设置为该文件所在的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM