Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Dec 20, 2021. It is now read-only.
/neotags.nvimPublic archive

Tag highlight in neovim

License

NotificationsYou must be signed in to change notification settings

c0r73x/neotags.nvim

Repository files navigation

Archived beacuse of lua rewritehttps://github.com/c0r73x/neotags.lua

neotags.nvim

A neovim plugin that generates and highlight ctags similar to easytags.

I wrote this because I didn't like that my vim froze when opening largeprojects.

Much of the plugin's speed boost comes from it's ability to filter tags atruntime. Only tags found in opened buffers are supplied to Neovim forhighlighting. Easytags, on the other hand, supplied all tags found recursivelyfor a whole project. For very large projects with possibly tens of thousands oftags, this made Neovim's parser grind to a halt. With the new method, the taglist is far more manageable.

Be warned that for such large projects it can take some time to process thelist of tags. Fortunately, this is done asynchronously and does not slow theeditor. Furthermore, it is only updated when either a new file is opened or thebuffer is saved. This infrequent time cost is made in place of constantlyforcing Neovim to do the same processing.

ScreenShot

Requirements

Neotags requires Neovim with if_python3, and psutil for Python3.If:echo has("python3") returns1 andpip3 list | grep psutil shows thepsutil package, then you're done; otherwise, see below.

You can enable Python3 interface and psutil with pip:

pip3 install neovim psutil

If tags processing is taking too long it may be advisable to use pypy3 inplace of python3. This is possible by addinglet g:python3_host_prog = 'pypy3'to your.vimrc. Be advised that it will be necessary to have the Neovimpython module and any modules required by any other Vim plugins installed forpypy3 as well (including psutil).

Configuration

There are several configuration options to tweak the processing behavior. Bydefault, to speed things up all standard autotools files (such as configure,Makefile.in, etc) are ignored by ctags. This behavior can be disabled with bysettingg:neotags_no_autoconf to0. Further filenames may be ignored byappending--exclude=foo to the ctags argument list (seeman ctags for moreinformation).

By default, a tags file is generated in a global directory for each directoryin which source files appear. If you would like to reduce the number of tagsfiles, and thereby conglomerate a project into one file, you may designate anydirectory as a "project" top directory using theNeotagsAddProject command.See below for details.

Optional C Extension

Because the original implementation in python can take a modestly long time forvery large projects, the section of code that does the tag filtering has beenrewritten in C. If used, this can quite dramatically decrease the waiting time,often by up to 4+ times.

It can be enabled simply by compiling it. Runmake in the root git directoryand the small project will be automatically configured, compiled, and installedinto~/.vim_tags/bin. The requirements are cmake, libpcre2, and of coursea working C compiler. All of these should be readily available on any Unix likeplatform. If you want to install it elsewhere feel free to configure and buildthe project yourself. It is also possible to configure with autotools byrunning the includedautogen.sh if you really prefer.

The build process can be easily automated with a package manager such as dein.Just add

call dein#add('c0r73x/neotags.nvim', {'build': 'make'})

to your .vimrc or init.nvim file and dein will handle the rest. To disable itafter installing either delete the binary or addlet g:neotags_bin = '' toyour setup.

As usual, on Windows things are more difficult. It is possible to compile withMinGW, but the resulting binary is usually slower than the original python! Ifyou have Visual Studio installed then it is possible to generate a project withcmake, provided that you can source a copy oflibpcre2-8.lib or similar fromsomewhere. There are no easily available pre-compiled version of this library,so you'll either have to compile it yourself or download MinGW and use itspre-compiled version (calledlibpcre2-8.dll.a). Put it in the same directoryas the topCMakeFiles.txt file and everything should work. There isn't anyshortcut around this, unfortunately.

If all of this seems like too much bother (especially for Windows users!) thenas mentioned the python version will work perfectly fine, and is probablyplenty fast enough for the majority of cases.

Commands

CommandDescription
NeotagsToggleToggle neotags on the fly
NeotagsAddProject <DIRECTORY>Add a directory to the global list of "project" top directories
NeotagsRemoveProject <DIRECTORYRemove a directry from the global list of "project" top directories
NeotagsAddProjectDirectory <DIRECTORY>Add an extra directory to the current "project"
NeotagsRemoveProjectDirectory <DIRECTORYRemove a directry from the current "project"
NeotagsBinToggleToggle usage of the compiled C binary

Options

OptionDescriptionDefault
g:neotags_enabledOption to enable/disable neotags0
g:neotags_directoryGlobal directory in which to store all generated tags files~/.vim_tags
g:neotags_settings_fileGlobal file in which to store all saved "project" directoriesg:neotags_directory/neotags.json
g:neotags_ignored_tagsList of tag names globally excluded from ever being highlighted (eg. tryNULL in C)""
g:neotags_no_autoconfAutomatically exclude all standard GNU autotools files (exceptMakefile) to speed up processing by having fewer tags1
g:neotags_events_updateList of vim events when to run tag generation and update highlightBufWritePost
g:neotags_events_highlightList of vim events when to update highlightBufEnter, BufReadPre
g:neotags_events_rehighlightList of vim events when to clear cache and update highlightSyntax, FileType
g:neotags_run_ctagsOption to enable/disable ctags generation from neotags1
g:neotags_highlightOption to enable/disable neotags highlighting1
g:neotags_recursiveOption to enable/disable recursive tag generation1
g:neotags_find_toolCommand (such asag -g) run in place ofctags -R to find files""
g:neotags_ctags_binLocation of ctagsctags
g:neotags_ctags_argsctags arguments--fields=+l --c-kinds=+p --c++-kinds+p --sort=no --extras=+q
g:neotags_ctags_timeoutctags timeout in seconds3
g:neotags_silent_timeoutHide message when ctags timeouts0
g:neotags_verboseVerbose output (for debug, must be set before neotags is starated)0
g:neotags_ignoreList of filetypes to ignore'text','nofile','mail','qf'
g:neotags_global_notinList of global syntax groups which should not include highlighting.'.&ast;String.&ast;', '.&ast;Comment.&ast;', 'cIncluded', 'cCppOut2', 'cCppInElse2', 'cCppOutIf2', 'pythonDocTest', 'pythonDocTest2'
g:neotags_ft_convDictionary of languages to convert between ctags and vim{ 'C++': 'cpp', 'C#': 'cs' }
g:neotags_ft_extDictionary of languages to convert between vim and file extensions{ 'python': ['py'], 'perl': ['pl', 'pm'], 'cpp': ['cpp', 'cxx', 'c', 'h', 'hpp'], 'c': ['c', 'h'], 'ruby': ['rb'], 'javascript': ['js', 'jsx', 'vue'], 'vue': ['js', 'vue'], 'typescript': ['ts', 'tsx'] }
g:neotags_tagfiles_by_typeUsesg:neotags_regex_tool andg:neotags_find_tool to only find files by extension(s)0
g:neotags_regex_toolRegex tool to use withg:neotags_tagfiles_by_typeag
g:neotags#c#orderGroup Name creation for the C languagecgstuedfpm
g:neotags#cpp#orderGroup Name creation for the Cpp languagecgstuedfpm
g:neotags#python#orderGroup Name creation for the Python languagemfc
g:neotags#ruby#orderGroup Name creation for the Ruby languagemfc
g:neotags#sh#orderGroup Name creation for the Shell languagefa
g:neotags#java#orderGroup Name creation for the Java languagecimegf
g:neotags#javascript#orderGroup Name creation for the Javascript languagecCfmpo
g:neotags#vim#orderGroup Name creation for the Vimscript languageacfv
g:neotags#perl#orderGroup Name creation for the Perl languages
g:neotags#php#orderGroup Name creation for the Php languagecfdi

Highlight Group Names

By default group name creation is set for all the different group names of all the supported languages.

C/Cpp

Default Highlight all groups:

letg:neotags#cpp#order='cgstuedfpm'letg:neotags#c#order='cgstuedfpm'
OptionGroup Name
ccppTypeTag
gcppTypeTag
scppTypeTag
tcppTypeTag
ucppTypeTag
ecppEnumTag
dcppPreProcTag
fcppFunctionTag
pcppFunctionTag
mcppMemberTag

C highlighting is identical to Cpp just removepp from the group name. Example,cTypeTag.With theg:neotags#cpp#order function you can restrict the highlighting to selected groups. SeeSpeed Improvementsbelow.

Vimscript

letg:neotags#vim#order='acfv'
OptionGroup Name
avimAutoGroupTag
cvimCommandTag
fvimFuncNameTag (Uses vimScriptFuncNameTag for local script functions)
vvimVariableTag

Python

letg:neotags#python#order='mfc'
LanguageGroup Name
mpythonMethodTag
fpythonFunctionTag
cpythonClassTag

Ruby

letg:neotags#ruby#order='mfc'
OptionGroup Name
mrubyModuleNameTag
frubyClassNameTag
crubyMethodNameTag

Shell / Zsh

letg:neotags#sh#order='fa'
OptionGroup Name
fshFunctionTag
ashAliasTag

Java

letg:neotags#java#order='cimegf'
OptionGroup Name
cjavaClassTag
ijavaInterfaceTag
mjavaMethodTag
ejavaEnumTag
gjavaEnumTypeTag
fjavaFieldTag

Javascript

letg:neotags#javascript#order='cCfmpo'
OptionGroup Name
cjavascriptClassTag
CjavascriptConstantTag
fjavascriptFunctionTag
mjavascriptMethodTag
pjavascriptPropsTag
ojavascriptObjectTag

Perl

letg:neotags#perl#order='s'
OptionGroup Name
sperlFunctionTag

Php

letg:neotags#php#order='cfdi'
OptionGroup Name
cphpClassesTag
fphpFunctionsTag
dphpConstantTag
iphpInterfaceTag
aphpInterfaceTag

Tips

To usethe_silver_searcher or similar applications when generating tags you can do something like this.

letg:neotags_recursive=1" Use this option for the_silver_searcherletg:neotags_find_tool='ag -g ""'" Or this one for ripgrep. Not both.letg:neotags_find_tool='ag --files'

Speed Improvements

Also on big projects syntax highlighting may become slow. To address this you can try:

setregexpengine=1

This provides significant speed improvements. In addition you set the highlight options for your language nothighlight everything but maybe only the tags your interested in the most. Example:

letg:neotags#cpp#order='ced'

The above will only highlightcppTypeTag, cppPreProcTag, cppEnumTag.

ptags

Neotags have support forptags by addingletg:neotags_ctags_bin = 'ptags' to your vimrc.

Do note that if you have your own custom settings forg:neotags_ctags_args youneed to prepend these with -c.Also since ptags do not support -L- theg:neotags_find_tool will be ignored. (-L was added in the latest version).

This is my setup using ptags for git repositories and ctags for other folders.

functions:neotagsCtagsCheck()ifsystem('git rev-parse --is-inside-work-tree')=~#'true'letg:neotags_ctags_bin='ptags'echom'Neotags using ptags'letg:neotags_ctags_args= [\'-c --fields=+l',\'-c --c-kinds=+p',\'-c --c++-kinds=+p',\'-c --sort=yes',\"-c --exclude='.mypy_cache'",\'-c --regex-go=''/^\s*(var)?\s*(\w*)\s*:?=\s*func/\2/f/''',\"-c --exclude='*Makefile'",\"-c --exclude='*Makefile.in'",\"-c --exclude='*aclocal.m4'",\"-c --exclude='*config.guess'",\"-c --exclude='*config.h.in'",\"-c --exclude='*config.log'",\"-c --exclude='*config.status'",\"-c --exclude='*configure'",\"-c --exclude='*depcomp'",\"-c --exclude='*install-sh'",\"-c --exclude='*missing'",\]elseletg:neotags_ctags_bin='ctags'echom'Neotags using ctags'letg:neotags_ctags_args= [\'--fields=+l',\'--c-kinds=+p',\'--c++-kinds=+p',\'--sort=yes',\"--exclude='.mypy_cache'",\'--regex-go=''/^\s*(var)?\s*(\w*)\s*:?=\s*func/\2/f/''',\"--exclude='*Makefile'",\"--exclude='*Makefile.in'",\"--exclude='*aclocal.m4'",\"--exclude='*config.guess'",\"--exclude='*config.h.in'",\"--exclude='*config.log'",\"--exclude='*config.status'",\"--exclude='*configure'",\"--exclude='*depcomp'",\"--exclude='*install-sh'",\"--exclude='*missing'",\]endifendfunctionaugroupNeotagsautocmdVimEnter*calls:neotagsCtagsCheck()augroupEND

Language conversion

Theneotags_ft_conv variable is used to convert for example C++ to cpp but itcan be used to convert custom filetypes to ctag filetypes.

For example this is what i use for flow

letg:neotags_ft_conv= {\'C++':'cpp',\'C#':'cs',\'JavaScript':'flow',\}

Note that you do need to copy the javascript neotags fileneotags.vim/plugin/neotags/javascript.vim toafter/plugin/neotags/flow.vimand do a replace for '#javascript' to '#flow'

Custom Rules

You can create custom rules for existing languages or new languages.

let g:neotags#[ctags language]#order = 'string with ctags kinds'let g:neotags#[ctags language]#[ctags kind] = { 'group': 'highlight' }

For more advanced rules, check the files inneotags.vim/plugin/neotags/*.vim.

You can get the list of kinds by runningctags --list-kinds=[language].

order determents priority of the highlight by first to last (tags with the same name will use the one with higher priority). Note that only kinds in the order string will be loaded.

For example, this is what I use in typescript/tsx

In ~/.ctags

--langdef=typescript--langmap=typescript:.ts--langmap=typescript:+.tsx--regex-typescript=/^[ \t]*(export([ \t]+abstract)?([ \t]+default)?)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\4/c,classes/--regex-typescript=/^[ \t]*(declare)?[ \t]*namespace[ \t]+([a-zA-Z0-9_]+)/\2/n,modules/--regex-typescript=/^[ \t]*(export)?[ \t]*module[ \t]+([a-zA-Z0-9_]+)/\2/M,modules/--regex-typescript=/^[ \t]*(export)?[ \t]*function[ \t]+([a-zA-Z0-9_]+)/\2/f,functions/--regex-typescript=/^[ \t]*export[ \t]+(var|let|const)[ \t]+([a-zA-Z0-9_]+)/\2/v,variables/--regex-typescript=/^[ \t]*(var|let|const)[ \t]+([a-zA-Z0-9_]+)[ \t]*=[ \t]*function[ \t]*\(\)/\2/V,varlambdas/--regex-typescript=/^[ \t]*(export)?[ \t]*(public|protected|private)[ \t]+(static)?[ \t]*([a-zA-Z0-9_]+)/\4/m,members/--regex-typescript=/^[ \t]*(export)?[ \t]*interface[ \t]+([a-zA-Z0-9_]+)/\2/i,interfaces/--regex-typescript=/^[ \t]*(export)?[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\2/t,types/--regex-typescript=/^[ \t]*(export)?[ \t]*enum[ \t]+([a-zA-Z0-9_]+)/\2/e,enums/--regex-typescript=/^[ \t]*import[ \t]+([a-zA-Z0-9_]+)/\1/I,imports/--regex-typescript=/^[ \t]*@([A-Za-z0-9._$]+)[ \t]*/\1/d,decorator/

In vimrc

letg:neotags#typescript#order='cnfmoited'letg:neotags#typescript#c= {'group':'javascriptClassTag' }letg:neotags#typescript#C= {'group':'javascriptConstantTag' }letg:neotags#typescript#f= {'group':'javascriptFunctionTag' }letg:neotags#typescript#o= {'group':'javascriptObjectTag' }letg:neotags#typescript#n=g:neotags#typescript#Cletg:neotags#typescript#f=g:neotags#typescript#fletg:neotags#typescript#m=g:neotags#typescript#fletg:neotags#typescript#o=g:neotags#typescript#oletg:neotags#typescript#i=g:neotags#typescript#Cletg:neotags#typescript#t=g:neotags#typescript#Cletg:neotags#typescript#e=g:neotags#typescript#Cletg:neotags#typescript#d=g:neotags#typescript#c

[8]ページ先頭

©2009-2025 Movatter.jp