Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass current file name to TermExec #12

Closed
oscarprabhakar opened this issue Mar 14, 2021 · 6 comments
Closed

Pass current file name to TermExec #12

oscarprabhakar opened this issue Mar 14, 2021 · 6 comments

Comments

@oscarprabhakar
Copy link

Is there. a way to pass the path of the current buffer (%) to the TermExec function like you can with the :terminal command?

@akinsho
Copy link
Owner

akinsho commented Mar 14, 2021

@oscarprabhakar when you say pass the path do you mean set the path of the terminal to that of the current buffer? in which case I'm working on that in #11 if not then can you clarify what you mean

@oscarprabhakar
Copy link
Author

No. I mean I would like to execute a shell command on the current file for which I would need the relative path of the file in the current buffer.

I could of course use toggleterm to open a new terminal and enter the command there and switch back, but it would be cool to do it in one command using the % register like so:

For e.g. to run unit tests in the current file I would like to run :TermExec mocha % —watch. The path of the current file would need to be replaced in place of the % sign. Currently it treats it like any other string.

This works: :!mocha % —watch
Also with floaterm: :FloatermNew mocha % —watch

@akinsho
Copy link
Owner

akinsho commented Mar 14, 2021

hmm I think you can do this on the commandline in vim without it needed to be built into the plugin tbh something like TermExec 'mocha '.expand('%').' -watch'. I think this is much easier to do directly via the command line rather than adding extra parsing to the command.

@oscarprabhakar
Copy link
Author

Alright. I guess I could easily put this into a mapping. I just thought there might have been an easier way to integrate this in the plugin as I see it supported in other plugins. I'm not familiar with Vim script or Lua or I would have offered to make a PR. Thanks for checking though :-)

@akinsho
Copy link
Owner

akinsho commented Mar 15, 2021

@oscarprabhakar I'd accept a PR that implemented this but, it would involve having to add logic to parse each term exec command looking for a % surrounded by spaces and tbh not sure which other commands for what languages might end up breaking because of that. It wouldn't be as trivial for me or anyone implementing this as just adding a mapping.

@oscarprabhakar
Copy link
Author

Yeah, I totally understand. Out of curiosity I checked the vim-floaterm plugin I mentioned earlier. It does indeed look like there is special handling of command line parameters, and it goes beyond the % register. See here

I have closed the issue. Thanks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants