0

Say that we have a function:

function StripTrailingWhitespace()
  if !&binary && &filetype != 'diff'
    normal mz
    normal Hmy
    %s/\s\+$//e
    normal 'yz<CR>
    normal `z
  endif
endfunction

How to map this function to StripTrailingWhiteSpace command so that we can run :StripTrailingWhiteSpace instead of :call StripTrailingWhiteSpace() ?

How to do the same for functions with arguments ?

The reason for doing that is: we get commands as completion window of fzf/vim-clap/coc plugins. And it's more align with vscode's cmd+shift+p functionality.

1 Answer 1

3

The :command command is what you are looking for.

Please read :h command for details. E.g. range handling, arguments handling etc.

In your case:

command! StripTrailingWhiteSpace call StripTrailingWhiteSpace()
Sign up to request clarification or add additional context in comments.

1 Comment

! Is probably not necessary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.