On Sa, 28 Sep 2013, Bram Moolenaar wrote:
> Dimitar Dimitrov wrote:
>
> > Hi,
> > The call to histdel below doesn't seem to be doing what I want it to do.
> > It doesn't delete my 3 search patterns added by the 2 :substitute and
> > the :global calls. Not sure what it does exactly, it seems to delete
> > one correct entry and 2 wrong ones.
> > All I want is no trace of those patterns in my search history,
> > but histdel('/', '\\s\\+\$') wouldn't be a solution since I still want
> > this pattern in my history if I enter it manually at some point.
> > Any help appreciated.
> >
> >
> > " Squeeze empty lines
> > function! s:Squeeze()
> > let save_cursor = getpos(".")
> > " empty lines at BOF|EOF
> >
> > silent %substitute/\%^\_s*\n\|\_s*\%$//
> > " empty line clusters
> > silent global/^\%(\s*$\n\)\{2,}/delete
> > silent! %substitute/\s\+$//e
> > for i in range(1, 3)
> > call histdel('/', -1)
> > endfor
> > call setpos('.', save_cursor)
> > endfunction
> >
> > nmap <silent> <leader>z :call <sid>Squeeze()<cr>
>
> Not sure what happens there, but it might be a lot simpler if we have a
> way to avoid patterns to be put in the history, instead of deleting them
> afterwards. When a pattern was typed you may want to keep it, but after
> executing a :s command you don't know if the pattern was typed before
> you used it with :s. That gets complicated.
>
> For :s we could add a flag, but for :g/pattern/ there is is no place to
> put a flag. Perhaps we should use a modifier ":keeppatterns", like
> ":keepjumps" and ":keepmarks" ?
Here is a patch that adds the :keeppatterns command modifier as well as
an additional search flag 'h'
regards,
Christian
--
Tango ist der vertikale Ausruck eines horizontalen Verlangens.
-- Argentinien
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt
--- a/runtime/doc/cmdline.txt
+++ b/runtime/doc/cmdline.txt
@@ -356,6 +356,10 @@
List the recent five entries from all histories: >
:history all -5,
+:keepp[atterns] {command} *:keepp* *:keeppatterns*
+ Execute {command}, without adding anything to the search
+ history
+
==============================================================================
2. Command-line completion *cmdline-completion*
diff --git a/runtime/doc/pattern.txt b/runtime/doc/pattern.txt
--- a/runtime/doc/pattern.txt
+++ b/runtime/doc/pattern.txt
@@ -171,6 +171,7 @@
b[+num] [num] identical to s[+num] above (mnemonic: begin)
b[-num] [num] identical to s[-num] above (mnemonic: begin)
;{pattern} perform another search, see |//;|
+ h don't add search item to search |history|
If a '-' or '+' is given but [num] is omitted, a count of one will be used.
When including an offset with 'e', the search becomes inclusive (the
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -477,6 +477,8 @@
NEEDARG|EXTRA|NOTRLCOM),
EX(CMD_keepjumps, "keepjumps", ex_wrongmodifier,
NEEDARG|EXTRA|NOTRLCOM),
+EX(CMD_keeppatterns, "keeppatterns", ex_wrongmodifier,
+ NEEDARG|EXTRA|NOTRLCOM),
EX(CMD_keepalt, "keepalt", ex_wrongmodifier,
NEEDARG|EXTRA|NOTRLCOM),
EX(CMD_list, "list", ex_print,
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -1843,6 +1843,11 @@
cmdmod.keepalt = TRUE;
continue;
}
+ if (checkforcmd(&ea.cmd, "keeppatterns", 5))
+ {
+ cmdmod.keeppatterns = TRUE;
+ continue;
+ }
if (!checkforcmd(&ea.cmd, "keepjumps", 5))
break;
cmdmod.keepjumps = TRUE;
@@ -2584,6 +2589,7 @@
case CMD_keepalt:
case CMD_keepjumps:
case CMD_keepmarks:
+ case CMD_keeppatterns:
case CMD_leftabove:
case CMD_let:
case CMD_lockmarks:
@@ -3100,6 +3106,7 @@
{"unsilent", 3, FALSE},
{"verbose", 4, TRUE},
{"vertical", 4, FALSE},
+ {"keeppatterns", 5, FALSE},
};
/*
@@ -3597,6 +3604,7 @@
case CMD_keepalt:
case CMD_keepjumps:
case CMD_keepmarks:
+ case CMD_keeppatterns:
case CMD_leftabove:
case CMD_lockmarks:
case CMD_rightbelow:
diff --git a/src/ex_getln.c b/src/ex_getln.c
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -5498,6 +5498,9 @@
if (hislen == 0) /* no history */
return;
+ if (cmdmod.keeppatterns && histype == HIST_SEARCH)
+ return;
+
/*
* Searches inside the same mapping overwrite each other, so that only
* the last line is kept. Be careful not to remove a line that was moved
diff --git a/src/search.c b/src/search.c
--- a/src/search.c
+++ b/src/search.c
@@ -1360,6 +1360,10 @@
+ ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
RE_LAST, (linenr_T)0, tm);
+ if (pat != NULL && *pat == 'h')
+ /* remove previous added history entry */
+ del_history_idx(HIST_SEARCH, -1);
+
if (dircp != NULL)
*dircp = dirc; /* restore second '/' or '?' for normal_cmd() */
if (c == FAIL)
diff --git a/src/structs.h b/src/structs.h
--- a/src/structs.h
+++ b/src/structs.h
@@ -542,6 +542,7 @@
int keepmarks; /* TRUE when ":keepmarks" was used */
int keepjumps; /* TRUE when ":keepjumps" was used */
int lockmarks; /* TRUE when ":lockmarks" was used */
+ int keeppatterns; /* TRUE when ":keeppatterns" was used */
# ifdef FEAT_AUTOCMD
char_u *save_ei; /* saved value of 'eventignore' */
# endif