I am developing Laravel app with my favorite editor, Vim.
My compulsion used to be that I cannot jump to Laravel's magic method definitions such as getIsActiveAttribute
, and scopeIsActive
.
So I set proper ctags
configuration to jump to them by C-]
.
~/.ctags
--regex-php=/get([a-z|A-Z|0-9]+)Attribute/\1/
--regex-php=/scope([a-z|A-Z|0-9]+)/\1/
Then,
- Run
ctags
command in your project root. Recentctag
read our configuration file automatically. - Open a file with vim (of course)
- Set the cursor to a magic method
- Type
C-]
I strongly recommend customize your ctags
. I set the following configuration to jump to the definition of class method of JavaScript.
--langmap=javascript:.js.es6.es.jsx
--javascript-kinds=-c-f-m-p-v
--regex-javascript=/^[ \t]*([a-z]+[ \t]+)*class[ \t]+([A-Za-z0-9_]+)[ \t]*([^)])/\2/c,class,classes/
--regex-javascript=/^[ \t]*([a-z]+[ \t]+)*const[ \t]+([A-Za-z0-9_]+)[ \t]*([^)])/\2/c,const/
--regex-javascript=/^[ \t]*([a-z]+[ \t]+)*type[ \t]+([A-Za-z0-9_]+)[ \t]*([^)])/\2/c,type/
--regex-javascript=/^[ \t]*([a-z]+[ \t]+)*[ \t]+([A-Za-z0-9_]+) ?\(\)[ \t]*([^)])/\2/c,method/
--regex-javascript=/^[ \t]*([a-z|A-Z]+)\(\)/\1/
--regex-javascript=/^[ \t]*([a-z]+[ \t]+)*const[ \t]+([A-Za-z0-9_]+)[ \t]*([^)])/\2/c,class,classes/
Happy hacking with Vim!
Top comments (1)
Lovely stuff, although my editor (Atom) still wouldn't jump to the scope or accessor as the first character of the tag will be uppercase, and this doesn't match with the search term the cursor will be positioned at.
My solution was to prefix these tags with a placeholder.
Then post-process the tags using
sed
and convert the uppercase first character to lowercase.