Hash(#) is treated as normal character in vi and it depends in which context you are writing it.
In shell scripts, if you are assigning it to a variable, use single quote
password='kdjkkd#@123' # This is OK
What type of script are you writing?
Share the snippet as well.