Skip to content

Automatically open file upon creation #1120

Closed

Description

@Cgboal

Is your feature request related to a problem? Please describe.
When you create a file, it gets put into the file list in alphabetical order which means you have to navigate down to the newly created file in order to open it.

Describe the solution you'd like
It would be great if nvim-tree could automatically open newly created files.

Activity

  1. kyazdani42 commented on Mar 29, 2022

    @kyazdani42
    Member

    you could do it yourself :)

    -- with relative path
    require"nvim-tree.events".on_file_created(function(file) vim.cmd("edit "..file.fname) end)
    -- with absolute path
    require"nvim-tree.events".on_file_created(function(file) vim.cmd("edit "..vim.fn.fnamemodify(file.fname, ":p")) end)
  2. Cgboal commented on Mar 29, 2022

    @Cgboal
    Author

    Ahh I saw the event in the man page but wasn't sure how to link it up, thank you.

  3. magoz commented on Oct 16, 2022

    @magoz

    It shows as deprecated.
    What's the new way of calling nvim-tree.events.on_file_created?

  4. alex-courtis commented on Oct 17, 2022

    @alex-courtis
    Member

    Take a look at :help nvim-tree-events.

    Event.FileCreated is the one.

  5. magoz commented on Oct 17, 2022

    @magoz

    Thank you!
    This worked for me:

    local api = require("nvim-tree.api")
    api.events.subscribe(api.events.Event.FileCreated, function(file)
      vim.cmd("edit " .. file.fname)
    end)
  6. alex-courtis commented on Jan 14, 2023

    @alex-courtis
    Member

    Fantastic! Could you please add this useful Recipe to the Wiki? Don't forget to credit yourself...

  7. magoz commented on Jan 15, 2023

    @magoz

    Done! :-)

  8. alex-courtis commented on Jan 16, 2023

    @alex-courtis
    Member

    Done! :-)

    Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions