7

I want to rename a file in GUI. I know I can either RightClick > Rename OR press F2, but I know in Chrome OS you can just type Ctrl+Enter in the Files app, and it will do that.

Is anything similar to this possible in Ubuntu? Is there any keyboard shortcut other than F2 that will allow one to rename a file in GUI?

Or, if not, then is there a way for me to set a custom keyboard shortcut for this as Ctrl+Enter, like in Chrome OS? I know currently trying Ctrl+Enter will only do the same thing as just typing Enter.


Specs

  • Make & Model: Dell Inspiron N5010
  • Operating System: Ubuntu 15.04
  • File Manager1: Files [the default one included in Unity]
  • GUI Environment2: Unity

1 I don't even think this matters, does it?

2 Is it redundant to say "GUI Environment"?

AEM
  • 1,166

3 Answers3

8

I'm using Gnome instead of Unity, but they should be the same (more or less).

Nautilus (a.k.a. Files) keeps its keyboard shortcuts in ~/.config/nautilus/accels

File Rename is listed there as:

; (gtk_accel_path "<Actions>/DirViewActions/Rename" "F2")

The ; means that it is commented out and Nautilus uses the system default.

If you remove the ; and change the line to:

(gtk_accel_path "<Actions>/DirViewActions/Rename" "<Primary>Return")

Then File Rename will be changed to Control-Enter.

It seems that there is only one shortcut possible for each operation. Nautilus uses the last one listed.
So you can't have F2 and Control-Enter at the same time.

In order for the changes to take effect you have to stop nautilus. Run the following from the commandline (before you make the change):

nautilus -q

Detailed steps (on request):

  • open Files ('Nautilus')

  • browse to directory .config/nautilus in your home directory

  • if you don't see directories starting with a dot, press <Ctrl>H or in the preferences for Files ('Nautilus'), tick the box for displaying hidden files.

  • right-click or double-click file accels so that it opens in an editor (likely gedit)

  • Alternatively, hit <Alt>F2 and give command: gedit ~/.config/nautilus/accels

Now we have the configuration file in an editor, we have to stop Files ('Nautilus') before we can make changes. Again, two ways of doing this:

  • Option 1: open a terminal window (Gnome Terminal) and kill nautilus, by issuing command: nautilus -q. Your Files window(s) should all disappear
  • Option 2: hit <Alt>F2 and give command nautilus -q. Your Files window(s) should all disappear

Now Files ('Nautilus') has been stopped, we can make changes to its configuration files.

  • In the editor, make the changes as listed above and save the file
  • Exit the editor

If you now open Files ('Nautilus') again, your changes should take effect


Answers to foot notes:

  1. It is relevant to specify the application you're having a problem with. In this case, it was the configuration of the application as opposed to a system setting that had to be modified to resolve this issue.
  2. People will know what you mean by GUI Environment. It is however generally referred to as GUI or Desktop in this context.
waldyrious
  • 2,197
NZD
  • 3,231
  • By the way, a few questions: (1) What do you mean by "commented out"? – SarahofGaia Nov 12 '15 at 17:27
  • (2) What does <primary> mean? Nothing comes up if I search for that on Wikipedia. – SarahofGaia Nov 12 '15 at 17:28
  • (3) Damn, it'd be nice to have both F2 and Ctrl+Enter. Still, it's just as nice to even just have Ctrl+Enter! :D – SarahofGaia Nov 12 '15 at 17:28
  • @SarahofGaia (1)Commented out means that the line has no effect. The ; tells Nautilus to ignore everything that follows it. Nautilus will then use its default setting, which is F2 – NZD Nov 12 '15 at 19:56
  • @SarahofGaia (2) <Primary> is the GTK name for the Control key. See http://unix.stackexchange.com/a/168516/121614 – NZD Nov 12 '15 at 20:07
  • @SarahofGaia (3) It might be possible to bind a function to multiple key combination, but I don't know enough about the configuration syntax to answer that. – NZD Nov 12 '15 at 20:09
  • (1) Oh, I see. Sort of like the # syntax for commenting in an HTML document, right? – SarahofGaia Nov 18 '15 at 17:50
  • (2) Ah, so correct me if I'm wrong, but then Ctrl is not a Windows-proprietary, nor has ever been a Windows-proprietary key label, correct? – SarahofGaia Nov 18 '15 at 17:54
  • (3) Neither do I. Lol. I'll just make do with having just Ctrl+Enter. ;) – SarahofGaia Nov 18 '15 at 17:59
  • @SarahofGaia (1) Comments in an HTML document are enclosed in <!-- and -->, Bash and most configuration files use # to introduce a comment. And, yes ; has the same function as these comment delimiters in HTML (2) Primary is a GTK+ thing, for details see this post on UL – NZD Nov 18 '15 at 18:40
  • (1) Oh, yeah, you're right. Oops! Lol. I got that mixed up from Python. xD – SarahofGaia Nov 20 '15 at 01:26
  • (2) Didn't you already suggest that link above at 2015-11-12T20:07Z? – SarahofGaia Nov 20 '15 at 01:26
  • @SarahofGaia (2) Yes, you're right - same link. Still useful ;-) I do have another link for you though on Wikipedia - Modifier Key – NZD Nov 20 '15 at 01:33
  • Really, now. :3 Another link? You shouldn't have. °∪° – SarahofGaia Nov 20 '15 at 01:43
  • By the way, is the above directions supposed to be done in the file manager or the terminal? Sorry for being a doofus. °∩° – SarahofGaia Nov 20 '15 at 14:33
  • 1
    @SarahofGaia See amended instructions in the post. – NZD Nov 20 '15 at 19:43
  • By the way, Just as a bonus, could you answer a few more questions? – SarahofGaia Nov 22 '15 at 19:30
  • (1) The footnote questions. – SarahofGaia Nov 22 '15 at 19:30
  • (2) Is this abnormal or bad? :{ – SarahofGaia Nov 22 '15 at 19:31
  • @SarahofGaia (1) I've answered your foot notes as well. (2) This is nothing to worry about. It very likely only happens when Nautilus is not running. A lot of GTK+ programs generate a lot of errors and warnings when run from the commandline. See the answers to this post – NZD Nov 22 '15 at 20:04
  • (1) Indeed, you have. Thank you. °◡° (2) Okay, I see. – SarahofGaia Nov 24 '15 at 19:44
  • Followup to Footnote Responses: (1) "People will know what you mean by GUI Environment." I realise now that technically it wasn't redundant since there are also TUI environments, not just GUI. (2) "It is however generally referred to as GUI or Desktop in this context." Isn't "desktop" most often used to refer to the desktop? – SarahofGaia Nov 24 '15 at 19:59
  • 1
    @SarahofGaia In 'colloquial speech' they are often used interchangeable. E.g. someone could ask you what GUI you are using and you could say that you are using the Gnome desktop of the XFCE desktop. Also see this UL post – NZD Nov 25 '15 at 06:30
5

ALT+Enter worked for me in the File Navigator, but then you have to use ESC to close.

zx485
  • 2,426
jjjjjj
  • 151
1

Similar to Bring BackSpace back to nautilus (3.18+) once and for all!. We can use the same fix for Ubuntu 18.04+ (Nautilus 3.26+) to set the shortcut keys for rename.

1) Install Nautilus Python

apt-get install python-nautilus

2) Download Backspace-Back.py from Nautilus-backspace and put it in ~/.local/share/nautilus-python/extensions:

mkdir ~/.local/share/nautilus-python
mkdir ~/.local/share/nautilus-python/extensions
wget https://raw.githubusercontent.com/riclc/nautilus_backspace/master/BackspaceBack.py ~/.local/share/nautilus-python/extensions/BackspaceBack.py

3) Make a copy of the file (or rename) for the purposes of making a new shortcut (or put it all in that one file).

cp BackspaceBack.py Rename.py

4) Edit Rename.py and modify the line in the file that starts with app.set_accels_for_action to the following:

app.set_accels_for_action( "view.rename", ["<control>Return"] )
app.set_accels_for_action( "view.open-item-new-tab", [] )

5) Restart Nautilus (killall nautilus)

Note that "open-item-new-tab" also has to be modified to free up the Control+Return key combination and then reassign it to "rename".

You can use this to change any shortcut in Nautilus. The complete list of current shortcuts and their defaults can be pulled from the source code for Nautilus (search for nautilus_application_set_accelerator).