• StarDreamer
    link
    fedilink
    English
    arrow-up
    11
    ·
    6 months ago
    :w !sudo tee %
    

    Warning: does not work for neovim

      • StarDreamer
        link
        fedilink
        English
        arrow-up
        2
        ·
        6 months ago

        Iirc the specific reason behind this is

        • sudo by default requires a tty to run
        • vim’s bang spawns a tty to execute commands
        • nvim’s bang executes the command directly, then pipes the output to nvim

        As a result, sudo (without args) can’t work in nvim as it doesn’t have a tty to prompt the user for passwords. Nvim also used to do what vim did, but they found out spawning the tty was causing other issues (still present in vim) so they changed it.