To exit Vi/Vim, use the :q command and hit [Enter] . To save a file and exit Vi/Vim simultaneously, use the :wq command and hit [Enter] or :x command.
More Info: https://linuxapt.com/blog/5-how-to-exit-vim-text-editor-command