I know that in vim I can type
:terminal <command> %
to run a command on the file in the current edit buffer. For example and to simplify what I want to do let's take a simple ls command:
:terminal ls %
which will split the window, run the command and exit the shell while leaving the output on the screen. that's not what I want. I want it to run the command but leave me in the shell so I can run more bash commands potentially related to the current file/operation, then exit manually when I'm done.
If I simply type
:terminal
it brings me to a bash shell which allows me to type as many commands as I want which is great. BUT I then lose the ability to use the expansion facility of %, and the ease of spawning the terminal from the file I'm editing. ie. I lose the automation of the context provided by spawning from the original file/buffer which means I have to manually type in the current file name including potentially long path and or scroll previous bash history to rerun the original command. this is a waste of keystrokes.
Basically, I'm trying to find a way to create a vim map that lets me use % filename expansion in a bash command via :term
withOUT ending the job after the command is run (i prefer to be left in at a prompt in a shell to continue the session!)
I actually don't care if a solution just starts the :term
shell and echos my command with % filename expansion at the bash prompt without entering it.. that would allow me to still stay in bash after the command is executed by me with a manual carriage return.
I'm not sure if what I want to do is possible? note, I'm not looking to suspend my current edit session and fg back as it ties up the current editing session. I'm not sure if tmux - vim integration might provide a way to do what I want though I'd prefer to find a solution using straight-up :term
since it's a built-in feature and works well except for what I'm trying to achieve :)
:term
, although might be possible manually starting the terminal withterm_start()
and a handler for a proper option (see help forjob-options
). I must say, though, that the whole picture is not particularly straightforward. You want features from a constantly opened terminal (history, scroll to see previous commands) without opening a terminal. I'm failing to understand how keeping a new one open after each time you run a command would be more practical. – sidyll:term
, sometimes i like to RErun the script BUT then feed it different args from the command line. sometimes those args are files and i can add them to the scripts command line using bash tab completion or i can run find or other bash commands to find which files to specify as args. – robus:term
directly and i have a full shell which gets me 90% what i want. but if vim is NOT in the directory of my edited file, i have to find the file i'm currently editing. no context. just easier if % could be passed to shell and shell doesn't exit on it. make sense? – robus