Getting YcmCompleter RefactorRename shortcut to work properly - vim

I would like to add shortcut for YcmCompleter RefactorRename command. Here is what I have so far:
nmap <leader>yrn :exe 'YcmCompleter RefactorRename '.input('refactor \"'.expand('<cword>').'\" to:')<cr>"
When I press shortcut, I see input prompt, but after I enter new name, operation fails with RuntimeError: Cannot rename the symbol under cursor.
If I run YcmCompleter RefactorRename newname in the same place, it works just fine. There seems to be a problem with my script
How do I get this to work?

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.

Vim: Avoid having to press ENTER after successful make?

$ ls
Makefile html-page/ page-generator.m4
Run includes/
Alongside the Makefile, I have a script Run that is executed only when make completes without errors. This I've managed to implement with the following in my .vimrc file, which also looks for the Makefile in parent directories if needed.
" Before the 'make' quickfix command, run my quickfix pre-commands
autocmd QuickfixCmdPre make call MyQuickfixCmdPre()
" After the 'make' quickfix command, run my quickfix post-commands
autocmd QuickfixCmdPost make call MyQuickfixCmdPost()
and
function! MyQuickfixCmdPre()
" Save current buffer, but only if it's been modified
update
" (h)ead of (p)ath of % (current buffer), i.e. path of current file
let l:dir = expand('%:p:h')
" Remove final / and smack a /Makefile on the end, glob gives empty if file doesn't exist
while empty(glob(substitute(l:dir, '/$', '', '') . '/Makefile'))
" There's no Makefile here. Are we at the root dir?
if l:dir ==# "/"
" Just use dir of current file then
let l:dir = '.'
break
else
" Try the parent dir. Get (h)ead of dir, i.e. remove rightmost dir name from it
let l:dir = fnamemodify(l:dir, ':h')
endif
endwhile
" Makefile is in this dir, so local-cd (only this window) to the dir
execute "lcd " . l:dir
endfunction
function! MyQuickfixCmdPost()
" Get number of valid quickfix entries, i.e. number of errors reported,
" using filter to check the 'valid' flag
let l:err_count = len(filter(getqflist(), 'v:val.valid'))
if l:err_count ==# 0
" The make succeeded. Execute the Run script expected in the same dir as Makefile
call system('./Run')
redraw!
endif
endfunction
With this in place, after typing :mak in vim, the code is made and run... There are two possible results:
If there are errors during make, vim will present these errors with a Press ENTER or type command to continue afterwards, which is all good.
If make succeeds without errors, however, my Run script is executed, for testing my code (in this case an html file shown in a browser), but then when I switch back to vim, I have to press enter to get rid of a message from vim that I don't need to read because it doesn't tell me about errors. This message used to look like this:
"includes/m4includes/subs.m4" 34L, 759B written
:!make 2>&1| tee /var/folders/zk/0bsgbxne3pe5c86jsbgdt27f3333yd/T/vkbxFyd/255
m4 -I includes/m4includes page-generator.m4 >html-page/mypage.html
(1 of 1): m4 -I includes/m4includes page-generator.m4 >html-page/mypage.html
Press ENTER or type command to continue
but after introducing the redraw! in MyQuickfixCmdPost() is now reduced to:
(1 of 1): m4 -I includes/m4includes page-generator.m4 >html-page/mypage.html
Press ENTER or type command to continue
yet still with the need to press enter.
How do we avoid having to press enter every single time we return to vim after a successful compilation? Any ideas?
Note: vim has a -silent command-line option, but as far as I can see this would silence all the Press ENTERs, and the goal here is to only avoid them after a successful make.
Just add call feedkeys("\<CR>") afterwards. There are not many places you need feedkeys() (often normal! or similar commands will do), and there are subtle effects (look at the flags it takes carefully). Fortunately this is one place it is useful.

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

Forcefully quit vim even if pattern not found

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.

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