Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't the key combination Ctrl-K Ctrl-F work for php visual code?

I'm intending to format the selection (indentation) for the PHP code, but it does not work.

  • I already made sure that there aren't duplicate shortcuts.
  • I also disabled all extensions.
  • I changed the keyboard shortcut from Ctrl+K Ctrl+f to Ctrl+k Ctrl+y.

None of these helped.

Is the only language that does not work for me to format selection Eye. It's not because I'm missing the closing tag (?>).

enter image description here

like image 273
Labrador Avatar asked Nov 06 '22 16:11

Labrador


2 Answers

To see menu bar if not present press

Left Alt

then go:

Preferences > Keyboard Shortcuts

type in the search bar

ctrl+k ctrl+f

you should see

enter image description here

perhaps you have a collision and other command has the same shortcut defined or your shortcut is not defined at all. You can double click on shortcut to edit it.

Note at the picture When this is when the command works because one shortcut may work only if you are currently editing document and other when you are browsing files so once you set a shortcut make sure your checking it in different places of editor to see if its working or not.

If you use shortcut:

Ctrl+Shift+P

and select command:

enter image description here

You'll see whole bunch of shortcuts and there should be there one you are missing:

{ "key": "ctrl+k ctrl+f",         "command": "editor.action.formatSelection",
                                     "when": "editorHasDocumentSelectionFormattingProvider && editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly" },

I think that you can just copy the one above, paste to your file if it is not present and save that file, restart your Code and all should be working. Remember that the file is JSON so keep its format - look how other keys are presented there and your pasting should not make JSON invalid.

like image 81
Jimmix Avatar answered Nov 25 '22 22:11

Jimmix


.vue file doesn't have formate selection. This function depends on your file type.

like image 23
hellorayza Avatar answered Nov 25 '22 22:11

hellorayza