I think you should use the function as below: function! BenIndent() let oldLine=line('.') normal! gg=G execute ':' . oldLine endfunction nnoremap -- :call BenIndent()<CR> Should work now I think. Here's what I changed from your function: fun -> function! BenIndent() " I've just always known functions to be declared this way, I may be wrong let oldLine=line('.') normal -> normal! gg=G " the ! sign tells vim to not remap the provided keys, e.g. if you map g to :q then vim would quit when indenting! execute ':' . oldLine endfun -> endfunction " just my convention map -> nnoremap -- :call BenIndent()<CR> " the ! sign tells vim to not remap the provided keys prefix of `->` is your code and suffix is mine.