Setting via vimrc does not seem to be reflected inside of VIM - vim

I have the following vimrc:
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
call plug#end()
let g:UltiSnipsExpandTrigger = '<C-j>'
let g:UltiSnipsJumpForwardTrigger = '<C-j>'
let g:UltiSnipsJumpBackwardTrigger = '<C-k>'
The settings of <C-j> for expansion and jumping forward and <C-k> for backward jump is consistent with official documentation https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt
When the above vimrc is sourced from within a file, while the output of :verbose map <C-j> reveals that the settings has been read in from the vimrc.
The output of :verbose map <C-k>, however, is No mapping found.
This is confusing--why would only <C-j> be recorded but not <C-k>?
:echo g:UltiSnipsJumpForwardTrigger provides output <C-j>, and,
:echo g:UltiSnipsJumpBackwardTrigger provides output <C-k> indicating that these settings were read in from the vimrc and yet :verbose map <C-k> does not provide expected output. Animated gif of the various tests provided here: https://imgur.com/qkHau09 and reproduced below.

Related

Why can I combine `Plug` and `set` in vimrc, but cannot `nnoremap`?

I can combine two lines like below,
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
Plug 'sheerun/vim-polyglot' | Plug 'ap/vim-css-color'
set splitright splitbelow
but cannot with nnoremap like below.
nnoremap <Up> gk | nnoremap <Down> gj
Why this happens, and how could I resolve?
solved.
need to trim white space before |.

"mo" to open a file with default application,

When I happened to issue "mo" in NERDTree, it open a file in default application
which is awesome, but, I cannot not refer to a documentation for such an operation.
Where could I find where the "mo" is defined?
It is not in "help".
Here is my vimrc
> execute pathogen#infect()
nnoremap <silent> <F5> :NERDTree<CR>
"syntax enable
set background=dark
filetype plugin indent on
syntax on
"NERDTree Config
autocmd vimenter * NERDTree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif
map <leader>r :NERDTreeFind<cr>
"Edit process
set number
"set ignorecase
"set smartcase
set spell spelllang=en_us
"Switch between the tabs
map <C-l> :tabn<CR>
map <C-h> :tabp<CR>
map <C-n> :tabnew<CR>
It seems that m is mapped to the menu:
call s:initVariable("g:NERDTreeMapMenu", "m")
It doesn't seem to be a default menu-item, since the NERDTree documentation states the following:
A programmable menu system is provided (simulates right clicking on a
node)
one default menu plugin is provided to perform basic filesystem
operations (create/delete/move/copy files/directories)
There's an API for adding your own keymappings
The last item is your key here, there is an API which allows you and other plugins to expand the menu:
call NERDTreeAddMenuItem({
\ 'text': 'e(x)ecute',
\ 'shortcut': 'x',
\ 'callback': 'NERDTreeExecute' })
This is an example from this plugin:
https://github.com/ivalkeen/nerdtree-execute/blob/master/nerdtree_plugin/execute_menuitem.vim
So I bet you have another Plugin installed which maps o as shortcut in the NERDTreeMenu.

How to unmap vim shortcuts upon quickfix exits

Background: I'm using skwp's dotfiles, and his recently changes is breaking some functionalities I use on daily basis.
Instead of set up the mappings globally, I'm trying to nnoremap two shortcuts upon quickfix enters and nunmap after quickfixes quits.
BTW, I think syntastic is used for linting, which invokes the quickfix/location lists.
Here's the code:
augroup quickfixShortcutsGroup
autocmd!
autocmd BufWrite * :echom "Foo"
" au BufReadPost quickfix nnoremap <silent> <C-z> :cp<CR>
" au BufReadPost quickfix nnoremap <silent> <C-x> :cn<CR>
au BufWinEnter quickfix nnoremap <silent> <C-z> :cp<CR>
au BufWinEnter quickfix :echo '1'
au BufWinLeave quickfix nnoremap <silent> <C-z> :cp<CR>
au BufWinLeave quickfix :echo 'BufWinLeave'
au BufLeave qf :echo 'BufLeave'
au BufUnload qf :echo 'unload qf'
" au BufLeave qf noremap <silent> <C-z> :cb<CR>
" au BufLeave quickfix noremap <silent> <C-z> :cb<CR>
" au BufWinLeave quickfix noremap <silent> <C-z> :cb<CR>
" au BufWinLeave quickfix nunmap <C-z>
" au BufWinLeave quickfix :echom 'Hello'<cr>
" BufWinEnter
augroup END
After read reference:
http://vimdoc.sourceforge.net/htmldoc/autocmd.html#BufWinLeave
http://vimdoc.sourceforge.net/htmldoc/autocmd.html#autocmd-patterns
I still could not get unmap events working, i.e. BufWinLeave, BufUnload, BufLeave are not invoked.
Can Vimers tell me which event(s) I should be using and help me out on this? Thank you in advance for the help.
As :help BufWinLeave explains, the current buffer "%" may be different from the buffer being unloaded "". So you need a global autocmd, and resolve the buffer number that has been left, and then check for the quickfix 'buftype':
autocmd! BufWinLeave * if getbufvar(bufnr(expand('<afile>')), '&buftype') ==# 'quickfix' | echo "leaving quickfix" | endif
But in general, I'd advise against such tricks and especially conditional mappings. Your <C-z> / <C-x> mappings are still global, now just depending on whether the quickfix list is visible. That's bad for muscle memory, and the overload of the key combos is mentally taxing. I'd rather get rid of the mappings completely, or assign different (if potentially longer) keys.
And there's the next complication: Vim "distributions" and other people's dotfiles lure you with a quick install and out-of-the-box settings, but you pay the price with increased complexity (you need to understand both Vim's runtime loading scheme and the arbitrary conventions of the distribution) and inflexibility (the distribution may make some things easier, but other things very difficult). Vim is incredibly customizable, using someone else's customization makes no sense.
If you would like to nnoremap these two mappings upon quickfix enters and nunmap after quickfix quits, you could
" map silently upon entering Quickfix
autocmd BufWinEnter * if &buftype == 'quickfix'
\| nnoremap <silent> <C-x> :cn<CR>
\| nnoremap <silent> <C-z> :cp<CR>
\| endif
" unmap upon leaving Quickfix
autocmd BufWinLeave * if &buftype == 'quickfix'
\| nunmap <C-x>
\| nunmap <C-z>
\| endif
Or you can make use of local buffer mapping to make your code shorter
" map silently upon entering Quickfix, and only for Quickfix
autocmd BufWinEnter * if &buftype == 'quickfix'
\| nnoremap <buffer><silent> <C-x> :cn<CR>
\| nnoremap <buffer><silent> <C-z> :cp<CR>
\| endif
These autocmd's are invoked every time you enter or leave a buffer. So it is really better just, as Sato Katsura suggested, add in your ~/.vim/ftplugin/qf.vim
nnoremap <buffer><silent> <C-x> :cn<CR>
nnoremap <buffer><silent> <C-z> :cp<CR>
You may consider to read these:
:h ftplugins
:h map-local
:h buftype
:h line-continuation

How can I show winmanager automatically?

I’ve installed the winmanager, NERDTree and BufExplorer plugins. Now, I have <F8> set to toggle the winmanager display, using the following code in my .vimrc:
" mapping for triggering winmanager plugin
nnoremap <silent> <F8> :if IsWinManagerVisible() <BAR>WMToggle<CR><BAR> else<BAR> WMToggle<CR>:q<CR> endif <CR><CR>
This works fine.
What I want to do is to have winmanager show up automatically if the filetype is .c or .cpp. I added this to my .vimrc:
autocmd FileType c,cpp nested "\<F8>"
but it does not work.
Any help? Thanks in advance!
<F8> is a normal-mode mapping, but :autocmd expects an Ex command on its right-hand side. You need to use :normal (without a ! here, to allow mappings to take effect), and :execute to interpret the special key code:
:autocmd FileType c,cpp nested execute "normal \<F8>"
But I think it is cleaner to avoid the additional redirection and duplicate the mapping's commands instead:
:autocmd FileType c,cpp nested if IsWinManagerVisible() |exe 'WMToggle'| else| exe 'WMToggle' | quit | endif

No lines in buffer when writing in Vim

I'm running MacVim with MiniBufExplorer amongst some other plugins. What I have noticed is that occasionally when I edit a file and try to write it (:w), I get the message
--No lines in buffer--
If I then enter :w again the file writes successfully. It seems to sprout up randomly but once it starts happening it continues to happen with every file in the buffer until I close/restart MacVim.
EDIT:
Plugins currently used:
Pathogen
Ack
Command-T
MiniBufExpl
Nerdtree
Pep8
Pydoc
Ropevim
Supertab
Tagbar
Current .vimrc
filetype off
call pathogen#infect()
call pathogen#helptags()
set foldmethod=indent
set foldlevel=99
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
syntax on
filetype on
filetype plugin indent on
au FileType python set omnifunc=pythoncomplete#Complete
let g:SuperTabDefaultCompletionType = "context"
set completeopt=menuone,longest,preview
map <leader>n :NERDTreeToggle<CR>
map <leader>j :RopeGotoDefinition<CR>
map <leader>r :RopeRename<CR>
map <leader>o :TagbarToggle<CR>
nmap <leader>a <Esc>:Ack!
autocmd BufEnter *.py set ai sw=4 ts=4 sta et fo=croql
colorscheme desert
map J 15j
map K 15k
set noswapfile
set nobackup
set nowritebackup
For me the problem was caused by minibufexplorer. The fix has been included in v6.5.0 of fholgado, consisting of inserting the silent keyword below in minibufexpl.vim
" Delete all lines in buffer.
silent 1,$d _

Resources