vim icon indicating copy to clipboard operation
vim copied to clipboard

Add 'include' and 'define' patterns for vim9script in ftplugin/vim.vim

Open matteocoder opened this issue 2 years ago • 8 comments

The ftplugin for '.vim' files does not seem to have 'include' and 'define' patterns; adding them would enhance navigation across Vimscript files, at least for vim9script, by leveraging the language's "import" feature and Vim's native symbol navigation commands.

Describe the solution you'd like The following settings appear to be working for me, but suggestions and improvements are welcome:

setlocal include=\\v^\\s*import\\s*(autoload)?
setlocal define=\\v^(export)?\\s*def

Thank you for your attention.

matteocoder avatar Jul 05 '22 06:07 matteocoder

I personally use the following here: https://gist.github.com/bfrg/a7343cb63b4a7170a140e9b5b9326b23

bfrg avatar Jul 05 '22 08:07 bfrg

The ftplugin for '.vim' files does not seem to have 'include' and 'define' patterns; adding them would enhance navigation across Vimscript files, at least for vim9script, by leveraging the language's "import" feature and Vim's native symbol navigation commands.

Describe the solution you'd like The following settings appear to be working for me, but suggestions and improvements are welcome:

setlocal include=\\v^\\s*import\\s*(autoload)?
setlocal define=\\v^(export)?\\s*def

Good idea. There are more things that can be exported, this should cover them:

setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)

-- "I can't complain, but sometimes I still do." (Joe Walsh)

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \
/// \
\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

brammool avatar Jul 05 '22 12:07 brammool

I personally use the following here: https://gist.github.com/bfrg/a7343cb63b4a7170a140e9b5b9326b23

Hmm, I don't think ":command" needs to be found with 'define'. You can find commans with [i or jump to them with [<Tab>.

I'm not sure, but finding exported items only with [d seems useful.

-- hundred-and-one symptoms of being an internet addict: 54. You start tilting your head sideways to smile. :-)

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \
/// \
\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

brammool avatar Jul 05 '22 12:07 brammool

@brammool Should I open a pull request?

matteocoder avatar Jul 05 '22 17:07 matteocoder

@brammool Should I open a pull request?

This is what I have now:

" set 'include' to recognize import commands
setlocal include=\\v^\\s*import\\s*(autoload)?

" set 'define' to recognize export commands
setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)

Let me know if you prefer something else.

-- Keyboard not found. Think ENTER to continue.

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \
/// \
\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

brammool avatar Jul 05 '22 20:07 brammool

@brammool I'm ok with your solution. Thank you.

matteocoder avatar Jul 05 '22 20:07 matteocoder

Hmm, I don't think ":command" needs to be found with 'define'. You can find commands with [i or jump to them with [<Tab>.

Yes, you're right.

This is what I have now:

" set 'include' to recognize import commands setlocal include=\v^\simport\s(autoload)?

" set 'define' to recognize export commands setlocal define=\v^\sexport\s(def|const|var|final)

I think making export optional is helpful so that jumping to a script-local function or variable is possible.

bfrg avatar Jul 06 '22 20:07 bfrg

Hmm, I don't think ":command" needs to be found with 'define'. You can find commands with [i or jump to them with [<Tab>.

Yes, you're right.

This is what I have now:

" set 'include' to recognize import commands setlocal include=\v^\simport\s(autoload)?

" set 'define' to recognize export commands setlocal define=\v^\sexport\s(def|const|var|final)

I think making export optional is helpful so that jumping to a script-local function or variable is possible.

From inside one script? Then you can use "*" or "gD".

From another script items without "export" are not usable, thus finding them might be confusing. Strictly speaking, if there are two imported scripts, both defining a function Xfunc, but only one exports Xfunc, then the exported one should be found.

-- I got a new desk stapler. It broke on the first desk I tried.

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \
/// \
\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

brammool avatar Jul 07 '22 09:07 brammool

This was fixed in 5ed1153.

dkearns avatar Mar 04 '24 12:03 dkearns