The :Gstatus window has specific mappings for that particular buffer. In my case, I would like to change the cc mapping to not only execute :Gcommit but also go into insert mode afterwards.
It seems like the user robodendron figured out how to do this as shown in https://github.com/tpope/vim-fugitive/issues/647, but I'm don't know what he means when he says "changing the order should be enough." Also, I would ask this on the Git issues page, but it seems like the user NicolasWebDev already tried that and no one got back to him.
I can add mappings by creating a after/ftplugin/gitcommit.vim file, but modifying an existing mapping seems to be more difficult since the mapping is defined after the filetype is set.
Also, I could modify the source code mappings, but we all know that's more of a temporary fix.
I am not sure about trying to alter :Gstatus mappings, but you can start insert mode when entering the commit buffer.
Add the following to your vimrc file:
augroup turbo_commit
autocmd!
autocmd BufEnter COMMIT_EDITMSG startinsert
augroup END
For more help see:
:h :autocmd
:h :augroup
:h BufEnter
:h startinsert
Related
I want to create a plugin which maps a certain localleader mapping to a function call.
I have a ftplugin/javascript.vim file with the following content:
augroup javascript_pluginName
au!
echom "The plugin is loaded for JS"
au FileType javascript nnoremap <buffer> <localleader>j :call pluginName#pluginName#funName()<cr>
augroup END
When I open a javascript file, the message is printed, but then checking the mapped combinations shows that there is no such mapping.
I understand, that nnoremap is simply not going to map on top of other mappings. However, if I only leave the nnoremap command, without putting it in an autocmd, it would map properly.
Simply executing the call in command mode also works fine.
I looked into the vim help to see how to use autocmd, and I can't see any difference between the way I use it and what is explained there. The "Learn Vim the Hard Way" book also didn't help.
Is there something I'm missing? Should I frame the autocmd somehow differently?
I finally found out what the problem is!
Apparently, according to this article: https://vimways.org/2018/from-vimrc-to-vim/ if you put a filetype specific code into a filetype plugin, there is no need to create an autocmd for it.
The boilerplate is all made redundant by the general behaviour of vim setting the filetype on open and then running the ftplugin scripts, which are relevant for the file.
This means that in my ftplugin/javascript.vim file I only need the mapping:
nnoremap <buffer> <localleader>j :call pluginName#pluginName#funName()<cr>
Currently, I'm trying to clean the quickfix window while using cscope and to do that I'm using these commands:
augroup quickfix
autocmd!
autocmd BufRead qf set modifiable
autocmd FileType qf
\ set modifiable |
\ set hidden |
\ execute ":%s/<<.*>>//g"
augroup END
This way whenever a file is opened the <<>> tags are removed. However, since by default the quickfix window is nomodifiable I'm having to force it.
During testing I found that the replacement is executed but the quickfix window is still nomodifiable afterward; therefore I cannot edit its content or use it as notes. Modifiable can be set by hand once the window is opened, but this is not convenient. Maybe I`m missing something or using the wrong event. Can someone explain what is wrong?
It's not urgent to deal with autogroup before you are familiar to them enough.
Just try or do it in your .vimrc with a line like below:
au BufRead errors.err set ma hidden | execute ":%s/<<.*>>//g"
then the quickfix file (usually named as 'errors.err') should be modifiable.
(If you use a different name, substitute it for the 'errors.err', or use a pattern like '*.err'.)
See :h au for further info.
I suspect there is something inherently inefficient about your process of using the quickfix list, but if you wanted to abuse it this way and make it modifiable the following works for me:
au! FileType qf set ma hidden | execute ":%s/<<.*>>//g"
au! BufReadPost quickfix set ma
See :h CTRL-W-<Enter> for some further information.
I use MacVim and in my .vimrc file I have map ,V :source $MYVIMRC<CR> binding that allows me to apply the newest version of .vimrc in a case it was recently modified.
However I noticed that strange things can happen, relaunch can slow down vim and some plugins can start to conflict after pressing ,V, when everything works fine if I just close and relaunch MacVim from the scratch.
I'd be very thankful if you could give me a hint on the reason of this behavior as I'd like to have a possibility to update .vimrc file that will completely clear internal vim state and grab new configuration file
The only viable way to re-apply your config to a pristine Vim is actually to restart it.
But the most likely cause of slow downs is the overuse/misuse of autocommands.
Autocommands are added without checking for existing ones. One consequence is that they tend to pile-up if you don't manage them properly and every individual autocommand corresponding to a specific event is executed when that event is triggered, leading to dreadful slow downs.
Here are the two ways you are supposed to use autocommands in your vimrc:
Method #1
" anywhere
augroup nameofthegroup
autocmd!
autocmd EventName pattern commandtoexecute
autocmd AnotherEventName anotherpattern anothercommandtoexecute
augroup END
Method #2
" near the top of your vimrc
augroup nameofthegroup
autocmd!
augroup END
" anywhere
autocmd nameofthegroup EventName pattern commandtoexecute
autocmd nameofthegroup AnotherEventName anotherpattern anothercommandtoexecute
The idea is to create a group of autocommands that clears itself whenever it is invoked and thus prevents them from piling-up.
Basically I would like to be able to quickly look up Vim's help pages for specific commands. To do that, I am using this mapping:
nnoremap K :help <C-r><C-w><CR>
However, I would like to apply this mapping only to my .vimrc (in order to be able to use different lookup documentations for different files).
Is that possible?
K already does keyword lookup but the associated 'keywordprg' option is rarely defined.
Add the snippet below to your ~/.vimrc to get the desired behavior:
augroup vim
autocmd!
autocmd FileType vim setlocal keywordprg=:help
augroup END
Thanks for reminding me to set it up correctly in my own config.
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?