[英]VIM set ctags in .vimrc
I have my projects in /srv/http/dev folder. 我在/ srv / http / dev文件夹中有我的项目。 I generated ctags file for one project: 我为一个项目生成了ctags文件:
$ ctags -R --languages=php .
Now I set ctags path: 现在我设置ctags路径:
:set tags=/srv/http/dev/proj/tags
And it's working fine. 它工作正常。
But I have many projects in dev/ folder. 但我在dev /文件夹中有很多项目。 How can I set ctags in .vimrc file? 如何在.vimrc文件中设置ctags? set tags=tags
not working properly. set tags=tags
不能正常工作。
And I would like to generate tags file by pressing hotkey on selected NERDTree folder. 我想通过按下所选NERDTree文件夹上的热键来生成标签文件。 I tried: 我试过了:
nmap <silent> <F4>
\ :!ctags -R
\ --languages=php .<CR>
But it creates tags file in home folder and shows warnings about scanning home folder.. 但它会在主文件夹中创建标签文件并显示有关扫描主文件夹的警告。
EDIT: As @Alexandru Plugaru advised I should use g:NERDTreeFileNode.GetSelected() function. 编辑:正如@Alexandru Plugaru建议我应该使用g:NERDTreeFileNode.GetSelected()函数。
I am just newbie vim user, so I have one more question. 我只是新手vim用户,所以我还有一个问题。 I have added in my .vimrc file: 我在我的.vimrc文件中添加了:
function createTags()
let curNodePath = g:NERDTreeFileNode.GetSelected().path.str
exec ':!ctags -R --languages=php ' . curNodePath
endfunction
nmap <silent> <F4> :execute createTags()<CR>
But by pressing on F4 I see: 但按F4我看到:
E117: Unknown function: createTags
E15: Invalid expression: createTags
EDIT 2: Thanks to @Alexandru Plugaru I got this: 编辑2:感谢@Alexandru Plugaru我得到了这个:
function CreateTags()
let curNodePath = g:NERDTreeFileNode.GetSelected().path.str()
exec ':!ctags -R --languages=php -f ' . curNodePath . '/tags ' . curNodePath
endfunction
nmap <silent> <F4> :call CreateTags()<CR>
And it works! 它的工作原理! By pressing F4 I get tags file in project folder. 通过按F4我得到项目文件夹中的标签文件。
Functions are supposed to start with a capital letter. 函数应该以大写字母开头。 Change createTags
to CreateTags
. 将createTags
更改为CreateTags
。
To use project-specific tags
files you will need to add something like that to your .vimrc
: 要使用特定于项目的tags
文件,您需要在.vimrc
添加类似的内容:
set tags=./tags,tags;
so that Vim looks for a tags
file in the current directory first and up and up until it finds it. 这样Vim首先在当前目录中查找一个tags
文件,直到它找到它为止。 Additionnaly, I like to set autochdir
: the working directory is always the one containing the current file. 另外,我喜欢set autochdir
:工作目录始终是包含当前文件的目录。
That is because the current directory of vim is the home directory. 那是因为vim的当前目录是主目录。 You either need to change the path or create nerdtree plugin. 您需要更改路径或创建nerdtree插件。 See nerdtree_plugin directory for an example. 有关示例,请参阅nerdtree_plugin目录。 I think that you'll find this function interesting: 我认为你会发现这个功能很有趣:
g:NERDTreeFileNode.GetSelected()
in your .vimrc use: 在.vimrc中使用:
set tags+=tags,/srv/http/dev/proj/tags
I believe that comma is the proper separator. 我相信逗号是合适的分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.