Question

Visual studio code, how to copy the file name

In the visual studio code, it has commands to Copy Path and Copy Relative Path (Ctrl+Shift+p->File: Copy Path of Active File). Is there a way I could copy the active file name instead of the whole path?

If there is no way copy the active file name. Is there a way I could write a script or something which creating a new command based on existing Copy Path and showing the new command in the Command Palette?

 46  40473  46
1 Jan 1970

Solution

 33

The extension Copy file name works like a charm! CTRL+ALT+F gives you filename and CTRL+ALT+E gives the filename.extension.

2019-09-24

Solution

 6

View the current file in the "Explorer" view and type F2 or Enter to select the filename text.

With VSCode 1.71 (Aug. 2022), you can type F2 and:

  • 1st press => prefix
  • 2nd press => all
  • 3rd press => suffix
  • 4th press => cycles back around to prefix

https://user-images.githubusercontent.com/4544166/184671196-01adb871-a666-4065-9ad4-57b752f1fecc.gif

Denis Howe mentions in the comments that, on macOS, it is Enter to select the filename text initially.
F2 works as described thereafter.

And you can open the explorer view with E / Shift-Crtl-E.

See kapex's answer.

2022-08-17