According to this documentation

:'<,'>YcmCompleter Format

will format the selected text. I am struggling to map this to shortcut key <S-F2>.

I have tried all of the following after having visually line selected the lines:

Attempt1: vmap <S-F2> :YcmCompleter Format<CR>

Attempt2: nmap <S-F2> :YcmCompleter Format<CR>


function! YCMFormat()
    silent execute ":'<,'>YcmCompleter Format"
vnoremap <S-F2> :call YCMFormat()<CR>


function! YCMFormat()
    silent execute ":'<,'>YcmCompleter Format"
nnoremap <S-F2> :call YCMFormat()<CR>

None of the above work. After hitting these keys, the focus shifts to the bottom command line which displays:

Entering Ex mode.  Type "visual" to go to Normal mode.

Is there a way to correctly assign <S-F2> to format the visually selected lines?

  • 1
    Possibly your terminal and vim pair do not work with that key combo—try a regular key first and see if the mapping works
    – D. Ben Knoble
    Sep 3, 2021 at 12:00
  • @D.BenKnoble Thank you. You were absolutely correct. vmap <Leader>ft :YcmCompleter Format<CR> works like a charm !
    – Tryer
    Sep 3, 2021 at 12:44

1 Answer 1


As mentioned in the comments, <S-F2> may not work in some terminals or with some vims. Using another key solves the issue of binding it correctly: I would use something like

vnoremap <leader>f :YcmCompleter Format<CR>

But it might also be nice to set formatexpr or indentexpr instead.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.