# Copyright (C) 2009, 2010 Roman Zimbelmann # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ This is the default key configuration file of ranger. Syntax for binding keys: map(*keys, fnc) Examples for keys: "x", "gg", "", "", "" fnc is a function which is called with the CommandArgs object. The CommandArgs object has these attributes: arg.fm: the file manager instance arg.wdg: the widget or ui instance arg.n: the number typed before the key combination (if allowed) arg.keys: the string representation of the used key combination arg.keybuffer: the keybuffer instance Direction keys are special. They must be mapped with: map.dir(*keys, **args) where args is a dict of values such as up, left, down, right, absolute, relative, pages, etc... Example: map.dir('gg', to=0) Direction keys can be accessed in a mapping that contians "". Example scenario ---------------- If this keys are defined: map("dd", "d", fm.cut(foo=bar)) map.dir("gg", to=0) Type in the keys on the left and the function on the right will be executed: dd => fm.cut(foo=bar) 5dd => fm.cut(foo=bar, narg=5) dgg => fm.cut(foo=bar, dirarg=Direction(to=0)) 5dgg => fm.cut(foo=bar, narg=5, dirarg=Direction(to=0)) 5d3gg => fm.cut(foo=bar, narg=5, dirarg=Direction(to=3)) """ from ranger.api.keys import * from ranger import log # =================================================================== # == Define keys for everywhere: # =================================================================== map = global_keys = KeyMapWithDirections() map('Q', fm.exit()) map('', fm.redraw_window()) map('', alias='') # Backspace is bugged sometimes #map('', wdg.move()) @map('') # move around with direction keys def move(arg): arg.wdg.move(narg=arg.n, **arg.direction) # -------------------------------------------------- direction keys map.dir('', down=1) map.dir('', down=-1) map.dir('', right=-1) map.dir('', right=1) map.dir('', down=0, absolute=True) map.dir('', down=-1, absolute=True) map.dir('', down=1, pages=True) map.dir('', down=-1, pages=True) map.dir('%', down=1, percentage=True, absolute=True) # =================================================================== # == Define aliases # =================================================================== map = vim_aliases = KeyMapWithDirections() map.dir('j', alias='') map.dir('k', alias='') map.dir('h', alias='') map.dir('l', alias='') map.dir('gg', alias='') map.dir('G', alias='') map.dir('', alias='') map.dir('', alias='') map = readline_aliases = KeyMapWithDirections() map.dir('', alias='') map.dir('', alias='') map.dir('', alias='') map.dir('', alias='') map.dir('', alias='') map.dir('', alias='') # =================================================================== # == Define keys in "general" context: # =================================================================== map = keymanager['general'] map.merge(global_keys) map.merge(vim_aliases) map('gg', fm.move(to=0)) # --------------------------------------------------------- history map('H', fm.history_go(-1)) map('L', fm.history_go(1)) # ----------------------------------------------- tagging / marking map('t', fm.tag_toggle()) map('T', fm.tag_remove()) map(' ', fm.mark(toggle=True)) map('v', fm.mark(all=True, toggle=True)) map('V', fm.mark(all=True, val=False)) # ------------------------------------------ file system operations map('yy', 'y', fm.copy()) map('dd', 'd', fm.cut()) map('pp', fm.paste()) map('po', fm.paste(overwrite=True)) map('pl', fm.paste_symlink()) map('p', fm.hint('press //p// once again to confirm pasting' \ ', or //l// to create symlinks')) # ---------------------------------------------------- run programs map('s', fm.execute_command(os.environ['SHELL'])) map('E', fm.edit_file()) map('.term', fm.execute_command('x-terminal-emulator', flags='d')) map('du', fm.execute_command('du --max-depth=1 -h | less')) # -------------------------------------------------- toggle options map('z', fm.hint("show_//h//idden //p//review_files" \ "//d//irectories_first //c//ollapse_preview flush//i//nput")) map('zh', fm.toggle_boolean_option('show_hidden')) map('zp', fm.toggle_boolean_option('preview_files')) map('zi', fm.toggle_boolean_option('flushinput')) map('zd', fm.toggle_boolean_option('directories_first')) map('zc', fm.toggle_boolean_option('collapse_preview')) # ------------------------------------------------------------ sort map('o', 'O', fm.hint("//s//ize //b//ase//n//ame //m//time" \ " //t//ype //r//everse")) sort_dict = { 's': 'size', 'b': 'basename', 'n': 'basename', 'm': 'mtime', 't': 'type', } for key, val in sort_dict.items(): for key, is_capital in ((key, False), (key.upper(), True)): # reverse if any of the two letters is capital map('o' + key, fm.sort(func=val, reverse=is_capital)) map('O' + key, fm.sort(func=val, reverse=True)) map('or', 'Or', 'oR', 'OR', lambda arg: \ arg.fm.sort(reverse=not arg.fm.settings.sort_reverse)) # ----------------------------------------------- console shortcuts @map("A") def append_to_filename(arg): command = 'rename ' + arg.fm.env.cf.basename arg.fm.open_console(cmode.COMMAND, command) map('cw', fm.open_console(cmode.COMMAND, 'rename ')) map('cd', fm.open_console(cmode.COMMAND, 'cd ')) map('f', fm.open_console(cmode.COMMAND_QUICK, 'find ')) map('bf', fm.open_console(cmode.COMMAND, 'filter ')) map('d', fm.hint('d//u// (disk usage) d//d// (cut)')) map('@', fm.open_console(cm