Global plugin in VIM is not loaded - vim

I love the dragvisuals vim plugin introduced in Damien Conway's OSCON 2013 talk. There is a github clone for the plugin here: https://github.com/atweiden/vim-dragvisuals. The problem is I can't get it to work. Here are the steps that I have taken:
1.Drop the script in my $VIMRUNTIME/plugin path and added the relevant settings to my .vimrc
ru plugin/dragvisuals.vim
vmap <expr> <LEFT> DVB_Drag('left')
vmap <expr> <RIGHT> DVB_Drag('right')
vmap <expr> <DOWN> DVB_Drag('down')
vmap <expr> <UP> DVB_Drag('up')
vmap <expr> D DVB_Duplicate()
let g:dvb_trimws = 1
2.The script gets loaded successfully because it is output by :scriptnames
/vim/runtime/path/dragvisuals.vim
But all of the functions (DVB_Drag, DVB_Duplicate) are not loaded. Am I missing anything?
EDIT:
At first I tried putting the script in ~/.vim/plugin as well as as ~/.vim/bundle/vim-dragsvisual/plugin because I use vundle to manage my plugins. But it didn't work; that's why I put the script in $VIMRUNTIME as the last resort.

Start again by placing the plugin in ~/.vim/plugin and removing the ru plugin/dragvisuals.vim from your ~/.vimrc.
Installed correctly, that plugin seems to work perfectly and does exactly what it's supposed to do, here.
Never touch $VIMRUNTIME.

Related

In vim with pathogen, how can I check if a plugin will be loaded?

I'm using pathogen to manage my plugins in vim, and I have a section in my vimrc that I would like to run only if a certain plugin isn't installed/won't be loaded. E.g.
if(dwm.vim not in use)
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
endif
The two options that would probably work in most cases are to check if dwm.vim is in g:pathogen_disabled and/or to check if the directory .vim/bundle/dwm.vim exists.
However these checks seem somewhat brittle. For example if I don't have dwm at all checking for dwm.vim not to be pathogen disabled is insufficient, and if for whatever reason dwm.vim is in some nonstandard location that still makes it into the runtimepath the path check won't work.
The whole point of pathogen is to make managing my runtimepath easier, so an elegant solution would be to search this path. But searching the help, the pathogen source, google, and here revealed no easy way to do this. Can I do this in vim/pathogen natively? Is there a plugin that will do this for me? Should I not be doing this at all, since the cases where the checks fail are fairly corner-casey and won't happen as long as I manage my plugins properly?
Most plugins have a (re)inclusion guard. Usually named g:loaded_pluginname. Using this and the after directory you can conditionally load your mappings.
Put the following in ~/.vim/after/plugin/dwm.vim:
if !get(g:, 'loaded_dwm', 0)
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
endif
For more help see:
:h write-plugin
:h after-directory
:h get()
Add this after pathogen#infect():
if globpath(&runtimepath, 'dwm.vim', 1) !=# ''
" dwm.vim caught in the act
endif

How do I debug a non-functioning keymap in Vim?

I ask this question generally, but I will put it in terms of the specific problem I'm having.
I'm using the vim-lawrencium plugin for a project under Mercurial source control. I use the :Hgstatus command to open the status buffer.
The status buffer comes with some nice keymaps to make it easy to add files to the commit, look at diffs, and finalize the commit.
nnoremap <buffer> <silent> <cr> :Hgstatusedit<cr>
nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr>
nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.', 'Wbe')<cr>
nnoremap <buffer> <silent> <C-D> :Hgstatustabdiff<cr>
nnoremap <buffer> <silent> <C-V> :Hgstatusvdiff<cr>
nnoremap <buffer> <silent> <C-U> :Hgstatusdiffsum<cr>
nnoremap <buffer> <silent> <C-H> :Hgstatusvdiffsum<cr>
nnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr>
nnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr>
nnoremap <buffer> <silent> <C-R> :Hgstatusrefresh<cr>
nnoremap <buffer> <silent> q :bdelete!<cr>
Most of these seem to work. I've successfully tried diffing, adding, and q to close the status, but the <C-S> shortcut doesn't work at all. I can manually run the :Hgstatuscommit command it's mapped to. I've also looked at :map to verify the key is actually mapped for that buffer, and it does show up in the list.
What is my next step in debugging this? I want to fix this specific problem, but I also want to know how to fix it in the event I run across broken shortcuts in the future. I'm new to Vim, so I'm at a bit of a loss at this point.
UPDATE: Output of :verbose map <C-S>
v <C-S> *#:Hgstatuscommit<CR>
Last set from ~/.spf13-vim-3/.vim/bundle/vim-lawrencium/plugin/lawrencium.vim
n <C-S> *#:Hgstatuscommit<CR>
Last set from ~/.spf13-vim-3/.vim/bundle/vim-lawrencium/plugin/lawrencium.vim
SOLUTION: Turned out the problem was that my shell was intercepting Ctrl-S and it was never getting to Vim.
I added a Vim alias to my .zshrc to fix:
alias vim="stty stop '' -ixoff ; vim"
ttyctl -f
Found the fix on the Vim Wikia which also has a solution for bash shells.
Software Flow Control
If you are using using a terminal then it is often the case that <c-s> is being used for terminal's software flow control (XON/XOFF). Which makes <c-s> a trickier key to map.
Turn off flow control by adding the following to some startup script (e.g. ~/.bash_profile or ~/.bashrc):
stty -ixon
If you have frozen your terminal then you can unfreeze it by pressing <c-q>.
Generic map debuging
You can debug pretty much any custom vim mapping via the following command:
:verbose map
This will list out each key/chord ({lhs}) maps to what command ({rhs}), mode, and file the mapping was sourced from. For more information on this listing see :h map-listing and :h :map-verbose.
We can filter this list in a few ways:
Supplying a mode. e.g. :verbose nmap for normal mode and :verbose imap for insert mode.
Proving the key we want to query for. e.g :verbose nmap <c-s>
Can also see buffer specific mappings by adding <buffer>. e.g. :verbose nmap <buffer> <c-s>
So for your question the best way to debug what your mapping is set to would be to run the following query:
:verbose nmap <buffer> <c-s>
Note: Vim's native command are not listed via :verbose map. The best way to find one of Vim's native commands is to help. See :h for more.
First, check that <C-S> still mapped to :Hgstatuscommit
map <C-S>
Hgstatuscommit calls s:HgStatus_Commit. Open its definition on line 1134 and put some debugging print outs:
echom a:linestart
echom a:lineend
echom a:bang
echom a:vertical
After using the mapping, check :messages.
I’d suspect that <C-S> is mapped to something else. You can use :map
<C-S> to check how (or if) its mapping is configured. Even better, you can
add the prefix to see where the mapping was set from, e.g., when I run
:verbose map <C-L>, the following is displayed:
<C-L> * :noh<CR><C-L>
Last set from ~/.vimrc
By contrast, I haven’t set a mapping for <C-S> so when I run, :map <C-S>,
I get:
No mapping found
Prepending verbose to a command is a useful general debugging technique as it can show where any Vim option was set, e.g., :verbose set background? shows what the background option is currently set to and which Vim configuration file it was set in:
background=dark
Last set from ~/.vimrc

Vim map failed unless reload .vimrc

I want to do the following maps in my .vimrc.local
```
inoremap <C-H> <Left>
nnoremap <C-H> <C-W><C-H>
inoremap <C-J> <Down>
inoremap <C-K> <Up>
inoremap <C-L> <Right>
```
When I restart my vim, the fist two mapping failed, and the last three commands succeeded. However, when I source ~/.vimrc.local, then all the five mapping methods are OK. That means, I need to load my .vimrc.local myself.
I've already write source ~/.vimrc.local in my .vimrc . And if I source ~/.vimrc rather than .vimrc.local, it works as well.
What's wrong with my mapping? Is there any conflict? I searched in my .vimrc and .vimrc.local, but didn't find conflicts.
I'm using OS X 10.9 and MacVim Snapshot 71, and the main .vimrc from spf13. There are my .vimrc and .vimrc.local.
How can I do the mapping without manually reload .vimrc?
Thanks!

How do I map ctrl x ctrl o to ctrl space in terminal vim?

After searching a bit on the net it seems that I can't map CtrlSpace to anything/alot. Is there a way to do it today, what I found was usually 2 years old.
I've run into the same issue, the short answer is yes you can, and not only in the gui version. Adding this on you .vimrc is enough:
inoremap <C-Space> <C-x><C-o>
inoremap <C-#> <C-Space>
The problem seems to be that Terminal.app doesn't interpret <C-Space> correctly and Vim understands it as <C-#> which is a built-in mapping (:help CTRL-#).
Maybe you could go with something like the following in your .vimrc:
if !has("gui_running")
inoremap <C-#> <C-x><C-o>
endif
which seems to work, here, but I don't like the idea of overriding built-ins like that.
Instead you should try with <Leader> (:help leader), it gives you huge possibilities for defining your own custom mappings and (depending on the mapleader you choose) won't interfere with OS/app specific shortcuts/limitations and hence be more portable.
With this in my .vimrc:
let mapleader=","
inoremap <leader>, <C-x><C-o>
I just hit ,, to complete method names.
The nitpicker broke pablox solution. The crux of the solution was just about remapping. So when you disable remapping, it cannot work.
If you really want to throw in a noremap, this is what it looks like:
inoremap <expr><C-space> neocomplete#start_manual_complete()
imap <C-#> <C-Space>
What will not work: inoremap <C-#> <C-Space> 'cause the <C-Space> part will not be remapped itself.
Have you tried :inoremap <c-space> <c-x><c-o> ?
Does CtrlX CtrlO do anything when you type in insert mode? Is omnifunc set?
Add the following code to ~/.vimrc:
" Ctrl-Space for completions. Heck Yeah!
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
\ "\<lt>C-n>" :
\ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
\ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
\ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-#> <C-Space>
Source: https://coderwall.com/p/cl6cpq
To accommodate both Windows and Linux I applied this to ~/.vimrc
if has("unix")
inoremap <C-#> <c-x><c-o>
elseif has("win32")
inoremap <C-Space> <c-x><c-o>
endif
I had better results with this set of mappings across all modes on Mac OS. Have not tested Windows or Linux.
I don't understand how the excepted answer is supposed to work in terminal mode.
inoremap <C-space> <ESC>
vnoremap <C-space> <ESC>
cnoremap <C-space> <C-c>
" When in terminal, <C-Space> gets interpreted as <C-#>
imap <C-#> <C-space>
vmap <C-#> <C-space>
cmap <C-#> <C-space>
Like the others said, using inoremap with the correct key for your term (as discovered using i_Ctrl_v) should work. I will add to this another possible cause for problems with insert mode mappings: paste mode. As the docs state:
When the 'paste' option is switched on (also when it was already on):
- mapping in Insert mode and Command-line mode is disabled
This may seem irrelevant, but this very thing tripped me up trying to get a similar inoremap binding to work in Vim 8.2. I had set paste in my .vimrc, and had to chop it up with :finish statements (as [recommended in the vim faq) to isolate the line causing the problem.

Unable to eliminate T in Vim's Taglist

I have the following code in .vimrc
" to eliminate the effect of the line 1560 in taglist.vim
if v:version >= 700
nnoremap <buffer> <silent> t
\
nnoremap <buffer> <silent> <C-t>
\
endif
The command does what it should do. However, the command gives also me the following error at Vim's startup
No mapping found
No mapping found
How can you eliminate the keyboard shortcut, such that you do not get the message in Taglist but you can still use the default "T" for browsing up in Dvorak?
Delete it. I don't use taglist, but the example you gave in your post does nothing.
It is supposed to map something to something, but the right side is missing, i.e. something is supposed to being mapped to "t" and "C-t", but that something isn't defined.
Or, you can do this:
:silent nnoremap <buffer> <silent> t (and analoguous for the second line)
(mapping stays but the message will not be displayed)

Resources