There are several substitutes for margarine if you are on keto. You can take vegan butter like almond butter, avocado butter, or coconut butter to replace margarine. Also, peanut butter is a healthy substitute for margarine. Additionally, you can also use cream cheese, olive oil, MCT oil(coconut oil) instead of margarine.