0

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>

Attempt3:

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

Attempt4:

function! YCMFormat()
    silent execute ":'<,'>YcmCompleter Format"
endfunction
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?

2
  • 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 at 12:00
  • @D.BenKnoble Thank you. You were absolutely correct. vmap <Leader>ft :YcmCompleter Format<CR> works like a charm !
    – Tryer
    Sep 3 at 12:44
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, privacy policy and cookie policy

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