=head1 NAME ranger - visual file manager =head1 SYNOPSIS B [B<--version>] [B<--help>] [B<--debug>] [B<--clean>] [B<--confdir>=I] [B<--copy-config>=I] [B<--choosefile>=I] [B<--choosefiles>=I] [B<--choosedir>=I] [B<--selectfile>=I] [B<--list-unused-keys>] [B<--list-tagged-files>=I] [B<--profile>] [B<--cmd>=I] [I] =head1 DESCRIPTION ranger is a console file manager with VI key bindings. =head1 RESOURCES I contains instructions on how to use and configure ranger. I, you can press I<1?> for a list of key bindings, I<2?> for commands and I<3?> for settings. The F contains install instructions. The file F contains guidelines for code modification. The directory F contains configuration files. They are usually installed to F and can be obtained with ranger's --copy-config option. The man page of rifle(1) describes the functions of the file opener The section I of this man page contains further resources. =head1 OPTIONS =over 14 =item B<-d>, B<--debug> Activate the debug mode: Whenever an error occurs, ranger will exit and print a full traceback. The default behavior is to merely print the name of the exception in the statusbar/log and try to keep running. =item B<-c>, B<--clean> Activate the clean mode: ranger will not access or create any configuration files nor will it leave any traces on your system. This is useful when your configuration is broken, when you want to avoid clutter, etc. =item B<-r> I, B<--confdir>=I Change the configuration directory of ranger from ~/.config/ranger to "dir". =item B<--copy-config>=I Create copies of the default configuration files in your local configuration directory. Existing ones will not be overwritten. Possible values: I, I, I, I, I, I. Note: You may want to disable loading of the global configuration files by exporting I in your environment. See also: B, B --copy-config=B will copy only a small sample configuration file with a thoroughly commented example. It is recommended to keep this file tidy to avoid getting defunct commands on ranger upgrades. The full default commands.py can be copied with --copy-config=B, but that file will be ignored by ranger and serves only as a reference for making your own commands. =item B<--choosefile>=I Allows you to pick a file with ranger. This changes the behavior so that when you open a file, ranger will exit and write the absolute path of that file into I. =item B<--choosefiles>=I Allows you to pick multiple files with ranger. This changes the behavior so that when you open a file, ranger will exit and write the absolute paths of all selected files into I, adding one newline after each filename. =item B<--choosedir>=I Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into I. =item B<--selectfile>=I Open ranger with I selected. =item B<--list-unused-keys> List common keys which are not bound to any action in the "browser" context. This list is not complete, you can bind any key that is supported by curses: use the key code returned by C. =item B<--list-tagged-files>=I List all files which are tagged with the given tag. Note: Tags are single characters. The default tag is "*" =item B<--profile> Print statistics of CPU usage on exit. =item B<--cmd>=I Execute the command after the configuration has been read. Use this option multiple times to run multiple commands. =item B<--version> Print the version and exit. =item B<-h>, B<--help> Print a list of options and exit. =back =head1 CONCEPTS This part explains how certain parts of ranger work and how they can be used efficiently. =head2 TAGS Tags are single characters which are displayed left of a filename. You can use tags however you want. Press "t" to toggle tags and "ut" to remove any tags of the selection. The default tag is an Asterisk ("*"), but you can use any tag by typing I<">. =head2 PREVIEWS By default, only text files are previewed, but you can enable external preview scripts by setting the option C and C to true. This default script is F<~/.config/ranger/scope.sh>. It contains more documentation and calls to the programs I and I for html, I for text/code, I for images, I for archives, I for PDFs and I for video and audio files. Install these programs (just the ones you need) and scope.sh will automatically use them. Independently of the preview script, there is a feature to preview images by drawing them directly into the terminal. To enable this feature, set the option C to true and enable one of the image preview modes: =head3 w3m This does not work over ssh, requires certain terminals (tested on "xterm" and "urxvt") and is incompatible with tmux, although it works with screen. To enable this feature, install the program "w3m" and set the option C to true. =head3 iTerm2 This only works in iTerm2 compiled with image preview support, but works over ssh. To enable this feature, set the option C to true. =head2 SELECTION The I is defined as "All marked files IF THERE ARE ANY, otherwise the current file." Be aware of this when using the :delete command, which deletes all files in the selection. You can mark files by pressing , v, etc. A yellow B symbol at the bottom right indicates that there are marked files in this directory. =head2 MACROS Macros can be used in commands to abbreviate things. %f the highlighted file %d the path of the current directory %s the selected files in the current directory. %t all tagged files in the current directory %c the full paths of the currently copied/cut files The macros %f, %d and %s also have upper case variants, %F, %D and %S, which refer to the next tab. To refer to specific tabs, add a number in between. (%7s = selection of the seventh tab.) %c is the only macro which ranges out of the current directory. So you may "abuse" the copying function for other purposes, like diffing two files which are in different directories: Yank the file A (type yy), move to the file B, then type @diff %c %f Macros for file paths are generally shell-escaped so they can be used in the C command. Additionally, if you create a key binding that uses , a special statement which accepts any key, then the macro %any (or %any0, %any1, %any2, ...) can be used in the command to get the key that was pressed. =head2 BOOKMARKS Type B> to bookmark the current directory. You can re-enter this directory by typing B<`>. can be any letter or digit. Unlike vim, both lowercase and uppercase bookmarks are persistent. Each time you jump to a bookmark, the special bookmark at key ` will be set to the last directory. So typing "``" gets you back to where you were before. Bookmarks are selectable when tabbing in the :cd command. Note: The bookmarks ' (Apostrophe) and ` (Backtick) are the same. =head2 RIFLE Rifle is the file opener of ranger. It can be used as a standalone program or a python module. It is located at F. In contrast to other, more simple file openers, rifle can automatically find installed programs so it can be used effectively out of the box on a variety of systems. It's configured in F through a list of conditions and commands. For each line the conditions are checked and if they are met, the respective command is taken into consideration. By default, simply the first matching rule is used. In ranger, you can list and choose rules by typing "r" or simply by typing "". If you use rifle standalone, you can list all rules with the "-l" option and pick a rule with "-p ". The rules, along with further documentation, are contained in F. =head2 FLAGS Flags give you a way to modify the behavior of the spawned process. They are used in the commands C<:open_with> (key "r") and C<:shell> (key "!"). f Fork the process. (Run in background) c Run the current file only, instead of the selection r Run application with root privilege (requires sudo) t Run application in a new terminal window There are some additional flags that can currently be used only in the C command: (for example C<:shell -w df>) p Redirect output to the pager s Silent mode. Output will be discarded. w Wait for an Enter-press when the process is done By default, all the flags are off unless specified otherwise in the F configuration file. You can specify as many flags as you want. An uppercase flag negates the effect: "ffcccFsf" is equivalent to "cs". The terminal program name for the "t" flag is taken from the environment variable $TERMCMD. If it doesn't exist, it tries to extract it from $TERM and uses "xterm" as a fallback if that fails. Examples: C<:open_with c> will open the file that you currently point at, even if you have selected other files. C<:shell -w df> will run "df" and wait for you to press Enter before switching back to ranger. =head2 PLUGINS ranger's plugin system consists of python files which are located in F<~/.config/ranger/plugins/> and are imported in alphabetical order when starting ranger. A plugin changes rangers behavior by overwriting or extending a function that ranger uses. This allows you to change pretty much every part of ranger, but there is no guarantee that things will continue to work in future versions as the source code evolves. There are some hooks that are specifically made for the use in plugins. They are functions that start with hook_ and can be found throughout the code. grep 'def hook_' -r /path/to/rangers/source Also try: pydoc ranger.api Note that you should NOT simply overwrite a function unless you know what you're doing. Instead, save the existing function and call it from your new one. This way, multiple plugins can use the same hook. There are several sample plugins in the F directory, including a hello-world plugin that describes this procedure. =head1 KEY BINDINGS Key bindings are defined in the file F. Check this file for a list of all key bindings. You can copy it to your local configuration directory with the --copy-config=rc option. Many key bindings take an additional numeric argument. Type I<5j> to move down 5 lines, I<2l> to open a file in mode 2, I<10> to mark 10 files. This list contains the most useful bindings: =head2 MAIN BINDINGS =over 14 =item h, j, k, l Move left, down, up or right =item ^D or J, ^U or K Move a half page down, up =item H, L Move back and forward in the history =item gg Move to the top =item G Move to the bottom =item [, ] Move up and down in the parent directory. =item ^R Reload everything =item ^L Redraw the screen =item i Inspect the current file in a bigger window. =item E Edit the current file in $EDITOR ("nano" by default) =item S Open a shell in the current directory =item ? Opens this man page =item W Opens the log window where you can review messages that pop up at the bottom. =item w Opens the task window where you can view and modify background processes that currently run in ranger. In there, you can type "dd" to abort a process and "J" or "K" to change the priority of a process. Only one process is run at a time. =item ^C Stop the currently running background process that ranger has started, like copying files, loading directories or file previews. =item =, +, - Change the permissions of the selection. For example, C<777=> is equivalent to C, C<+ar> does C, C<-ow> does C etc. =item yy Copy (yank) the selection, like pressing Ctrl+C in modern GUI programs. =item dd Cut the selection, like pressing Ctrl+X in modern GUI programs. =item pp Paste the files which were previously copied or cut, like pressing Ctrl+V in modern GUI programs. =item po Paste the copied/cut files, overwriting existing files. =item pl, pL Create symlinks (absolute or relative) to the copied files =item phl Create hardlinks to the copied files =item pht Duplicate the subdirectory tree of the copied directory, then create hardlinks for each contained file into the new directory tree. =item mI Create a bookmark with the name I =item `I Move to the bookmark with the name I =item n Find the next file. By default, this gets you to the newest file in the directory, but if you search something using the keys /, cm, ct, ..., it will get you to the next found entry. =item
when defined(nimHasLentIterators) and not defined(nimWorkaround14447):
  template lent2(T): untyped = lent T
else:
  template lent2(T): untyped = T

iterator items*[T: not char](a: openArray[T]): lent2 T {.inline.} =
  ## Iterates over each item of `a`.
  var i = 0
  while i < len(a):
    yield a[i]
    inc(i)

iterator items*[T: char](a: openArray[T]): T {.inline.} =
  ## Iterates over each item of `a`.
  # a VM bug currently prevents taking address of openArray[char]
  # elements converted from a string (would fail in `tests/misc/thallo.nim`)
  # in any case there's no performance advantage of returning char by address.
  var i = 0
  while i < len(a):
    yield a[i]
    inc(i)

iterator mitems*[T](a: var openArray[T]): var T {.inline.} =
  ## Iterates over each item of `a` so that you can modify the yielded value.
  var i = 0
  while i < len(a):
    yield a[i]
    inc(i)

iterator items*[IX, T](a: array[IX, T]): T {.inline.} =
  ## Iterates over each item of `a`.
  var i = low(IX)
  if i <= high(IX):
    while true:
      yield a[i]
      if i >= high(IX): break
      inc(i)

iterator mitems*[IX, T](a: var array[IX, T]): var T {.inline.} =
  ## Iterates over each item of `a` so that you can modify the yielded value.
  var i = low(IX)
  if i <= high(IX):
    while true:
      yield a[i]
      if i >= high(IX): break
      inc(i)

iterator items*[T](a: set[T]): T {.inline.} =
  ## Iterates over each element of `a`. `items` iterates only over the
  ## elements that are really in the set (and not over the ones the set is
  ## able to hold).
  var i = low(T).int
  while i <= high(T).int:
    if T(i) in a: yield T(i)
    inc(i)

iterator items*(a: cstring): char {.inline.} =
  ## Iterates over each item of `a`.
  when defined(js):
    var i = 0
    var L = len(a)
    while i < L:
      yield a[i]
      inc(i)
  else:
    var i = 0
    while a[i] != '\0':
      yield a[i]
      inc(i)

iterator mitems*(a: var cstring): var char {.inline.} =
  ## Iterates over each item of `a` so that you can modify the yielded value.
  when defined(js):
    var i = 0
    var L = len(a)
    while i < L:
      yield a[i]
      inc(i)
  else:
    var i = 0
    while a[i] != '\0':
      yield a[i]
      inc(i)

iterator items*[T: enum](E: typedesc[T]): T =
  ## Iterates over the values of the enum ``E``.
  for v in low(E) .. high(E):
    yield v

iterator items*[T](s: HSlice[T, T]): T =
  ## Iterates over the slice `s`, yielding each value between `s.a` and `s.b`
  ## (inclusively).
  for x in s.a .. s.b:
    yield x

iterator pairs*[T](a: openArray[T]): tuple[key: int, val: T] {.inline.} =
  ## Iterates over each item of `a`. Yields ``(index, a[index])`` pairs.
  var i = 0
  while i < len(a):
    yield (i, a[i])
    inc(i)

iterator mpairs*[T](a: var openArray[T]): tuple[key: int, val: var T<