From: Daniel Carl Date: Sat, 19 Oct 2013 18:11:11 +0000 (+0200) Subject: Added noremap counterparts for the xmap commands. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=c6c62597946d026bbd2c2acf964b125b3c5f39f4;p=vimb.git Added noremap counterparts for the xmap commands. --- diff --git a/doc/vimb.1 b/doc/vimb.1 index 91ec70f..15aaa43 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -2,20 +2,16 @@ .\" Process this file with .\" groff -man -Tascii vimb.1 .TH vimb 1 "DATE" "vimb/VERSION" "Vimb Manual" - .SH NAME vimb - Vim Browser - A modal web browser based on webkit thats inspired by vim the great editor. - .SH SYNOPSIS .BI "vimb [" "OPTION" "] [" "URI" "]" - .SH DESCRIPTION vimb is a webkit based web browser that behaves like the vimperator plugin for the firefox and usage paradigms from the great editor vim. The goal of vimb is to build a completely keyboard-driven, efficient and pleasurable browsing-experience. - .SH OPTIONS Mandatory arguments to long options are mandatory for short options too. .TP @@ -36,7 +32,6 @@ create a own config file in .TP .B "\-v, \-\-version" Print build and version information. - .SH MODES vimb is modal an has following main modes: .TP @@ -54,12 +49,10 @@ In Pass-Through mode only the `` and `` keybindings are interpreted by vimb, all other keystrokes are given to the webview to handle them. This allows to use websites that uses keybindings itself, that might be swallowed by vimb else. - .SH NORMAL MODE COMMANDS Some of the Normal Model Commands can have a numeric count to multiply the effect of the command. If a command supports the count this is shown as \fB[N]\fP. - .SS General .TP .B : @@ -83,7 +76,6 @@ Pass the next key press directly to gtk. .TP .B CTRL\-Q Quit the browser. - .SS Navigation .TP .B o @@ -140,7 +132,6 @@ Reload the website without using caches. .TP .B CTRL\-C Stop loading the current page. - .SS Motion .TP .BI [ N ]CTRL\-F @@ -180,7 +171,6 @@ Scroll page \fIN\fP steps down. .TP .BI [ N ]k Scroll page \fIN\fP steps up. - .SS Hinting The hinting is the way to do what you would do with the mouse in common mouse-driven browsers. Open url, yank uri, save page and so on. If the hinting @@ -199,7 +189,6 @@ and numbered. Elements can be selected either by typing their number, or by typing part of their text (\fIhint\fP) to narrow down the result. When an element has been selected, it is automatically clicked or used (depending on \fImode\fP) and hint mode ends. - .RS 0 Following keys have special meanings in Hints mode: .IP \fB\fP @@ -211,7 +200,6 @@ Moves the focus to the previous hint element. .IP "\fB, CTRL\-C, CTRL\-[\fP" Exits Hints mode without selecting an element .RE - .TP .B f Is an alias for the \fB;o\fP hint mode. @@ -256,7 +244,6 @@ feature. .TP .B ;\-y Yank hint's destination location into primary and secondary clipboard. - .SS Searching .TP .BI / QUERY ", ?" QUERY @@ -278,7 +265,6 @@ direction. .BI [ N ]N Search for \fIN\fPnth previous search result depending on current serach direction. - .SS Zooming .TP .BI [ N ]z\-i @@ -295,7 +281,6 @@ Full-Content Zoom-Out the page by \fIN\fP steps. .TP .B z\-z Reset Zoom. - .SS Yank .TP .B y @@ -303,9 +288,7 @@ Yank the URI or current page into clipboard. .TP .B Y Yank the current selection into clipboard. - .SH COMMAND MODE - .SS Command Line Editing .TP .B , CTRL\-[, CTRL-C @@ -331,7 +314,6 @@ Moves the cursor after the char in inputbox. .TP .B CTRL\-V Pass the next key press directly to gtk. - .SS Command Line History .TP .B @@ -345,19 +327,16 @@ Step backward in the command history. .TP .B Step forward in the command history. - .SS Open .TP -.BI ":o[pen] [" URI "], o [" URI ] +.BI ":o[pen] [" URI ] Open the give \fIURI\fP into current window. If \fIURI\fP is empty the configured 'home-page' is opened. .TP -.BI ":t[abopen] [" URI "], t [" URI ] +.BI ":t[abopen] [" URI ] Open the give \fIURI\fP into a new window. If \fIURI\fP is empty the configured 'home-page' is opened. - .SS Key Mapping - Key mappings allow to alter actions of key presses. Each key mapping is associated with a mode and only has effect when the mode is active. Following commands allow the user to substitute one sequence of key presses by another. @@ -366,7 +345,6 @@ commands allow the user to substitute one sequence of key presses by another. Note that the \fIlhs\fP ends with the first found space. If you want to use space also in the {lhs} you have to escape this with a single `\\' like shown in the examples. - .RS 0 Standard key mapping commands are provided for these modes \fIm\fP: .IP \fBn\fP @@ -376,7 +354,6 @@ Insert mode: When interacting with text fields on a website. .IP \fBc\fP Command Line mode: When typing into the vimbs command line. .RE - Most keys in key sequences are represented simply by the character that you see on the screen when you type them. However, as a number of these characters have special meanings, and a number of keys have no visual representation, a @@ -384,25 +361,18 @@ special notation is required. As special key names have the format \fI<...>\fP. Following special keys can be used , , , for the cursor keys, , , , --, - and -. - +- and -. .TP .BI ":nm[ap] {" lhs "} {" rhs } .TP .BI ":im[ap] {" lhs "} {" rhs } .TP .BI ":cm[ap] {" lhs "} {" rhs } -Map the key-sequence \fIlhs\fP to \fIrhs\fP for the applicable mode. +Map the key sequence \fIlhs\fP to \fIrhs\fP for the modes where the map +command applies. The result, including \fIrhs\fP, is then further scanned for +mappings. This allows for nested and recursive use of mappings. -.TP -.BI ":nu[nmap] {" lhs } -.TP -.BI ":iu[nmap] {" lhs } -.TP -.BI ":cu[nmap] {" lhs } -Remove the mapping of \fIlhs\fP for the applicable mode. - -.RS 0 +.RS Example: .IP ":cmap h /home/user/downloads/" Adds a keybind to insert a file path into the input box. This could be useful @@ -413,7 +383,22 @@ This will enable scripts and lookup the first bookmarked URI with the tag .IP ":nmap \\\\\ \\\\\ 50G;o" Example which mappes two spaces to go to 50% of the page, start hinting mode. .RE - +.TP +.BI ":nn[oremap] {" lhs "} {" rhs } +.TP +.BI ":ino[remap] {" lhs "} {" rhs } +.TP +.BI ":cno[remap] {" lhs "} {" rhs } +Map the key sequence \fIlhs\fP to \fIrhs\fP for the mode where the map command +applies. Disallow mapping of \fIrhs\fP, to avoid nested and recursive +mappings. Often used to redefine a command. +.TP +.BI ":nu[nmap] {" lhs } +.TP +.BI ":iu[nmap] {" lhs } +.TP +.BI ":cu[nmap] {" lhs } +Remove the mapping of \fIlhs\fP for the applicable mode. .SS Bookmarks .TP .BI ":bma [" TAGS ] @@ -422,7 +407,6 @@ Save the current opened uri with \fITAGS\fP to the bookmark file. .BI ":bmr [" URI ] Removes all bookmarks for given \fIURI\fP or if not given the current opened page. - .SS Shortcuts Shortcuts allows to open URL build up from a named template with additional parameters. If a shortcut named 'dd' is defined, you can use it with `:open dd @@ -445,7 +429,6 @@ to setup a search engine. Can be called by `:open dl my search phrase'. .IP ":shortcut-add gh=https://github.com/$0/$1" to build urls from given parameters. Can be called `:open gh fanglingsu vimb'. .RE - .TP .BI ":shortcut-remove " "SHORTCUT" Remove the search engine to the given \fISHORTCUT\fP. @@ -453,7 +436,6 @@ Remove the search engine to the given \fISHORTCUT\fP. .BI ":shortcut-default " "SHORTCUT" Set the shortcut for given \fISHORTCUT\fP as the default. It doesn't matter if the \fISHORTCUT\fP is already in use or not to be able to set it. - .SS Settings .TP .BI ":se[t] " VAR = VALUE @@ -468,7 +450,6 @@ Show the current set value of variable .TP .BI ":se[t] " VAR ! Toggle the value of boolean variable \fIVAR\fP and display the new set value. - .SS Queue The queue allows to mark URLs for later reding (something like a read it later list). This list is shared between the single instances of vimb. Only @@ -486,7 +467,6 @@ queue. .TP .B :qc[lear] Removes all entries from queue. - .SS Misc .TP .BI ":sh[ellcmd] " CMD @@ -522,9 +502,7 @@ Example: .B :ha[rdcopy] Print current document. Open a GUI dialog where you can select the printer, number of copies, orientation, etc. - .SH INPUT MODE - .TP .B , CTRL\-[ Switch back to normal mode. @@ -534,7 +512,6 @@ Open configured editor with content of current form field. .TP .B CTRL\-Z Enter the pass-through mode. - .SH COMPLETIONS The completions are triggered by pressing `` or `` in the activated inputbox. Depending of the current inserted content different @@ -572,13 +549,12 @@ Example: .TP .B boomark tags The boomark tag completion allows to insert already used bookmars for the -`:bma ` or `:bookmark-add ` commands. +`:bma ` commands. .TP .B search The search completion allow to get a filtered list of already done searches. This completion starts by `/` or `?` in inputbox and performs a prefix comparison for further typed chars. - .SH FILES .I $XDG_CONFIG_HOME/vimb/config .RS @@ -607,11 +583,11 @@ This file holds the history of search queries. .RE .I $XDG_CONFIG_HOME/vimb/bookmark .RS -Holds the bookmarks saved with command `bookmark-add'. +Holds the bookmarks saved with command `bma'. .RE .I $XDG_CONFIG_HOME/vimb/queue .RS -Holds the read it later queue filled by `hint-queue-push' or `queue-push' if +Holds the read it later queue filled by `qpush' if vimb has been compiled with QUEUE feature. .RE .I $XDG_CONFIG_HOME/vimb/scripts.js @@ -624,7 +600,6 @@ that is opened. File for userdefined css styles. These file is used if the config variable `stylesheet' is enabled. .RE - .SH ENVIRONMENT .TP .B HOME @@ -634,11 +609,9 @@ directory. If not set the entry out of the passwd file will be used instead. .B http_proxy If this variable is set to an none empty value, and the configuration option `proxy' is enabled, this will be used as http proxy. - .SH "REPORTING BUGS" Report bugs to the main project page on https://github.com/fanglingsu/vimb/issues .br or on the mailing list https://lists.sourceforge.net/lists/listinfo/vimb-users. - .SH AUTHOR Daniel Carl diff --git a/src/ex.c b/src/ex.c index 2f2c7af..574dc28 100644 --- a/src/ex.c +++ b/src/ex.c @@ -45,10 +45,13 @@ typedef enum { EX_EVAL, EX_HARDCOPY, EX_CMAP, + EX_CNOREMAP, EX_IMAP, EX_NMAP, + EX_NNOREMAP, EX_CUNMAP, EX_IUNMAP, + EX_INOREMAP, EX_NUNMAP, EX_NORMAL, EX_OPEN, @@ -131,16 +134,19 @@ static void history_rewind(void); * searching for a matching command if the next compared character did not * match. */ static ExInfo commands[] = { - /* command code func flags */ + /* command code func flags */ {"bma", EX_BMA, ex_bookmark, EX_FLAG_RHS}, {"bmr", EX_BMR, ex_bookmark, EX_FLAG_RHS}, {"cmap", EX_CMAP, ex_map, EX_FLAG_LHS|EX_FLAG_RHS}, + {"cnoremap", EX_CNOREMAP, ex_map, EX_FLAG_LHS|EX_FLAG_RHS}, {"cunmap", EX_CUNMAP, ex_unmap, EX_FLAG_LHS}, {"hardcopy", EX_HARDCOPY, ex_hardcopy, EX_FLAG_NONE}, {"eval", EX_EVAL, ex_eval, EX_FLAG_RHS}, {"imap", EX_IMAP, ex_map, EX_FLAG_LHS|EX_FLAG_RHS}, + {"inoremap", EX_INOREMAP, ex_map, EX_FLAG_LHS|EX_FLAG_RHS}, {"iunmap", EX_IUNMAP, ex_unmap, EX_FLAG_LHS}, {"nmap", EX_NMAP, ex_map, EX_FLAG_LHS|EX_FLAG_RHS}, + {"nnoremap", EX_NNOREMAP, ex_map, EX_FLAG_LHS|EX_FLAG_RHS}, {"normal", EX_NORMAL, ex_normal, EX_FLAG_BANG|EX_FLAG_LHS}, {"nunmap", EX_NUNMAP, ex_unmap, EX_FLAG_LHS}, {"open", EX_OPEN, ex_open, EX_FLAG_RHS}, @@ -700,22 +706,14 @@ static gboolean ex_hardcopy(const ExArg *arg) static gboolean ex_map(const ExArg *arg) { - char *lhs, *rhs; - if (!arg->lhs->len || !arg->rhs->len) { return false; } - lhs = arg->lhs->str; - rhs = arg->rhs->str; + /* instead of using the EX_XMAP constants we use the first char of the + * command name as mode and the second to determine if noremap is used */ + map_insert(arg->lhs->str, arg->rhs->str, arg->name[0], arg->name[1] != 'n'); - if (arg->code == EX_NMAP) { - map_insert(lhs, rhs, 'n'); - } else if (arg->code == EX_CMAP) { - map_insert(lhs, rhs, 'c'); - } else { - map_insert(lhs, rhs, 'i'); - } return true;; } diff --git a/src/map.c b/src/map.c index 4c05c89..98eaf7b 100644 --- a/src/map.c +++ b/src/map.c @@ -27,11 +27,12 @@ extern VbCore vb; typedef struct { - char *in; /* input keys */ - int inlen; /* length of the input keys */ - char *mapped; /* mapped keys */ - int mappedlen; /* length of the mapped keys string */ - char mode; /* mode for which the map is available */ + char *in; /* input keys */ + int inlen; /* length of the input keys */ + char *mapped; /* mapped keys */ + int mappedlen; /* length of the mapped keys string */ + char mode; /* mode for which the map is available */ + gboolean remap; /* if false do not remap the {rhs} of this map */ } Map; static struct { @@ -294,10 +295,14 @@ MapState map_handle_keys(const guchar *keys, int keylen, gboolean use_map) /* copy the mapped string into the queue */ strncpy(map.queue, match->mapped, match->mappedlen); map.qlen += match->mappedlen - match->inlen; - if (match->inlen <= match->mappedlen) { - map.resolved = match->inlen; - } else { + + /* without remap the mapped chars are resolved now */ + if (!match->remap) { map.resolved = match->mappedlen; + } else if (match->inlen <= match->mappedlen + && !strncmp(match->in, match->mapped, match->inlen) + ) { + map.resolved = match->inlen; } } else { /* first char is not mapped but resolved */ @@ -321,7 +326,7 @@ void map_handle_string(char *str, gboolean use_map) map_handle_keys((guchar*)keys, len, use_map); } -void map_insert(char *in, char *mapped, char mode) +void map_insert(char *in, char *mapped, char mode, gboolean remap) { int inlen, mappedlen; char *lhs = convert_keys(in, strlen(in), &inlen); @@ -330,13 +335,13 @@ void map_insert(char *in, char *mapped, char mode) /* if lhs was already mapped, remove this first */ map_delete_by_lhs(lhs, inlen, mode); - /* TODO replace keysymbols in 'in' and 'mapped' string */ Map *new = g_new(Map, 1); new->in = lhs; new->inlen = inlen; new->mapped = rhs; new->mappedlen = mappedlen; new->mode = mode; + new->remap = remap; map.list = g_slist_prepend(map.list, new); } diff --git a/src/map.h b/src/map.h index 52b2c72..852303b 100644 --- a/src/map.h +++ b/src/map.h @@ -36,7 +36,7 @@ void map_cleanup(void); gboolean map_keypress(GtkWidget *widget, GdkEventKey* event, gpointer data); MapState map_handle_keys(const guchar *keys, int keylen, gboolean use_map); void map_handle_string(char *str, gboolean use_map); -void map_insert(char *in, char *mapped, char mode); +void map_insert(char *in, char *mapped, char mode, gboolean remap); gboolean map_delete(char *in, char mode); #endif /* end of include guard: _MAP_H */