Search code examples
vimvi

How to get username in vi/vim editor?


I am trying to get the find the username/fullname of the current user who invoked the vi/vim editor.

:autocmd bufnewfile *.sh exe "1," . 10 . "g/AUTHOR :.*/s//AUTHOR : " .getlogin() 

I tried using getlogin(), getuser(), getpwnam() but nothing worked.


Solution

  • As suggested by others, the following worked for me:

    autocmd Bufwritepre,Filewritepre *.c,*.vim,*.py,*.sh exe "silent 1," . num_header_lines . "g/MODIFIED BY :.*/s/MODIFIED BY :.*/MODIFIED BY : " . $USER