Simple mappings like let mapleader = "," don't seem to be working, so I reinstalled vim and removed all plugins. Yet some mappings like this still don't work. Where can I find vim plugin config files? I've looked in ~/.vim and ~/.config. When I type a comma in command mode, instead of starting the mapleader command, my mac gives me an alarm bell sound. I included let mapleader = "," as the first line in my .vimrc.
UPDATE To help diagnose, I have this line in my .vimrc:
noremap <silent> <Leader>w :w<CR>
When I type :map in vim, I see, among other mappings:
,w * :w<CR>
The most elaborate information you'll get by running vim via vim -V.
This will give you information on every file that vim looks for, finds and opens.
The most important are ~/.vimrc and /usr/share/vim/*.
Besides, please verify that your mapleader command is at the beginning of your vimrc.
From the manual:
Note that the value of "mapleader" is used at the moment the mapping is
defined. Changing "mapleader" after that has no effect for already defined
mappings.
EDIT
To verify if it's enabled for sure, type :let mapleader in a running vim. It should print something like mapleader ,. Please verify it, so we can think of other causes.
Try placing your mappings in a file called ~/.vimrc.
The ~/.vim directory is used to store plugin files, whereas the ~/.vimrc file is typically used for generic settings like mappings.
Note that the value of "mapleader" is used at the moment the mapping is defined. Changing "mapleader" after that has no effect for already defined mappings.
Are you sure you are defining map leader before you create your mappings? If not, your mapleader is probably , just as your define, but all your macros will be mapped to \.
A Vim plugin usually "configures itself" in ~/.vim/plugin/pluginname.vim, not in an external file. The configuration typically consists of variables (e.g. g:pluginnameSettingName) and mappings, which should appear in this format:
nnoremap <silent> <Plug>(PluginMapping) :<C-u>call pluginname#MyFunc()<CR>
if ! hasmapto('<Plug>(PluginMapping)', 'n')
nmap <Leader>x <Plug>(PluginMapping)
endif
If the default mapping starts with <Leader>, your intended change via :let mapleader should work. Alternatively, you can try to explicitly override the mapping by mapping your own keys to the <Plug>... mapping.
I really suggest you use a practical plugin Vundle to manage your vim plugins. It would enable you to manage your plugins in text format and config parameters of each plugins separately.
For instance, if you want to install a new plugin 'a.vim', you just need to add a line into your bundle.vim
Bundle 'a.vim' (for any plugins you can access from VimScripts you could just type the short name like 'c.vim' or 'Tagbar'). Restart Vim and run :BundleInstall, Vim will install the new plugins automatically.
In the same way, when you want to uninstall the plugin, just remove the line Bundle 'a.vim' in your configuration file and run :BundleClean, the plugin will be removed automatically.
Related
I want to make a filetype plugin(in fact asm) of vim. After Searching for a while on the Internet, i found that i should add a asm.vim in ~/.vim/ftplugin folder. So I added that new file asm.vim in that folder and wrote the following codes:
map <F7> oTest<CR><Esc>
a very simple vim script, only output the Test string in the next line. but i failed, when i opened an xxx.asm file and pressed <F7> button, nothing happened. Anything wrong with the code? any help appreciated!
You need to ensure that Vim actually detects the filetype; asm is defined in $VIMRUNTIME/filetype.vim, and there is a syntax, but no filetype plugin yet. Check that
:set filetype?
outputs asm. If not, you need to work on the detection.
You also need to have :filetype plugin on (in your ~/.vimrc); otherwise, no filetype plugin scripts aren't loaded. Check with :scriptnames.
Also note that you should not define global mappings or commands in a filetype plugin. Use :noremap <buffer> <F7> ....
You can check your mapping exists with :verbose map <F7>.
A plugin adds to my insert mappings a mapping for <leader>is. I have some ideas which one it can be. But it does not matter I don't want to change anything in foreign plugins. So I want to disable this mapping. I tried this:
imap <leader>is <nop>
I did not help.
What is your suggestions?
BTW, I want to ask how disable in vimrc all insert mapping of plugins?
To remove an insert mode mapping, use the :iunmap command:
:iunmap <Leader>is
I don't know whether it is possible to do "bulk unmapping", but at least you can list all active insert mode mappings with
:imap
or, even better, with
:verbose imap
which will also tell you where the mapping has been defined in the first place.
Edit: To clarify, the unmapping needs to be done after the plugin has been loaded. To do so, create a file with the following contents in ~/.vim/after/plugin/ (see #ZyX's answer):
" myafter.vim: will be executed after plugins have been loaded
iunmap <Leader>is
Your command if inserted in the vimrc is executed before plugin defines the intrusive mapping and this is why it has no effect. To make it have effect you should make it run after that plugin which is normally achieved either by putting it into ~/.vim/after/plugin/disable_mappings.vim (any name instead of disable_mappings works). Second is using VimEnter event:
augroup DisableMappings
autocmd! VimEnter * :inoremap <leader>ic <Nop>
augroup END
. To disable all mappings see :h 'paste' and :h 'pastetoggle', also :h :imapclear (though the latter will remove mappings instead of temporary disabling them).
Of course, you may also use iunmap just where I suggested to use inoremap … <Nop>. How did I came to forget this command?
It took me almost two years of programming till I decided to switch Textmate for Vim and I love it so far. However, after playing with it for a few days I hit a first issue.
As a beginner I reached for Janus as many people do but in the end I decided to create my own configuration from scratch to get to know the stuff better. I backed my configs up and started writing my new .vimrc file. But later on (pretty early) I noticed that leader key isn't working, it does nothing when I press it, well it just beeps. I didn't change the key for a leader nor did any key mapping so I was kinda surprised.
So once again I removed my .vimrc file and .vim directory to start with a clean state. It didn't help. So I opened Vim and tried to reconfigure a leader to a different key to see if it helps.
:let mapleader
> E121: Undefined variable: mapleader
:let mapleader = ','
:let mapleader
> mapleader ,
Looks fine but nothing really happened. Even when I put it under a different key my Mac just beeps and thats it. There's no vim configuration in my home directory, no plugins, nothing. Setting leader in '.vimrc' instead of vim console doesn't help either.
I saw some discussions here on timeouts for key pressing but it have not got me anywhere.
I'm kinda stuck here and not able to use Vim for my day to day job even if I'd love to. Any help would be highly appreciated.
Follow these steps carefully…
Create a blank .vimrc file in your $HOME directory:
$ cd
$ touch .vimrc
Vim should now run in "nocompatible" mode which is what we all want.
Open your blank ~/.vimrc and add these lines:
let mapleader=","
nnoremap <leader>a :echo("\<leader\> works! It is set to <leader>")<CR>
Hit ,a, you should obtain the following message in the command line.
<leader> works! It is set to ,
<leader> may not be useful right from the start, though, there are other things to worry about.
Anyway, from there, I'd suggest you to add these few non-opinionated settings that will make your life considerably easier:
filetype plugin indent on
syntax on
set autoindent
set hidden
set incsearch
filetype plugin indent on allows Vim to recognize the filetype of the files you open and to apply all sorts of built-in filetype-specific settings (indent rules, completion…).
syntax on turns syntax highlighting on.
set autoindent copies the indent of the current line when you do <CR> life sucks so much if this is off.
set hidden allows you to open a new file or switch to another buffer without saving the changes to the current one.
set incsearch makes search-based navigation (/foo, ?bar) instantly awesome by turning incremental search on.
After that, it's up to you to add settings and mappings as you need them.
It's working, but the mappings preceding the change won't understand the changed leader character. For example, if I have a .vimrc that says
nnoremap <Leader>a :echo "test"<cr>
Then I can start up vim and hit \a to get test in the bottom left. However, if you type :let mapleader = ',' then do ,a it doesn't work because you changed leader after the mapping. If you then type :nnoremap <Leader>a :echo "test"<cr> and try ,a again it will work. Thus, :let mapleader = must come before mappings that use <Leader>.
After installing vim-ruby-debugger that plugin "hijacks" several mappings. Like <leader>n, or <leader>t which I use for respectively NERDTreeToggle and Command-T find.
The culprit is found at the hardcoded mappings in this ruby-debugger.
I'd prefer to have these remapped as <leader>rdX, i.e.: prefixed with *r*uby-*d*ebugger. Obviously, I could simply hack the plugin and change the mappings there. But that seems a bit too hackish (and will probably break on updates).
How can I unmap these mappings, so vim will fallback to my own mappings again? And so that I can remap the commands in my .vimrc (where it should be, IMHO).
First, I agree with ZyX's comments that this is a problem in the plugin that should be fixed. Please ask the plugin author to provide customization.
There is no easy way to unmap, because Vim does not remember the original mappings when a mapping is overridden. You have to make a note of the original mappings (:map ... when the offending plugin is temporarily disabled, or look in the Vim script for their definitions), then re-execute them after the offending plugin has been loaded (minus any <unique> flags it may have, as these will cause errors on re-execution). This cannot be done in .vimrc, it is sourced first; I would recommend a place like ~/.vim/after/plugin/zzzmappings.vim for this.
I keep all of my mappings in after/plugin/keys.vim. This seems to ensure that they always take precedence over plugin mappings. (I use a bunch of plugins, and the collisions seem taken care of) (here's my nvim config)
FWIW, I also keep filetype-specific mappings in the same folder, but write them as autocmd FileType commands with the <buffer> keyword. For example, the following is a mapping that conflicts with bullets.vim's ToggleCheckbox function (it adds an empty checkbox to the bullet if there is none)
autocmd FileType markdown nnoremap <buffer> <expr> <leader>x (getline('.') =~ '^\s*- \[' ? ':ToggleCheckbox<cr>' : '0/-<space><cr>la[<space>]<space><esc>')
I'm on this computer (ubuntu) where TAB is mapped (I can't find where) to autocomplete. I searched and seems like this is done by supertab, although I couldn't find how to disable it, neither did I find its files.
In my ~/.vimrc and /usr/share/vim/vimrc files, there is no mapping of the tab key. The later file includes debian.vim (and tries with /etc/vim/vimrc.local, but that doesn't exist) but that also doesn't have any mappings of tab, or any reference to supertab.
The output of :map! is this:
i <S-Tab> * <C-R>=BackwardsSnippet()<CR>
i <Plug>SuperTabBackward & <C-R>=<SNR>13_SuperTab('p')<CR>
i <Plug>SuperTabForward & <C-R>=<SNR>13_SuperTab('n')<CR>
i <C-Tab> * <Tab>
i <Tab> * <C-R>=TriggerSnippet()<CR>
i <CR> * <C-R>=<SNR>13_SelectCompletion(1)<CR>
i <C-N> <Plug>SuperTabForward
i <C-P> <Plug>SuperTabBackward
i <C-R><Tab> * <C-R>=ShowAvailableSnips()<CR>
i <C-X> <C-R>=<SNR>13_ManualCompletionEnter()<CR>
Which indicates that supertab is indeed mapping these keys.
I tried putting nomap! <TAB> in my ~/.vimrc, but it doesn't work as it seems like supertab is being loaded after ~/.vimrc is read.
My question is, how can I disable supertab, or alternatively make sure ViM doesn't let anyone map TAB to anything else?
Supertab is a plugin. As such it should be installed somewhere in ~/.vim/. There are many ways to install plugins (default, pathogen, vundle, etc.). Look into ~/.vim/bundle (if you use Pathogen) or in ~/.vim/plugin.
If it's not there it may have been installed in /usr/share/vim/vim7x/ which is very crowded and should not be touched in any way: good luck.
Anyway, you can do :verbose map! to see where the mappings are set (and thus, where the plugin is installed if you want to remove it) or you could simply configure Supertab to not use <tab>. See :help supertab.
In case you don't want to completely get rid of supertab you can remap the default keybindings using something like (in your ~/.vimrc):
let g:SuperTabMappingForward = '<c-space>'
let g:SuperTabMappingBackward = '<s-c-space>'
If you only want to insert literal tab characters, supertab makes it easy by mapping literal tabs to ctrl+tab by default (which unfortunately doesn't work in terminal). It can be customized by using something like:
g:SuperTabMappingTabLiteral='<C-`>'
Lastly, you can always escape a mapping by prepending it with ctrl-v in insert mode.
see :h supertab-forwardbackward for more information. (might not work if you haven't built supertab docs)