4

I have opened vim in a directory of code which contains long_name_module.py. My path variable is path+=** so the python file is visible to find.

I type

:find lo<tab>

and the filename is completed:

:find long_name_module.py

Given this state in the command panel is there a way to pipe this to a split or vsplit like

:find long_name_module.py | vs

To save returning to the start of the command, changing find to vs?

If there is a vfind like method that would be great to know but I'm also interested in a sequential way of achiving this.

  • 2
    :vertical sfind ... – Mass Jul 22 '19 at 21:12
  • @Mass Turn it into an answer? – filbranden Jul 22 '19 at 21:14
  • @Mass thank you! I'd also be interested to know if there's a pipe-like way to achive this if there is one – Noel Evans Jul 22 '19 at 21:16
  • @filbranden, OP said that the question is not exactly about ":vfind" but about ways to "chain" commands together (I guess with :execute).. but also about tab completion workflow – Mass Jul 22 '19 at 21:18
  • @Mass The vertical prefix is very useful. The other example I had was to force :e %:h (show netrw in current file's directory) in to a vertical split. And I see I can do this with :vertical edit %:h. I think given that my examples all send the output to a vsplit then you have given the answer – Noel Evans Jul 22 '19 at 21:26
2

For your particular case, you can use :vertical sfind, in which case you can Tab-complete the filename, same as you can do with :find.

Short version is:

:vert sf lo<TAB>

Which will complete to:

:vert sf long_name_module.py

And will open your file in a vertical split as you requested.


More generally, Vim doesn't really have a concept similar to "pipes" in the shell to compose arbitrary commands, so there isn't really a general way to accomplish what you described with general commands.

The closest concept to this in Vim is that of commands that execute other commands but modify their behavior as they run.

Some examples of such modifier commands are:

  • :vertical, which we just used in order to modify the way :sfind works and split vertically rather than horizontally.
  • :leftabove and :rightbelow, which also change how splits will work, more specifically where the next splits will open.
  • :noautocmd, to disable execution of auto-commands for a particular command execution.
  • :silent, which can silent the output of commands it executes.
  • :sandbox, to run a potentially untrusted command in a sandbox and contain its effects.

You can use many of these together. For example, :silent noautocmd vertical rightbelow call MyFunc() will execute the MyFunc() function, in silence, and if it splits to open a new file, it will be done vertically with a new split on the right, and no auto-commands will be executed for it. So, in a way, that's similar to how you'd chain multiple commands using pipes in a shell, right?

Note that for some particular cases, you end up with dedicated commands. For instance, there's not really a command modifier to open the next file in a new split, so you end up with :sfind (similar to :find), :new (similar to :enew), etc.

| improve this answer | |
  • 1
    As an added "bonus": vert sf **/lo*.py will autocomplete and cycle in sub-directories – ChatterOne Jul 24 '19 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.