vim ctrlp_使用Ctrlp和Ctag使Vim更智能

vim ctrlp

by _haochuan

通过_haochuan

使用Ctrlp和Ctag使Vim更智能 (Make Your Vim Smarter Using Ctrlp and Ctags)

I absolutely love Vim, and I use Vim for all my coding and writing from year to year. Although more are more people, especially for those are working with JavaScript, prefer modern code editors such as Sublime Text or VSCode, I’d rather spend a little time trying to make my toy more intelligent.

我绝对喜欢Vim,并且我每年都使用Vim进行所有编码和写作。 尽管有更多的人,特别是对于那些使用JavaScript的人,更喜欢诸如Sublime Text或VSCode之类的现代代码编辑器,但我还是愿意花一点时间来使我的玩具更智能。

CtrlP (CtrlP)

If you are a Sublime Text, Atom, or VSCode guy, you must use ctrl + p thousands of times to improve productivity. Well, don’t be jealous if you are a Vim guy because this fancy Vim plugin CtrlP will give you all you need.Check this official doc for installation and setup.

如果您是Sublime Text,Atom或VSCode方面的人,则必须使用ctrl + p数千次才能提高生产力。 好吧,如果您是Vim家伙,请不要嫉妒,因为这个花哨的Vim插件CtrlP会为您提供所需的一切。请查看此官方文档进行安装和设置。

标签 (Ctags)

Ctags is a tool that will sift through your code, indexing methods, classes, variables, and other identifiers, storing the index in a tags file. The tags file contains a single tag per line. Depending on command line arguments and the language ctags is run against, a lot of information can be obtained from this index.

Ctags是一种工具,可用于筛选代码,索引方法,类,变量和其他标识符,并将索引存储在标签文件中。 标签文件每行包含一个标签。 根据命令行参数和使用的语言ctags,可以从该索引中获取很多信息。

Ctags currently supports 41 programming languages, and it’s relatively easy to add definitions for more.

Ctags当前支持41种编程语言 ,并且添加更多的定义相对容易。

Ctags makes it much easier to navigate a larger project, particularly if the code you’re working with is unfamiliar. If you’re unsure of what a method does or how it’s supposed to be called, you can jump straight to its definition. If you’re in the downward spiral of a 500+ line Perl script and want to know where a variable was defined three hours ago, you can jump right back to it. And afterward, you can jump right back to where you were working.

Ctags使导航更大的项目变得容易得多,尤其是在您不熟悉所使用的代码的情况下。 如果不确定方法的作用或方法的调用方式,可以直接转到其定义。 如果您处于Perl脚本超过500行的螺旋式下降状态,并且想知道三个小时前在哪里定义了变量,则可以直接跳回到该变量。 然后,您可以跳回到工作地点。

You can install Ctags using Homebrew in OSX:

您可以在OSX中使用Homebrew安装Ctags:

brew install ctags

Please note that OS X comes with a Ctags executable, but it’s not exuberant-Ctags and is missing most of the useful features. If you see an error like Invalid Parameter when you run ctags, it means that the system is not using the one you installed with Homebrew. To solve this:

请注意,OS X带有Ctags可执行文件,但它不是旺盛的Ctags,并且缺少大多数有用的功能。 如果在运行ctags时看到诸如Invalid Parameter类的错误,则表明系统未使用您通过Homebrew安装的系统。 要解决这个问题:

$ alias ctags="`brew --prefix`/bin/ctags"

When you’re sitting in the directory you want to index, just run:

当您坐在要索引的目录中时,只需运行:

ctags -R.

Ctags will walk through the directory recursively, tagging all source files it encounters. For very large projects, this might take a while, but normally it’s pretty fast.

Ctags将递归遍历该目录,标记它遇到的所有源文件。 对于非常大的项目,这可能需要一段时间,但通常速度很快。

You may also need some extra config for Ctags, below is the ~/.ctags I'm using:

您可能还需要对Ctags进行一些额外的配置,以下是我正在使用的~/.ctags

--langmap=javascript:.js.es6.es.jsx--javascript-kinds=-c-f-m-p-v
--regex-javascript=/^[ \t]*(var|let|const)[ \t]+([A-Za-z0-9_$]+)[ \t]*=[ \t]*\[/\2/A,Array,Arrays/
--regex-javascript=/^[ \t]*(var|let|const)[ \t]+([A-Z][A-Za-z0-9_$]+)[ \t]*=[ \t]*function/\2/C,Class,Classes/--regex-javascript=/^[ \t]*class[ \t]+([A-Za-z0-9_$]+)/\1/C,Class,Classes/
--regex-javascript=/^[ \t]*export[ \t]?({[ \t]*)*([A-Za-z0-9_\*]*[ \t]as[ \t])([A-Za-z0-9_]+)/\3/E,Export,Exports/--regex-javascript=/^[ \t]*export[ \t]?({[ \t]*)*([A-Za-z0-9_\*]*[ \t]as[ \t])*([A-Za-z0-9_]+),[ \t]*([A-Za-z0-9_\*]*[ \t]as[ \t])([A-Za-z0-9_]+)/\5/E,export,Exports/--regex-javascript=/^[ \t]*export[ \t]?({[ \t]*)*([A-Za-z0-9_\*]*[ \t]as[ \t])*([A-Za-z0-9_]+),[ \t]*([A-Za-z0-9_\*]*[ \t]as[ \t])*([A-Za-z0-9_]+),[ \t]*([A-Za-z0-9_\*]*[ \t]as[ \t])([A-Za-z0-9_]+)/\7/E,Export,Exports/--regex-javascript=/^[ \t]*export[ \t]?(var|let|const)[ \t]+([A_Za-z0-9_$]+)/\2/E,Export,Exports/--regex-javascript=/^[ \t]*export[ \t]?(var|let|const)[ \t]+([A_Za-z0-9_$]+)[ \t]*[^,]+,[ \t]*([A_Za-z0-9_$]+)/\3/E,Export,Exports/--regex-javascript=/^[ \t]*export[ \t]?(var|let|const)[ \t]+([A_Za-z0-9_$]+)[ \t]*[^,]+,[ \t]*([A_Za-z0-9_$]+)[ \t]*[^,]+,[ \t]*([A_Za-z0-9_$]+)/\4/E,Export,Exports/
--regex-javascript=/^[ \t]*function[ \t]*([A-Za-z0-9_$]+)[ \t\(]/\1/F,Function,Functions/--regex-javascript=/^[ \t]*[\(]function[ \t]*([A-Za-z0-9_$]+)[ \t\(]/\1/F,Function,Functions/--regex-javascript=/^[ \t]*(var|let|const)[ \t]+([a-z][A-Za-z0-9_$]+)[ \t]*=[ \t]*function[^\*][^\*]/\2/F,Function,Functions/--regex-javascript=/^[ \t]*(var|let|const)[ \t]+([a-z][A-Za-z0-9_$]+)[ \t]*=[ \t]*\([^\*]/\2/F,Function,Functions/
--regex-javascript=/^[ \t]*function[ \t]*\*[ \t]*([A-Za-z0-9_$]+)/\1/G,Generator,Generators/--regex-javascript=/^[ \t]*(var|let|const)[ \t]+([a-z][A-Za-z0-9_$]+)[ \t]*=[ \t]*function([ \t]*\*)/\2/G,Generator,Genrators/--regex-javascript=/^[ \t]*(\*[ \t])([A-Za-z0-9_$]+)[ \t]*\(.*\)[ \t]*{/\2/G,Generator,Generators/
--regex-javascript=/^[ \t]*import[ \t]?({[ \t]*)*([A-Za-z0-9_\*]*[ \t]as[ \t])([A-Za-z0-9_]+)/\3/I,Import,Imports/--regex-javascript=/^[ \t]*import[ \t]?({[ \t]*)*([A-Za-z0-9_\*]*[ \t]as[ \t])*([A-Za-z0-9_]+),[ \t]*([A-Za-z0-9_\*]*[ \t]as[ \t])([A-Za-z0-9_]+)/\5/I,Import,Imports/--regex-javascript=/^[ \t]*import[ \t]?({[ \t]*)*([A-Za-z0-9_\*]*[ \t]as[ \t])*([A-Za-z0-9_]+),[ \t]*([A-Za-z0-9_\*]*[ \t]as[ \t])*([A-Za-z0-9_]+),[ \t]*([A-Za-z0-9_\*]*[ \t]as[ \t])([A-Za-z0-9_]+)/\7/I,Import,Imports/
--regex-javascript=/^[ \t]*this\.([A-Za-z0-9_$]+)[ \t]*=.*{$/\1/M,Method,Methods/--regex-javascript=/^[ \t]*([A-Za-z0-9_$]+)[ \t]*[:=][ \t]*[\(]*function[ \t]*\(/\1/M,Method,Methods/--regex-javascript=/^[ \t]*static[ \t]+([A-Za-z0-9_$]+)[ \t]*\(/\1/M,Method,Methods/--regex-javascript=/^[ \t]*([A-Za-z0-9_$]+)\(.*\)[ \t]*{/\1/M,Method,Methods/
--regex-javascript=/^[ \t]*(this\.)*([A-Za-z0-9_$]+)[ \t]*[:=].*[,;]*[^{]$/\2/P,Property,Properties/
--regex-javascript=/^[ \t]*(var|let|const)[ \t]+([A-Za-z0-9_$]+)[ \t]*=[ \t]*{/\2/O,Object,Objects/
--regex-javascript=/\/\/[ \t]*(FIXME|TODO|BUG|NOBUG|\?\?\?|\!\!\!|HACK|XXX)[ \t]*\:*(.*)/\1/T,Tag,Tags/
--regex-javascript=/^[ \t]*(var|let|const)[ \t]+([A-Za-z0-9_$]+)[ \t]*=[ \t]*[^\[{]*;$/\2/V,Variable,Variables/
--exclude=min--exclude=vendor--exclude=\*.min.\*--exclude=\*.map--exclude=\*.swp--exclude=\*.bak--exclude=tags--exclude=node_modules--exclude=bower_components--exclude=test--exclude=__test__--exclude=build--exclude=dist--exclude=*.bundle.*

Here is how it looks like going to function definition:

这是去函数定义的样子:

Also you can use Ctrlp to search for tags instead of files. To do this, first you need to map a shortcut in your .vimrc:

您也可以使用Ctrlp搜索标签而不是文件。 为此,首先需要在.vimrc映射一个快捷方式:

nnoremap <leader>. :CtrlPTag<cr>

Here is how it works:

下面是它的工作原理:

Hope it helps :)

希望能帮助到你 :)

I write code for audio and web, and play guitar on YouTube. If you want to see more stuff from me or know more about me, you can always find me in:

我编写音频和网络代码,并在YouTube上弹吉他。 如果您想从我这里了解更多信息或对我有更多了解,可以随时在以下位置找到我:

Website:https://haochuan.io/

网址: https//haochuan.io/

GitHub:https://github.com/haochuan

GitHub: https : //github.com/haochuan

Medium:https://medium.com/@haochuan

媒介: https//medium.com/@haochuan

YouTube: https://www.youtube.com/channel/UCNESazgvF_NtDAOJrJMNw0g

YouTube: https//www.youtube.com/channel/UCNESazgvF_NtDAOJrJMNw0g

翻译自: https://www.freecodecamp.org/news/make-your-vim-smarter-using-ctrlp-and-ctags-846fc12178a4/

vim ctrlp

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值