49

I wrote a little Vim function that moves the cursor to the first character of the current line. If the cursor was already on the first character, then the cursor is moved to the first column instead.

" Jump to first character or column noremap H :call FirstCharOrFirstCol()<cr> :function! FirstCharOrFirstCol() : let current_col = virtcol('.') : normal ^ : let first_char = virtcol('.') : if current_col == first_char : normal 0 : endif :endfunction 

How do I call this function silently? I’d rather ‘:call FirstCharOrFirstCol()’ wasn’t displayed in the status line. Simply changing to noremap H :silent call… doesn’t seem to be enough.

1
  • 10
    Just a small note: in a VimScript file (i.e. *.vim), you never need the leading : characters. Commented May 25, 2015 at 14:22

1 Answer 1

61

You can call the function silently by defining a silent map:

noremap <silent> H :call FirstCharOrFirstCol()<cr> 

For more info, see :h :map-<silent>. Note in particular that this will only ensure that the command is not echoed to screen when the mapping is executed. The :silent command is used to silence output from the function itself, and with a ! to silence all errors (see :h :silent).

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.