How to create a new file / directory using ranger?
Solution 1
To create a directory in ranger, just type
:mkdir exampledir
or,
:touch examplefile
Solution 2
The accepted answer is correct, but someone might prefer to get these commands typed just by pressing one key. As @jaustin describes in his answer, one need to have keys mapped in ~/.config/ranger/rc.conf
config file.
If you copied default configuration files by
ranger --copy-config=all
then you already have the shortest access to mkdir
/ touch
:
-
F7 - mkdir (config:
map <F7> console mkdir%space
) -
Insert - touch (config:
map <INSERT> console touch%space
)
Mine current version of Ranger is 1.9.2.
BTW: extra space at the end of map c console touch␣
doesn't work. Only map c console touch%space
will work.
Solution 3
You can use :touch somefile
, but I prefer it mapped to a key.
:map c console touch
(note the extra space at the end)
Place this at the bottom of your ~/.config/ranger/rc.conf
minus the leading :
Solution 4
For creating a new file that you intend to immediately edit, using:
:edit new_file_name
is slightly faster. This will open the file in vim
. Note that you'd need to save it in vim
(e.g. with :w<CR>) before it appears (contrary to :touch
, which will create the file immediately).
![nolan](https://lh3.googleusercontent.com/-057mQApd3Tw/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3reS6rADLBs2yqH2100RFixyyVFVwg/photo.jpg?sz=256)
nolan
PHP / Devops by day. Haskell by night. I like Linux, Spacemacs, Dvorak, windows tiling managers. Music production, Bitcoin. Hopefully unconventional.
Updated on September 18, 2022Comments
-
nolan almost 2 years
I suppose I could use
mkdir
/touch
but I'm not sure if these would go in the current directory as viewed in ranger.