I slightly modified your@Marcel's script. It did not workedwork for me, I could not tell why.
This is what I did :
#!/bin/bash
extension=$(echo $1 | rev | cut -d'.' -f1 | rev)
fName=$(basename $1 .$extension)
tmp=$(mktemp /var/tmp/$fName.XXXXXXXXXXXX.$extension)"
sudo cat "$1" > "$tmp"
( while true;do
changeControl=$(inotifywait -e modify "$tmp" 2>/dev/null)
sudo cp $tmp $1
done ) &
pid=$!
nvim $tmp
kill $pid
rm "$tmp"
The script extractextracts the extension of the source file and useuses it the for the temp file. This way, plugins like phpactor or intelephense still works.
Then it runruns the while in parallel and waitwaits for any change.
Anyway thanks Marcel for your primary proposition that leadled me to a solution.