dot

packages and services management
Log | Files | Refs | README

commit 5ce2ea0c32c09425d9db1a5a9d64272f08478138
parent 09d6cd0fd2fa2710e6b87f3efb0bba720b0d04f0
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 21 Apr 2017 14:29:47 +0200

Emacs-style keybindings for vis "_"

Diffstat:
Mbuild/vis | 2++
Avis/config.h | 391+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 393 insertions(+), 0 deletions(-)

diff --git a/build/vis b/build/vis @@ -4,6 +4,8 @@ tar=http://github.com/martanne/vis/archive/master.tar.gz build() { + cp -f "$CONFIG/vis/config.h" config.h + ./configure --disable-lua --disable-lpeg --prefix="$PREFIX" CFLAGS="$CFLAGS" && make install diff --git a/vis/config.h b/vis/config.h @@ -0,0 +1,391 @@ +/* Configure your desired default key bindings. */ + +#define ALIAS(name) .alias = name, +#define ACTION(id) .action = &vis_action[VIS_ACTION_##id], + +static const char *keymaps[] = { + NULL +}; + +static const KeyBinding bindings_basic[] = { + { "<C-z>", ACTION(EDITOR_SUSPEND) }, + { "<Down>", ACTION(CURSOR_LINE_DOWN) }, + { "<End>", ACTION(CURSOR_LINE_END) }, + { "<Home>", ACTION(CURSOR_LINE_BEGIN) }, + { "<Left>", ACTION(CURSOR_CHAR_PREV) }, + { "<PageDown>", ACTION(WINDOW_PAGE_DOWN) }, + { "<PageUp>", ACTION(WINDOW_PAGE_UP) }, + { "<Right>", ACTION(CURSOR_CHAR_NEXT) }, + { "<S-Left>", ACTION(CURSOR_LONGWORD_START_PREV) }, + { "<S-PageDown>", ACTION(WINDOW_HALFPAGE_DOWN) }, + { "<S-PageUp>", ACTION(WINDOW_HALFPAGE_UP) }, + { "<S-Right>", ACTION(CURSOR_LONGWORD_START_NEXT) }, + { "<Up>", ACTION(CURSOR_LINE_UP) }, + /* custom keybindings */ + { "<M-<>", ACTION(CURSOR_LINE_FIRST) }, + { "<M->>", ACTION(CURSOR_LINE_LAST) }, + { "<M-v>", ACTION(WINDOW_PAGE_UP) }, + { "<C-v>", ACTION(WINDOW_PAGE_DOWN) }, + { "<C-p>", ACTION(CURSOR_LINE_UP) }, + { "<C-n>", ACTION(CURSOR_LINE_DOWN) }, + { "<M-a>", ACTION(CURSOR_SENTENCE_PREV) }, + { "<M-e>", ACTION(CURSOR_SENTENCE_NEXT) }, + { "<C-a>", ACTION(CURSOR_LINE_BEGIN) }, + { "<C-e>", ACTION(CURSOR_LINE_END) }, + { "<M-b>", ACTION(CURSOR_WORD_START_PREV) }, + { "<M-f>", ACTION(CURSOR_WORD_END_NEXT) }, + { "<C-b>", ACTION(CURSOR_CHAR_PREV) }, + { "<C-f>", ACTION(CURSOR_CHAR_NEXT) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_motions[] = { + { "|", ACTION(CURSOR_COLUMN) }, + { "[{", ACTION(CURSOR_BLOCK_START) }, + { "]}", ACTION(CURSOR_BLOCK_END) }, + { "[(", ACTION(CURSOR_PARENTHESE_START) }, + { "])", ACTION(CURSOR_PARENTHESE_END) }, + { "$", ACTION(CURSOR_LINE_END) }, + { "^", ACTION(CURSOR_LINE_START) }, + { "}", ACTION(CURSOR_PARAGRAPH_NEXT) }, + { "{", ACTION(CURSOR_PARAGRAPH_PREV) }, + { "%", ACTION(CURSOR_PERCENT) }, + { "#", ACTION(CURSOR_SEARCH_WORD_BACKWARD) }, + { "*", ACTION(CURSOR_SEARCH_WORD_FORWARD) }, + { ")", ACTION(CURSOR_SENTENCE_NEXT) }, + { "(", ACTION(CURSOR_SENTENCE_PREV) }, + { "`", ACTION(MARK_GOTO) }, + { "'", ACTION(MARK_GOTO_LINE) }, + { "?", ACTION(PROMPT_SEARCH_BACKWARD) }, + { "/", ACTION(PROMPT_SEARCH_FORWARD) }, + { ";", ACTION(TOTILL_REPEAT) }, + { ",", ACTION(TOTILL_REVERSE) }, + { "+", ALIAS("j^") }, + { "-", ALIAS("k^") }, + { " ", ALIAS("<Space>") }, + { "<Space>", ALIAS("l") }, + { "<Backspace>", ALIAS("h") }, + { "B", ACTION(CURSOR_LONGWORD_START_PREV) }, + { "b", ACTION(CURSOR_WORD_START_PREV) }, + { "<C-h>", ALIAS("<Backspace>") }, + { "<C-j>", ALIAS("j") }, + { "<C-n>", ALIAS("j") }, + { "<C-p>", ALIAS("k") }, + { "E", ACTION(CURSOR_LONGWORD_END_NEXT) }, + { "e", ACTION(CURSOR_WORD_END_NEXT) }, + { "<Enter>", ALIAS("j") }, + { "F", ACTION(TO_LEFT) }, + { "f", ACTION(TO_RIGHT) }, + { "go", ACTION(CURSOR_BYTE) }, + { "gh", ACTION(CURSOR_BYTE_LEFT) }, + { "gl", ACTION(CURSOR_BYTE_RIGHT) }, + { "g0", ACTION(CURSOR_SCREEN_LINE_BEGIN) }, + { "g_", ACTION(CURSOR_LINE_FINISH) }, + { "G", ACTION(CURSOR_LINE_LAST) }, + { "g$", ACTION(CURSOR_SCREEN_LINE_END) }, + { "g<Down>", ALIAS("gj") }, + { "gE", ACTION(CURSOR_LONGWORD_END_PREV) }, + { "ge", ACTION(CURSOR_WORD_END_PREV) }, + { "gg", ACTION(CURSOR_LINE_FIRST) }, + { "gj", ACTION(CURSOR_SCREEN_LINE_DOWN) }, + { "gk", ACTION(CURSOR_SCREEN_LINE_UP) }, + { "gm", ACTION(CURSOR_SCREEN_LINE_MIDDLE) }, + { "g<Up>", ALIAS("gk") }, + { "h", ACTION(CURSOR_CHAR_PREV) }, + { "H", ACTION(CURSOR_WINDOW_LINE_TOP) }, + { "j", ACTION(CURSOR_LINE_DOWN) }, + { "k", ACTION(CURSOR_LINE_UP) }, + { "l", ACTION(CURSOR_CHAR_NEXT) }, + { "L", ACTION(CURSOR_WINDOW_LINE_BOTTOM) }, + { "M", ACTION(CURSOR_WINDOW_LINE_MIDDLE) }, + { "n", ACTION(CURSOR_SEARCH_NEXT) }, + { "N", ACTION(CURSOR_SEARCH_PREV) }, + { "T", ACTION(TILL_LEFT) }, + { "t", ACTION(TILL_RIGHT) }, + { "W", ACTION(CURSOR_LONGWORD_START_NEXT) }, + { "w", ACTION(CURSOR_WORD_START_NEXT) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_textobjects[] = { + { "a<", ACTION(TEXT_OBJECT_ANGLE_BRACKET_OUTER) }, + { "a`", ACTION(TEXT_OBJECT_BACKTICK_OUTER) }, + { "a{", ACTION(TEXT_OBJECT_CURLY_BRACKET_OUTER) }, + { "a(", ACTION(TEXT_OBJECT_PARANTHESE_OUTER) }, + { "a\"", ACTION(TEXT_OBJECT_QUOTE_OUTER) }, + { "a\'", ACTION(TEXT_OBJECT_SINGLE_QUOTE_OUTER) }, + { "a[", ACTION(TEXT_OBJECT_SQUARE_BRACKET_OUTER) }, + { "a>", ALIAS("a<") }, + { "a)", ALIAS("a(") }, + { "a]", ALIAS("a[") }, + { "a}", ALIAS("a{") }, + { "ab", ALIAS("a(") }, + { "aB", ALIAS("a{") }, + { "ae", ACTION(TEXT_OBJECT_ENTIRE_OUTER) }, + { "al", ACTION(TEXT_OBJECT_LINE_OUTER) }, + { "ap", ACTION(TEXT_OBJECT_PARAGRAPH) }, + { "as", ACTION(TEXT_OBJECT_SENTENCE) }, + { "a<Tab>", ACTION(TEXT_OBJECT_INDENTATION) }, + { "aW", ACTION(TEXT_OBJECT_LONGWORD_OUTER) }, + { "aw", ACTION(TEXT_OBJECT_WORD_OUTER) }, + { "gN", ACTION(TEXT_OBJECT_SEARCH_BACKWARD) }, + { "gn", ACTION(TEXT_OBJECT_SEARCH_FORWARD) }, + { "i<", ACTION(TEXT_OBJECT_ANGLE_BRACKET_INNER) }, + { "i`", ACTION(TEXT_OBJECT_BACKTICK_INNER) }, + { "i{", ACTION(TEXT_OBJECT_CURLY_BRACKET_INNER) }, + { "i(", ACTION(TEXT_OBJECT_PARANTHESE_INNER) }, + { "i\"", ACTION(TEXT_OBJECT_QUOTE_INNER) }, + { "i\'", ACTION(TEXT_OBJECT_SINGLE_QUOTE_INNER) }, + { "i[", ACTION(TEXT_OBJECT_SQUARE_BRACKET_INNER) }, + { "i>", ALIAS("i<") }, + { "i)", ALIAS("i(") }, + { "i]", ALIAS("i[") }, + { "i}", ALIAS("i{") }, + { "ib", ALIAS("i(") }, + { "iB", ALIAS("i{") }, + { "ie", ACTION(TEXT_OBJECT_ENTIRE_INNER) }, + { "il", ACTION(TEXT_OBJECT_LINE_INNER) }, + { "ip", ACTION(TEXT_OBJECT_PARAGRAPH) }, + { "is", ACTION(TEXT_OBJECT_SENTENCE) }, + { "i<Tab>", ACTION(TEXT_OBJECT_INDENTATION) }, + { "iW", ACTION(TEXT_OBJECT_LONGWORD_INNER) }, + { "iw", ACTION(TEXT_OBJECT_WORD_INNER) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_operators[] = { + { "0", ACTION(COUNT) }, + { "1", ACTION(COUNT) }, + { "2", ACTION(COUNT) }, + { "3", ACTION(COUNT) }, + { "4", ACTION(COUNT) }, + { "5", ACTION(COUNT) }, + { "6", ACTION(COUNT) }, + { "7", ACTION(COUNT) }, + { "8", ACTION(COUNT) }, + { "9", ACTION(COUNT) }, + { "~", ACTION(OPERATOR_CASE_SWAP) }, + { "!", ACTION(OPERATOR_FILTER) }, + { "=", ALIAS("gq") }, + { "<", ACTION(OPERATOR_SHIFT_LEFT) }, + { ">", ACTION(OPERATOR_SHIFT_RIGHT) }, + { "\"", ACTION(REGISTER) }, + { "c", ACTION(OPERATOR_CHANGE) }, + { "d", ACTION(OPERATOR_DELETE) }, + { "g~", ACTION(OPERATOR_CASE_SWAP) }, + { "gp", ACTION(PUT_AFTER_END) }, + { "gP", ACTION(PUT_BEFORE_END) }, + { "gq", ACTION(OPERATOR_FILTER_FMT) }, + { "gu", ACTION(OPERATOR_CASE_LOWER) }, + { "gU", ACTION(OPERATOR_CASE_UPPER) }, + { "p", ACTION(PUT_AFTER) }, + { "P", ACTION(PUT_BEFORE) }, + { "y", ACTION(OPERATOR_YANK) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_operator_options[] = { + { "v", ACTION(MOTION_CHARWISE) }, + { "V", ACTION(MOTION_LINEWISE) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_normal[] = { + { "a", ACTION(APPEND_CHAR_NEXT) }, + { "A", ACTION(APPEND_LINE_END) }, + { "@", ACTION(MACRO_REPLAY) }, + { ":", ACTION(PROMPT_SHOW) }, + { ".", ACTION(REPEAT) }, + { "~", ALIAS("<vis-operator-case-swap>ll") }, + { "C", ALIAS("c$") }, + { "<C-b>", ALIAS("<PageUp>") }, + { "<C-c>", ACTION(CURSORS_REMOVE_COLUMN) }, + { "<C-d>", ACTION(CURSORS_NEXT) }, + { "<C-e>", ACTION(WINDOW_SLIDE_UP) }, + { "<C-f>", ALIAS("<PageDown>") }, + { "<C-i>", ACTION(JUMPLIST_NEXT) }, + { "<C-j>", ACTION(CURSORS_NEW_LINE_BELOW) }, + { "<C-k>", ACTION(CURSORS_NEW_LINE_ABOVE) }, + { "<C-l>", ACTION(CURSORS_REMOVE_COLUMN_EXCEPT) }, +/* { "<C-n>", ACTION(CURSOR_SELECT_WORD) }, */ + { "<C-o>", ACTION(JUMPLIST_PREV) }, +/* { "<C-p>", ACTION(CURSORS_REMOVE_LAST) }, */ + { "<C-r>", ACTION(REDO) }, + { "<C-u>", ACTION(CURSORS_PREV) }, + { "<C-w><Backspace>", ALIAS("<C-w>k") }, + { "<C-w>c", ALIAS(":q<Enter>") }, + { "<C-w><C-h>", ALIAS("<C-w>k") }, + { "<C-w><C-j>", ALIAS("<C-w>j") }, + { "<C-w><C-k>", ALIAS("<C-w>k") }, + { "<C-w><C-l>", ALIAS("<C-w>j") }, + { "<C-w><C-w>", ALIAS("<C-w>j") }, + { "<C-w>h", ALIAS("<C-w>k") }, + { "<C-w>j", ACTION(WINDOW_NEXT) }, + { "<C-w>k", ACTION(WINDOW_PREV) }, + { "<C-w>l", ALIAS("<C-w>j") }, + { "<C-w>n", ALIAS(":open<Enter>") }, + { "<C-w>s", ALIAS(":split<Enter>") }, + { "<C-w>v", ALIAS(":vsplit<Enter>") }, + { "<C-w>w", ALIAS("<C-w>j") }, + { "<C-y>", ACTION(WINDOW_SLIDE_DOWN) }, + { "D", ALIAS("d$") }, + { "<Delete>", ALIAS("x") }, + { "<Escape>", ACTION(CURSORS_REMOVE_ALL) }, + { "<F1>", ALIAS(":help<Enter>") }, + { "ga", ACTION(UNICODE_INFO) }, + { "g8", ACTION(UTF8_INFO) }, + { "g,", ACTION(CHANGELIST_NEXT) }, + { "g;", ACTION(CHANGELIST_PREV) }, + { "g-", ACTION(EARLIER) }, + { "g+", ACTION(LATER) }, + { "gn", ALIAS("vgn") }, + { "gN", ALIAS("vgN") }, + { "gv", ACTION(SELECTION_RESTORE) }, + { "I", ACTION(INSERT_LINE_START) }, + { "i", ACTION(MODE_INSERT) }, + { "J", ACTION(JOIN_LINES) }, + { "gJ", ACTION(JOIN_LINES_TRIM) }, + { "m", ACTION(MARK_SET) }, + { "<M-C-j>", ACTION(CURSORS_NEW_LINE_BELOW_LAST) }, + { "<M-C-k>", ACTION(CURSORS_NEW_LINE_ABOVE_FIRST) }, + { "O", ACTION(OPEN_LINE_ABOVE) }, + { "o", ACTION(OPEN_LINE_BELOW) }, + { "q", ACTION(MACRO_RECORD) }, + { "R", ACTION(MODE_REPLACE) }, + { "r", ACTION(REPLACE_CHAR) }, + { "S", ALIAS("^c$") }, + { "s", ALIAS("cl") }, + { "<Tab>", ACTION(CURSORS_ALIGN) }, + { "u", ACTION(UNDO) }, + { "v", ACTION(MODE_VISUAL) }, + { "V", ACTION(MODE_VISUAL_LINE) }, + { "x", ACTION(DELETE_CHAR_NEXT) }, + { "X", ALIAS("dh") }, + { "Y", ALIAS("y$") }, + { "zb", ACTION(WINDOW_REDRAW_BOTTOM) }, + { "ZQ", ALIAS(":q!<Enter>") }, + { "zt", ACTION(WINDOW_REDRAW_TOP) }, + { "zz", ACTION(WINDOW_REDRAW_CENTER) }, + { "ZZ", ALIAS(":wq<Enter>") }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_visual[] = { + { "A", ACTION(CURSORS_NEW_LINES_END) }, + { "@", ACTION(MACRO_REPLAY) }, + { ":", ACTION(PROMPT_SHOW) }, + { "-", ACTION(SELECTIONS_ROTATE_LEFT) }, + { "+", ACTION(SELECTIONS_ROTATE_RIGHT) }, + { "\\", ACTION(SELECTIONS_TRIM) }, + { "<", ALIAS("<vis-operator-shift-left>gv") }, + { ">", ALIAS("<vis-operator-shift-right>gv") }, + { "<Backspace>", ALIAS("d") }, + { "<C-b>", ALIAS("<PageUp>") }, + { "<C-c>", ACTION(CURSORS_REMOVE_COLUMN) }, + { "<C-d>", ACTION(CURSORS_NEXT) }, + { "<C-f>", ALIAS("<PageDown>") }, + { "<C-h>", ALIAS("<Backspace>") }, + { "<C-j>", ALIAS("<C-d>") }, + { "<C-k>", ALIAS("<C-u>") }, + { "<C-l>", ACTION(CURSORS_REMOVE_COLUMN_EXCEPT) }, + { "<C-n>", ACTION(CURSORS_NEW_MATCH_NEXT) }, + { "<C-p>", ACTION(CURSORS_REMOVE_LAST) }, + { "<C-u>", ACTION(CURSORS_PREV) }, + { "<C-x>", ACTION(CURSORS_NEW_MATCH_SKIP) }, + { "<Delete>", ALIAS("<Backspace>") }, + { "<Escape>", ACTION(MODE_NORMAL) }, + { "I", ACTION(CURSORS_NEW_LINES_BEGIN) }, + { "J", ACTION(JOIN_LINES) }, + { "gJ", ACTION(JOIN_LINES_TRIM) }, + { "o", ACTION(SELECTION_FLIP) }, + { "q", ACTION(MACRO_RECORD) }, + { "r", ACTION(REPLACE_CHAR) }, + { "s", ALIAS("c") }, + { "<S-Tab>", ACTION(CURSORS_ALIGN_INDENT_RIGHT) }, + { "<Tab>", ACTION(CURSORS_ALIGN_INDENT_LEFT) }, + { "V", ACTION(MODE_VISUAL_LINE) }, + { "v", ALIAS("<Escape>") }, + { "x", ALIAS("d") }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_visual_line[] = { + { "v", ACTION(MODE_VISUAL) }, + { "V", ACTION(MODE_NORMAL) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_readline[] = { + { "<Backspace>", ACTION(DELETE_CHAR_PREV) }, + { "<C-c>", ALIAS("<Escape>") }, + { "<C-d>", ACTION(DELETE_CHAR_NEXT) }, + { "<C-h>", ALIAS("<Backspace>") }, + { "<C-u>", ACTION(DELETE_LINE_BEGIN) }, + { "<C-q>", ACTION(INSERT_VERBATIM) }, + { "<C-w>", ACTION(DELETE_WORD_PREV) }, + { "<Delete>", ACTION(DELETE_CHAR_NEXT) }, + { "<Escape>", ACTION(MODE_NORMAL) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_insert[] = { + { "<C-d>", ALIAS("<vis-operator-shift-left><vis-operator-shift-left>") }, + { "<C-i>", ALIAS("<Tab>") }, + { "<C-j>", ALIAS("<Enter>") }, + { "<C-m>", ALIAS("<Enter>") }, + { "<C-r>", ACTION(INSERT_REGISTER) }, + { "<C-t>", ALIAS("<vis-operator-shift-right><vis-operator-shift-right>") }, + { "<C-x><C-e>", ACTION(WINDOW_SLIDE_UP) }, + { "<C-x><C-y>", ACTION(WINDOW_SLIDE_DOWN) }, + { "<Enter>", ACTION(INSERT_NEWLINE) }, + { "<Escape>", ACTION(MODE_NORMAL) }, + { "<S-Tab>", ACTION(CURSORS_ALIGN_INDENT_LEFT) }, + { "<Tab>", ACTION(INSERT_TAB) }, + { 0 /* empty last element, array terminator */ }, +}; + +static const KeyBinding bindings_replace[] = { + { 0 /* empty last element, array terminator */ }, +}; + +/* For each mode we list a all key bindings, if a key is bound in more than + * one array the first definition is used and further ones are ignored. */ +static const KeyBinding **default_bindings[] = { + [VIS_MODE_OPERATOR_PENDING] = (const KeyBinding*[]){ + bindings_operator_options, + bindings_operators, + bindings_textobjects, + bindings_motions, + bindings_basic, + NULL, + }, + [VIS_MODE_NORMAL] = (const KeyBinding*[]){ + bindings_normal, + bindings_operators, + bindings_motions, + bindings_basic, + NULL, + }, + [VIS_MODE_VISUAL] = (const KeyBinding*[]){ + bindings_visual, + bindings_textobjects, + bindings_operators, + bindings_motions, + bindings_basic, + NULL, + }, + [VIS_MODE_VISUAL_LINE] = (const KeyBinding*[]){ + bindings_visual_line, + NULL, + }, + [VIS_MODE_INSERT] = (const KeyBinding*[]){ + bindings_insert, + bindings_readline, + bindings_basic, + NULL, + }, + [VIS_MODE_REPLACE] = (const KeyBinding*[]){ + bindings_replace, + NULL, + }, +};