Open-source News

A Linux file manager for Vim fans

opensource.com - Mon, 12/12/2022 - 16:00
A Linux file manager for Vim fans Seth Kenlon Mon, 12/12/2022 - 03:00

Ranger is a terminal-based file manager that uses Vim-like keyboard commands. If you're working in a terminal all day, running Sed and Awk commands and using Vim, then you might want a way to manage files without leaving the comforting glow of your amber-on-black screen. There are, of course, the ls and cd commands, but sometimes you want to "walk through" your system, or maybe you want to mimic a graphical experience without the graphics.

Install Ranger

On Linux, you may find Ranger in your Linux distribution's software repository. On Fedora, CentOS, Mageia, and similar:

$ sudo dnf install ranger

For instance, on Debian, Elementary, Linux Mint, and similar:

$ sudo apt install ranger

On macOS, use Homebrew or MacPort.

Using Ranger

If you use Vim, then Ranger is the terminal-based file manager for you. Sure, there's the NERDTree plugin for use while in Vim, but Ranger has all the conveniences of a file manager plus the interface conventions of Vim. If you don't know Vim (yet), then Ranger can serve as a nice introduction to the way Vim is operated.

Launch Ranger from a terminal:

$ ranger

Your terminal is now the Ranger interface, and by default, it lists the contents of your current directory.

Image by:

(Seth Kenlon, CC BY-SA 4.0)

By default, Ranger uses a three-column layout. From left to right:

  • List of home directories on your system.

  • List of directories.

  • Contents of the selected directory.

The basic interactions with Ranger can be performed with either your arrow keys or with the classic Vim navigation controls of the hjkl keys.

  • Up or K: Move to the previous item in a list, making it the active selection.

  • Down or J: Move to the next item in a list, making it the active selection.

  • Right or L: Move into a directory or open a file.

  • Left or H: Move to the parent directory.

If all you need to do is search for a file and open it, then you now know as much about Ranger as you need to know.

Of course, managing files is more than just navigating and opening files. The most common file management tasks have single-key shortcuts assigned to them, and you can view a complete list by pressing ? and then K for key bindings.

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles Select a file

You can select (or "mark," in Ranger terminology) a file or directory three different ways.

First, whatever happens to be highlighted in the Ranger window is considered the active selection. By default, any action you take is performed on your active selection. When you first launch Ranger, the active selection is probably the Desktop folder, which is usually at the very top of the list in your home directory. If you press the Left arrow, then you move into the Desktop folder and whatever item is at the top of that list becomes the active selection. This is the keyboard version of clicking on a file or folder in a graphical file manager.

The other way is to mark several files at once. To mark your current selection, press Spacebar. The item you've marked is indented one space and changes color, and your cursor is moved to the next item in the list. You can press Space again to select that item or move to a different item and press Space on it to add to your marked selection. This is the keyboard version of drawing a selection box around several items in a graphical file manager.

The third way is to select all items in a folder. To select everything, press v on your keyboard. To unselect everything, press v again.

Copy a file

To copy (or "yank," in Ranger terminology) your current selection (whether it's a single file or several files), press y y on your keyboard (that's the letter y twice in a row.)

To paste a file that you've copied, navigate to your target directory and press the p key twice in a row.

Move a file

To move a file from one location to another, press d twice in a row. Then move to your target location and press p twice.

Commands

In Ranger as in Vim, you can drop out of the normal mode of interaction to enter a command by pressing the : key.

For instance, say you've descended deep into a series of directories and subdirectories, and now you want to get to your Zombie_Apocalypse folder quickly. Press : and then type cd ~/Zombie_Apocalypse and press Return. You're instantly taken to the ~/Zombie_Apocalypse folder.

There are lots of commands to choose from, and you can see them all by pressing ? and then c for commands.

Tab

Ranger is a tabbed interface, just like your web browser. To open a new tab, press Ctrl+N. A tab number appears in the top right of the Ranger interface. To move between tabs, press Alt along with the number of the tab you want to switch to.

Split window

While the default view of Ranger is hierarchical columns, you can use an alternate view that splits the Ranger interface into two (or more) panels. This is useful for moving files from one directory to another quickly, or for comparing the contents of directories.

To split Ranger's interface, you change the view mode to multipane. This is done with the command set. To run a command in Ranger, you press : and then type your command:

:set viewmode multipane

When you split the Ranger interface, you're actually expanding tabs into one view. Instead of columns, you're now looking at two or more distinct single columns.

Image by:

(Seth Kenlon, CC BY-SA 4.0)

Instead of moving between these columns with Right and Left arrows (or h and l), you switch between tabs with Alt and a number. For instance, if you have three tabs open as split panes, the left column is Alt+1, the middle is Alt+2, and the right column is Alt+3.

A file manager for Vim users

Ranger is an obvious choice for you if you're a longtime Vim user, or if you just want to immerse yourself in the Vim style of working. The transition from Vim to Ranger and back again is nearly seamless, so fire up your favorite multiplexer and launch Ranger and Vim for easy access.

Use the Ranger file manager without leaving the comfort of your Linux terminal.

Linux What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Linux 6.1 Released With MGLRU, Initial Rust Code

Phoronix - Mon, 12/12/2022 - 06:32
Linus Torvalds just released Linux 6.1 as stable!..

Intel Preparing Virtual IA32_SPEC_CTRL Support For The Linux Kernel

Phoronix - Sun, 12/11/2022 - 21:53
Intel on Sunday posted a set of Linux patches implementing SPEC CTRL virtualization support for this VMX feature with new Intel CPUs to help with migrating virtual machines to hosts with different CPU microarchitectures where their security mitigations may be different...

More Rust Code Sent In For Linux 6.2 To Implement More Functionality

Phoronix - Sun, 12/11/2022 - 19:27
While Linux 6.1 merged the initial Rust infrastructure, in this kernel version set to be released as stable today there isn't any Rust-based functionality for end-users. With v6.1 it's just some of the initial code for building up the Rust programming language support and it's continuing that way for Linux 6.2. The pull request of more Rust enablement has already been sent out for the Linux 6.2 merge window...

AMD & Intel Sound Platform Updates For Linux 6.2 Along With Other Audio Updates

Phoronix - Sun, 12/11/2022 - 19:18
While the Linux 6.1 stable kernel isn't even being released until later today, there already have been a number of feature pull requests submitted for the upcoming Linux 6.2 kernel cycle. Due to the merge window being the two weeks leading up to Christmas, those with generous holiday/vacation time have been sending in their pull requests in advance. One of those early pull requests is all of the sound subsystem updates...

Pages