Forcefully quit vim even if pattern not found - vim

I am using command :%s/foo/bar/g | wq to find and replace using vim. It works fine if pattern is available but if pattern isn't available it Error detected while processing command line:
E486: Pattern not found: foo
How can I forcefully exit even if pattern isn't found? I tried wq! in above command but didn't help

The problem is with substitute issuing the error. You can set the flag e
:%s/foo/bar/ge | wq
which should prevent the "No match" error from breaking a mapping or commands.
:h :s_flags

Every time I tried to exit with :q it gave me an error message "E486: Pattern not found:..."
If I press ":" it appears "?" and instead of :q appeared ?q and gave me the error message: "E486: Pattern not found:..."
Cause? Instead of the US keyboard, I had set the Romanian (Standard) keyboard.
And instead of ":" type "ș" (special Romanian character).
I set back to US keyboard and everything was solved.

Related

Ctrl-p Vim bug - unclear what error message is telling me

prt path <mru>={ files }=<buf> <-> /home/....
Error detected while processing function <SNR>48_NormalPasta:
line 13:
E21: Cannot make changes, 'modifiable' is off
Press ENTER or type command to continue
kind of a strange vim error I get when I try to type the 'p' character using vim & ctrlp, using linux ubuntu here
Let's take that message one line at a time:
Error detected while processing function <SNR>48_NormalPasta:
There is an error in function NormalPasta() in the 48th script that was sourced by Vim.
line 13:
The error is on line 13 of that function.
E21: Cannot make changes, 'modifiable' is off
The function is trying to edit a non-modifiable buffer.
From there, you can do:
:filter 48 scriptnames
or:
$ grep -R NormalPasta ~/.vim/**/*.vim
to find in what script the problematic function is located.
This leads to this plugin, which appears to be OK. The whole situation seems rather strange, though, because the problematic function is supposed to be called from normal mode and I don't think a) that you should be in normal mode at CtrlP's prompt and b) that the CtrlP prompt is supposed to be non-modifiable.
My opinion is that the vim-pasta plugin is OK and thus that there is something fishy going on with CtrlP itself or the way you use it.

call from command line, show file also if the search does not match

I use a msdos-script to search with vim for patterns and show me the result
Script: tel.bat
rem script is called: tel.bat <pattern>
gvim -R %WORKSPACE%\telliste.csv "+set ignorecase" "+set ft=javascript" -c /%1
This works fine if the pattern exist in the file. If the pattern is not matched, I get an error message and I am stuck. No keystroke or mouse action changes the state. Like:
Enter key - has no effect
Esc key - has no effect
Ctrl + C - the error-messages disappears, but the editor is frozen. No action possible
Mouse click in editor - has no effect
I can only close vim and try again. That's what I get as error, when I call the script tel.bat konez on the command line:
Error message translated:
Error during execution of "command line":
E486: Pattern not found: konez
Confirm with the ENTER Key or place a command
How can I work further on the file, even if the pattern is not found? In other words how can I avoid that I am stuck in vim.
I tried already with -c ":execute 'silent !'" in the batch file, but this was not recognized. Perhaps I did it in the wrong way...
This should work, and I cannot reproduce this on Linux with Vim version 8.0.1358; I can accept the error message with <Enter> and continue.
This could be a plugin / configuration issue; try launching with gvim --clean.
The multi-line error message is ugly. You could avoid it by moving to the lower-level search() function:
gvim ... -c "call search('%1')"
By evaluating its return value; you could also craft your own error message: if search(...) == 0 | echomsg 'No matches' | endif

vim mapping K to external command

I'd like to map vim's 'keywordprg' to Dash, namely, use K to do !open dash://word-unser-curse.
Currently, I'm doing this:
:let &keywordprg '!open dash://'
but it says E34: No previous command.
from :h E34:
Any '!' in {cmd} is replaced with the previous
external command (see also 'cpoptions'). But not when
there is a backslash before the '!', then that
backslash is removed. Example: ":!ls" followed by
":!echo ! \! \\!" executes "echo ls ! \!".
Thus you have to escape ! in order to have vim treat as it is, otherwise vim tries to replace it with the "previous command", resulting in the error.
Additionally, I don't think you need that ! in your keywordprg. Vim calls it as an external command anyway (the default value is man, not !man).

find and replace a String in vi editor on linux?

i am trying to replace String with new String in Linux vi editor
:s/totel_email_count/total_email_count/g
but getting following error.
E486: Pattern not found: totel_email_count
I'd guess the reason you're getting that error message is because you intend to replace the string on all lines, not just the current one. In order to search all lines, add a % to your command:
:%s/totel_email_count/total_email_count/g
To find and replace with vi editor type following:-
Type : (colon) followed by %s/foo/bar/ and hit [Enter] key.
:%s/foo/bar/
for example:-
:%s/old_string/new_string/

No mapping found

Starting up vim and then No mapping found shows up at bottom.
running the command: vim -V20logfile
line 3: redir => res
line 4: silent! execute a:cmd
line 5: redir END
line 6: let &verbosefile = oldverbosefile
I had the same issue.
I commented out all maps, thinking they were all fine. Sure enough, vim loaded without err.
Then, I reintroduced the mappings until one broke it. Sure enough I had left out the space between the lhs and the rhs. As soon as I corrected this, it worked perfectly again.
I found the best way to debug your .vimrc is to enable the debug and pip it to a log file. Examine the file and search for the error.
If the error you are receiving is " no mapping found", open the log file and search for the these words.
:/no mapping found.
It will show you where the error is coming from. In my case I found that the error is from a plugin I installed. I disabled it and it works fine again.
Run the following command at the prompt:
vim -V20 2>&1 | tee logfile

Resources