How I can refactor imap nmap vmap code in vim? - vim

I can such code in my .vimrc file:
imap <D-1> <ESC>1gt
vmap <D-1> 1gt
nmap <D-1> 1gt
imap <D-2> <ESC>2gt
vmap <D-2> 2gt
nmap <D-2> 2gt
imap <D-3> <ESC>3gt
vmap <D-3> 3gt
nmap <D-3> 3gt
imap <D-4> <ESC>4gt
vmap <D-4> 4gt
nmap <D-4> 4gt
imap <D-5> <ESC>5gt
vmap <D-5> 5gt
nmap <D-5> 5gt
imap <D-6> <ESC>6gt
vmap <D-6> 6gt
nmap <D-6> 6gt
imap <D-7> <ESC>7gt
vmap <D-7> 7gt
nmap <D-7> 7gt
imap <D-8> <ESC>8gt
vmap <D-8> 8gt
nmap <D-8> 8gt
imap <D-9> <ESC>9gt
vmap <D-9> 9gt
nmap <D-9> 9gt
How I can refactor this code?

let i=1
while i<=9
execute "nmap <D-".i."> ".i."gt"
execute "vmap <D-".i."> ".i."gt"
execute "imap <D-".i."> <ESC>".i."gt"
let i+=1
endwhile

Related

How to change vim command execution priority?

I made :wincmd h<CR> shortcut to <leader>h, and mapleader is <Space> to me
but When I do <leader>h, I feel quite long delay to execute this action,
so I searched commands about <leader>h by :map <leader>h and
I found that I have serveral commands start with <Space>h like below
n <Space>hp #<Plug>(GitGutterPreviewHunk)
n <Space>hu #<Plug>(GitGutterUndoHunk)
n <Space>hs #<Plug>(GitGutterStageHunk)
x <Space>hs #<Plug>(GitGutterStageHunk)
n <Space>h * :wincmd h<CR>
I think because of map priority, <Space>h is performed last,
I want to change execution priority <Space>h to first place.
because <Space>h is the best easy way shortcut to me for :windcmd h.
How do I change priority order of map?
==== edit ====
I think vim wait for next character from h,
then How can I eliminate delay for <Space>h?
<nowait> is not working (I don't know why)
remapping for plugin is not working
==== edit2 ==== (it still not work thought adopt first answer)
init.vim
""Source file
source $HOME/.config/nvim/ascii_art.vim
""Plugin-install
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tweekmonster/gofmt.vim'
Plug 'tpope/vim-fugitive'
Plug 'vim-utils/vim-man'
Plug 'mbbill/undotree'
Plug 'sheerun/vim-polyglot'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'stsewd/fzf-checkout.vim'
Plug 'vuciv/vim-bujo'
Plug 'tpope/vim-dispatch'
Plug 'theprimeagen/vim-be-good', {'do': './install.sh'}
Plug 'vim-airline/vim-airline'
Plug 'gruvbox-community/gruvbox'
Plug 'vifm/vifm.vim'
"Theme
Plug 'colepeters/spacemacs-theme.vim'
Plug 'sainnhe/gruvbox-material'
Plug 'phanviet/vim-monokai-pro'
Plug 'flazz/vim-colorschemes'
Plug 'chriskempson/base16-vim'
" fuzzy find files
Plug 'ctrlpvim/ctrlp.vim'
" git gutter
Plug 'airblade/vim-gitgutter'
Plug 'scrooloose/nerdcommenter'
"NerdTree plugins (NerdTree makes vim too slow, so now it unstalled)
"Plug 'scrooloose/nerdtree'
"Plug 'Xuyuanp/nerdtree-git-plugin'
"Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
"Plug 'ryanoasis/vim-devicons'
Plug 'mattn/emmet-vim'
Plug 'vimwiki/vimwiki' "take note
Plug 'mhinz/vim-startify' "easy way to save and load session
call plug#end()
""General-setting
language en_US
syntax on
set number
set relativenumber
set guicursor=
set relativenumber
set nohlsearch
set hidden
set noerrorbells
set tabstop=4 softtabstop=4
set shiftwidth=4 "tab key spaces, = set sw
set expandtab "instead of tab, insert spaces
set smartindent
set nu
set nowrap
set smartcase
set noswapfile
set undofile
set incsearch
set termguicolors
set scrolloff=8 "Scroll offset
set noshowmode
set cmdheight=2
set updatetime=50
set shortmess+=c
set cursorline
set hlsearch "highlight searched words
"NOTE :eol is end of the line
set listchars=eol:↲,tab:→\ ,trail:~,extends:>,precedes:<,space:␣
set nolist "set list => $ is end of the line
"Fold setting: when auto save and load fold
set foldcolumn=2
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent! loadview
highlight ColorColumn ctermbg=0 guibg=lightgrey
""Color Theme
colorscheme gruvbox
"cursorline termguicolors
set background=dark
let g:gruvbox_contrast='soft'
let loaded_matchparen = 1
let mapleader = " "
""Status-line
set statusline=
set statusline+=%#IncSearch#
set statusline+=\ %y
set statusline+=\ %r
set statusline+=%#CursorLineNr#
set statusline+=\ %F
set statusline+=%= "Right side settings
set statusline+=%#Search#
set statusline+=\ %l/%L
set statusline+=\ [%c]
""Key-bindings
nnoremap <leader>gc :GCheckout<CR>
nnoremap <leader>ghw :h <C-R>=expand("<cword>")<CR><CR>
nnoremap <leader>prw :CocSearch <C-R>=expand("<cword>")<CR><CR>
nnoremap <leader>pw :Rg <C-R>=expand("<cword>")<CR><CR>
nnoremap <nowait> <leader>j :wincmd j<CR>
nnoremap <nowait> <leader>k :wincmd k<CR>
nnoremap <nowait> <leader>l :wincmd l<CR>
"bug report:: :wincmd h is mapped with below mapping,
"> but can not use shortcuts for GigGutterPreviewHunk, GitGutterUndoHunk, GitGutterStageHunk
autocmd filetype * nnoremap <nowait> <buffer> <leader>h :wincmd h<CR>
"nnoremap <nowait> <leader>h :wincmd h<CR>
nnoremap <leader>u :UndotreeShow<CR>
"nnoremap <leader>pv :wincmd v<bar> :Ex <bar> :vertical resize 30<CR>
nnoremap <leader>pv :call ToggleNetrw() <bar> :vertical resize 30<CR>
nnoremap <Leader>ps :Rg<SPACE>
nnoremap <C-p> :GFiles<CR>
nnoremap <Leader>pf :Files<CR>
nnoremap <Leader><CR> :<c-u>call <sid>Goto_definition() <CR>
nnoremap <F4> :so ~/.config/nvim/init.vim<CR>
nnoremap <Left> :vertical resize -2<CR>
nnoremap <Right> :vertical resize +2<CR>
nnoremap <Up> :resize +2<CR>
nnoremap <Down> :resize -2<CR>
nnoremap <Leader>rp :resize 100<CR>
nnoremap <Leader>ee oif err != nil {<CR>log.Fatalf("%+v\n", err)<CR>}<CR><esc>kkI<esc>
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
vnoremap X "_d
"built-in mapping disable
nnoremap Q <Nop>
" vim TODO
nmap <Leader>tu <Plug>BujoChecknormal
nmap <Leader>th <Plug>BujoAddnormal
let g:bujo#todo_file_path = $HOME . "/.cache/bujo"
" GoTo code navigation.
nmap <leader>gd <Plug>(coc-definition)
nmap <leader>gy <Plug>(coc-type-definition)
nmap <leader>gi <Plug>(coc-implementation)
nmap <leader>gr <Plug>(coc-references)
nmap <leader>rr <Plug>(coc-rename)
nmap <leader>g[ <Plug>(coc-diagnostic-prev)
nmap <leader>g] <Plug>(coc-diagnostic-next)
nmap <silent> <leader>gp <Plug>(coc-diagnostic-prev-error)
nmap <silent> <leader>gn <Plug>(coc-diagnostic-next-error)
nnoremap <leader>cr :CocRestart
nnoremap <silent> K :call <SID>show_documentation()<CR>
"quickly enter new line in normal mode
nnoremap <Leader>o o<Esc>
nmap ghs <Plug>(GitGutterStageHunk)
xmap ghs <Plug>(GitGutterStageHunk)
nmap ghu <Plug>(GitGutterUndoHunk)
nmap ghp <Plug>(GitGutterPreviewHunk)
"Emmet key
let g:user_emmet_mode="n"
let g:user_emmet_leader_key="," "default leader_key is <c-y> with trailing ,(comma)
" coc config
let g:coc_global_extensions = [
\ 'coc-snippets',
\ 'coc-pairs',
\ 'coc-tsserver',
\ 'coc-eslint',
\ 'coc-prettier',
\ 'coc-json',
\ 'coc-marketplace',
\ ]
"coc snippet
" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)
" Use <C-j> for select text for visual placeholder of snippet.
vmap <C-j> <Plug>(coc-snippets-select)
" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<c-j>'
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<c-k>'
" Use <C-j> for both expand and jump (make expand higher priority.)
imap <C-j> <Plug>(coc-snippets-expand-jump)
inoremap jk <ESC>
vmap ++ <plug>NERDCommenterToggle
nmap ++ <plug>NERDCommenterToggle
let g:NERDTreeIgnore = ['^node_modules$']
" ctrlp
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
" Highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()
" Remap for rename current word
nmap <F2> <Plug>(coc-rename)
"Functions
"show documetation function
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
"sync open file with NERDTree, Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable, file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" autocomplete functions for neoclide/coc.nvim
"---------------------------------------------------------------------------
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-#> coc#refresh()
endif
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
if exists('*complete_info')
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
"open implementation to the right split view(custom function)
"buggy: If you quit after invoke this function, this function will not work(it will quit your only window)
let s:first_open=1
function! s:Goto_definition() abort
if s:first_open
rightbelow vs "same as :vertical split and :wincmd l
normal K
wincmd h
let s:first_open=0
else
wincmd l "If right split window exists then quit
q
rightbelow vs
normal K
wincmd h
endif
endfunction
"---------------------------------------------------------------------------
"" netrw settings
let g:netrw_liststyle=3 "Tree style
let g:netrw_banner = 0 "Remove banner
let g:netrw_browse_split = 4 "Open file in previous window
let g:netrw_altv = 1 "Open vertical split window to the right side
let g:netrw_preview=1 "Preview in right side
set nocompatible "Limit search for your project
set path+=** "Search all subdirectories with recursively
set wildmenu "Show multifiles on one line when you :find
"Root directory:make current directory to root directory
nnoremap <leader>` :Ntree<CR>
let g:NetrwIsOpen=0
function! ToggleNetrw()
if g:NetrwIsOpen
let i = bufnr("$")
while (i >= 1)
if (getbufvar(i, "&filetype") == "netrw")
silent exe "bwipeout " . i
endif
let i-=1
endwhile
let g:NetrwIsOpen=0
else
let g:NetrwIsOpen=1
silent Lexplore
endif
endfunction
let g:netrw_list_hide= netrw_gitignore#Hide()
"=================Unorganized settings==================
"jsx comment
let g:NERDCustomDelimiters={
\ 'javascript': { 'left': '//', 'right': '', 'leftAlt': '{/*', 'rightAlt': '*/}' },
\}
"vimwiki setup
"let g:vimwiki_list = [{'path': '~/vimwiki/',
"\ 'syntax': 'markdown', 'ext': '.md'}]
=== edit for Result (now working) ===
for :map <leader>h now show like this picture
what I did
add 4 snippets from answer
:PlugUpdate => I was out of date.
remove <nowait>
:echo hasmapto('<Plug>(GitGutterStageHunk)', 'n') output 1
when upto 2 step, it didn't work, but after remove nowait it works
something interfereing commands, but I don't know exact reason.
The mappings that include <Leader>h as a prefix will cause this interference. Vim will wait for a timeout or additional keypress before executing your <Leader>h mapping, since it wants to check whether you meant to press one of the longer mappings...
The easiest way to fix this is set alternate mappings for the vim-gitgutter commands. If you set up different mappings for those in your vimrc, vim-gitgutter itself will not create its mappings which are causing the interference.
The vim-gitgutter README suggests using g as an alternative prefix for these:
To set your own mappings for these, for example if you prefer g-based maps:
nmap ghs <Plug>(GitGutterStageHunk)
nmap ghu <Plug>(GitGutterUndoHunk)
So just go ahead and create mappings for the four keybindings that are breaking your <Leader>h. Add these four lines to your vimrc:
nmap ghs <Plug>(GitGutterStageHunk)
xmap ghs <Plug>(GitGutterStageHunk)
nmap ghu <Plug>(GitGutterUndoHunk)
nmap ghp <Plug>(GitGutterPreviewHunk)
The xmap (for staging in Visual mode) is technically not required, you could keep using <Leader>hs there without interference... But on the other hand you might want to keep those consistent between Normal and Visual mode, so I'd recommend remapping that one too.
The reason why <noway> doesn't work to fix this is that <nowait> only works on <buffer>-local mappings, when they shadow global mappings. It doesn't work when all your mappings are global. (In that case, Vim prefers to force you to resolve the conflicts, rather than make then longest mappings always unaccessible.)

"line too long (83 > 79 characters) [E501]" message on gvim

So I use Gvim on Window, so i found an .vimrc file and copied on to my
here is the vimrc file
" plugins
let need_to_install_plugins = 0
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
let need_to_install_plugins = 1
endif
call plug#begin()
Plug 'tpope/vim-sensible'
Plug 'itchyny/lightline.vim'
Plug 'joshdick/onedark.vim'
Plug 'ap/vim-buftabline'
Plug 'airblade/vim-gitgutter'
Plug 'vim-scripts/The-NERD-tree'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'scrooloose/syntastic'
Plug 'majutsushi/tagbar'
Plug 'vim-scripts/indentpython.vim'
Plug 'lepture/vim-jinja'
Plug 'pangloss/vim-javascript'
call plug#end()
filetype plugin indent on
syntax on
set rnu
if need_to_install_plugins == 1
echo "Installing plugins..."
silent! PlugInstall
echo "Done!"
q
endif
" always show the status bar
set laststatus=2
" enable 256 colors
set t_Co=256
set t_ut=
" turn on line numbering
set number
" sane text files
set fileformat=unix
set encoding=utf-8
set fileencoding=utf-8
" sane editing
set tabstop=4
set shiftwidth=4
set softtabstop=4
set colorcolumn=80
set expandtab
set viminfo='25,\"50,n~/.viminfo
" word movement
imap <S-Left> <Esc>bi
nmap <S-Left> b
imap <S-Right> <Esc><Right>wi
nmap <S-Right> w
" indent/unindent with tab/shift-tab
nmap <Tab> >>
imap <S-Tab> <Esc><<i
nmap <S-tab> <<
" mouse
set mouse=a
let g:is_mouse_enabled = 1
noremap <silent> <Leader>m :call ToggleMouse()<CR>
function ToggleMouse()
if g:is_mouse_enabled == 1
echo "Mouse OFF"
set mouse=
let g:is_mouse_enabled = 0
else
echo "Mouse ON"
set mouse=a
let g:is_mouse_enabled = 1
endif
endfunction
" color scheme
syntax on
colorscheme onedark
filetype on
filetype plugin indent on
" lightline
set noshowmode
let g:lightline = { 'colorscheme': 'onedark' }
" code folding
set foldmethod=indent
set foldlevel=99
" wrap toggle
setlocal nowrap
noremap <silent> <Leader>w :call ToggleWrap()<CR>
function ToggleWrap()
if &wrap
echo "Wrap OFF"
setlocal nowrap
set virtualedit=all
silent! nunmap <buffer> <Up>
silent! nunmap <buffer> <Down>
silent! nunmap <buffer> <Home>
silent! nunmap <buffer> <End>
silent! iunmap <buffer> <Up>
silent! iunmap <buffer> <Down>
silent! iunmap <buffer> <Home>
silent! iunmap <buffer> <End>
else
echo "Wrap ON"
setlocal wrap linebreak nolist
set virtualedit=
setlocal display+=lastline
noremap <buffer> <silent> <Up> gk
noremap <buffer> <silent> <Down> gj
noremap <buffer> <silent> <Home> g<Home>
noremap <buffer> <silent> <End> g<End>
inoremap <buffer> <silent> <Up> <C-o>gk
inoremap <buffer> <silent> <Down> <C-o>gj
inoremap <buffer> <silent> <Home> <C-o>g<Home>
inoremap <buffer> <silent> <End> <C-o>g<End>
endif
endfunction
" move through split windows
nmap <leader><Up> :wincmd k<CR>
nmap <leader><Down> :wincmd j<CR>
nmap <leader><Left> :wincmd h<CR>
nmap <leader><Right> :wincmd l<CR>
" move through buffers
nmap <leader>[ :bp!<CR>
nmap <leader>] :bn!<CR>
nmap <leader>x :bd<CR>
" restore place in file from previous session
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" file browser
let NERDTreeIgnore = ['\.pyc$', '__pycache__']
let NERDTreeMinimalUI = 1
let g:nerdtree_open = 0
map <leader>n :call NERDTreeToggle()<CR>
function NERDTreeToggle()
NERDTreeTabsToggle
if g:nerdtree_open == 1
let g:nerdtree_open = 0
else
let g:nerdtree_open = 1
wincmd p
endif
endfunction
" syntastic
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
map <leader>s :SyntasticCheck<CR>
map <leader>d :SyntasticReset<CR>
map <leader>e :lnext<CR>
map <leader>r :lprev<CR>
" tag list
map <leader>t :TagbarToggle<CR>
" copy, cut and paste
vmap <C-c> "+y
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa
" disable autoindent when pasting text
" source: https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
but anyways here are the problem whenever I enter a list or a string that is too long this message pop up.
line too long (83 > 79 characters) [E501]
so i tried to find a solution on the internet but non of it works, so if anyone knows the solution plz help thanks in advance.:)
You might be using a plug-in like Ale to check your files, if that is the case, this might be of help

why it raise error `E523: Not allow here` in the simple function?

why it raise error E523: Not allow here in the simple function?
function! CheckMode()
echom mode()
exec "normal \<Esc>"
" normal ^[
" call feedkeys('\<esc>')
endfunction
inoremap <expr> <Esc> CheckMode()
In fact, what I want to do is:
memory the "insert mode" and auto start insert after come back. For example:
function! LeaveBuffer(key)
let b:is_insert_mode = mode() == 'i'
if b:is_insert_mode
exec "normal! \<C-\\>\<C-n>"
endif
exec "normal! \<C-w>".a:key
endfunction
noremap <expr> <C-w>h LeaveBuffer("h")
noremap <expr> <C-w>j LeaveBuffer("j")
noremap <expr> <C-w>k LeaveBuffer("k")
noremap <expr> <C-w>l LeaveBuffer("l")
function! EnterBuffer()
if b:is_insert_mode
startinsert
endif
endfunction
autocmd BufEnter,TermOpen term://** call EnterBuffer()

Vim - onoremap from learnvimscriptthehardway doesnt work in my case

As i have read the book. I have encounter the onoremap comman, especially this one:
:onoremap in( :<c-u>normal! f(vi(<cr>. But when i pressed din<shift>9, where <shift>9 is parenthesis, to delete content of next argument in parenthesis, nothing happened - just cursor moved up one line. Same here : :onoremap il( :<c-u>normal! F)vi(<cr> where cursos Find backwards the parethesis, but did nothing more.
It is weird, and even more strange because it worked few days ago (nothing has changed). What can be the problem?
I have even used vim -u NONE <somefile>, without loading .vimrc, random file with parethesis inside, and map it once again :onoremap in( :<c-u>normal! f(vi(<cr>, but even then didnt work. I reallt dont get it.
verb omap in( :
o in( * :<C-U>normal! f(vi(<CR>
Last set from ~/.vimrc
ADDITIONAL INFO:
1) .VIMRC:
enter code
:set nocompatible
:set helpheight=9999
:set matchtime=1
:set tabstop=3
:set autoindent
:set smartindent
:set shiftwidth=3
:set laststatus=2
:set fillchars=""
:set timeoutlen=300
"}}}
"statusline{{{
:set statusline=%f
:set statusline+=%=
:set statusline+=%l
:set statusline+=/
:set statusline+=%L
"}}}
"colorscheme{{{
:colorscheme elflord
:hi Folded guibg=NONE ctermbg=NONE guifg=Yellow
"}}}
"leader and localleader{{{
:let mapleader = ","
:let maplocalleader = ";"
"}}}
"edit and source $MYVIMRC{{{
:nnoremap <leader>e :vsplit $MYVIMRC<cr>
:nnoremap <leader>ee :tabedit $MYVIMRC<cr>
:nnoremap <leader>s :source $MYVIMRC<CR>
"}}}
"movements with arrows{{{
:nnoremap - <c-d>
:vnoremap <left> <Nop>
:vnoremap <right> <Nop>
:vnoremap <up> <Nop>
"}}}
"vnoremap <VISUAL>{{{
:vnoremap <leader>" <esc>`>a"<esc>`<i"<esc>lel
:vnoremap jk <esc>
:vnoremap Y "+y
"}}}
"inoremap <INSERT>{{{
:inoremap /<cr> <esc>A<cr>//
:inoremap <leader><cr> <esc>$a<cr>
:inoremap <c-d> <esc>ddi
:inoremap uu <esc>viwUea
:inoremap <leader>x <esc>:wq<cr>
:inoremap <c-h> <esc>hhviwxi
:inoremap <leader>m <esc>
:inoremap <leader>d <esc>dd
:inoremap <leader>ee <esc>:tabedit $MYVIMRC<cr>
:inoremap <leader>c <esc>:
:inoremap cls <esc>G$vggx
:cnoremap <C-DEL> <s-right><c-w>
"}}}
"nnoremap <NORMAL>{{{
:nnoremap <F2> :set wrap!<cr>
:nnoremap tn :tabnew<cr>
:nnoremap bd :bd!<cr>
:nnoremap <left> :w<cr>:bnext<cr>
:nnoremap <right> :w<cr>:bprevious<cr>
:nnoremap <leader><down> :<down>
:nnoremap <leader><up> :<up>
:nnoremap bn :w<cr>:new new<cr><c-w>j<c-w>c
:nnoremap <F1> :Explore<cr>
:nnoremap <leader>m q
:nnoremap <F10> :set nornu!<cr>:set nonu!<cr>
:nnoremap <leader>x :wq<cr>
:nnoremap P "+p
:nnoremap <leader>] <c-w>l
:nnoremap <leader>[ <c-w>h
:nnoremap <leader>r :reg<cr>
:nnoremap <leader>} :tabp<cr>
:nnoremap <leader>{ :tabn<cr>
:nnoremap <BS> i<BS>
:nnoremap <cr> $a<cr><esc>
:nnoremap <tab> i<tab><esc>
:nnoremap cls G$vggx
:nnoremap H 0
:nnoremap L $
:nnoremap q :q!<cr>
:nnoremap r <c-r>
:nnoremap <localleader>s :w<cr>:source %<cr>
:nnoremap <leader>; :exe "normal! mqA;\e`q"<cr>
:nnoremap <F12> :set incsearch!<cr>:set hls!<cr>
:nnoremap <leader>sp :match Error /\s\+/<cr>
:nnoremap <leader>no :match none<cr>
:nnoremap / /\v
:nnoremap gj :cnext!<cr>
:nnoremap gk :cprevious!<cr>
:nnoremap <c-a> Gvgg
"}}}
"cnoremap <COMMAND> {{{
cnoremap <c-h> <c-w>
cnoremap <a-h> <C-E><C-U>
cnoremap <C-DEL> <s-right><c-w>
"}}}
"onoremap <PENDING>{{{
:onoremap il( :<C-u>normal! F)vi(<cr>
:onoremap in( :<C-u>normal! f(vi(<cr>
:onoremap in{ :<C-u>normal! f{vi{<cr>
:onoremap in[ :<C-u>normal! f[vi[<cr>
:onoremap in" :<C-u>normal! f"vi"<cr>
:onoremap in' :<C-u>normal! f'vi'<cr>
:onoremap in< :<C-u>normal! f<vi<<cr>
:onoremap in` :<C-u>normal! f`vi`<cr>
:onoremap il{ :<C-u>normal! F}vi{<cr>
:onoremap il[ :<C-u>normal! F]vi[<cr>
:onoremap il" :<C-u>normal! F"vi"<cr>
:onoremap il' :<C-u>normal! F']i'<cr>
:onoremap il< :<C-u>normal! F>vi<<cr>
:onoremap il` :<C-u>normal! F`vi`<cr>
"}}}
"autocmd filetype_vim{{{
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker
augroup END
" }}}
"autocmd filetype_c{{{
augroup filetype_c
autocmd!
autocmd FileType c inoremap <buffer> <localleader>c /**/<esc>hi
autocmd FileType c iabbrev <buffer> main #include <stdio.h><cr>#include <stdlib.h><cr><cr>int main (void) {<cr><cr><cr>return 0;<cr>}<cr><esc>4ki<Tab>
autocmd FileType c nnoremap <F5> :w<cr>:!clear;gcc -lm -std=c99 -Wall -Wextra -pedantic -g % <cr>:!./a.out<cr>
autocmd FileType c nnoremap <F6> :w<cr>:!clear;gcc -pthread %<cr>:!./a.out<cr>
autocmd FileType c iabbrev <buffer><silent> pr printf("\n");<esc>2F"a<C-R>=Eatchar('\s')<cr>
autocmd FileType c inoremap <leader>a <esc>f"a,
autocmd FileType c iabbrev <buffer><silent> sc scanf(" %");<esc>F"i<C-R>=Eatchar('\s')<cr>
autocmd FileType c inoremap <leader>u <esc>kkkO<CR>
autocmd FileType c iabbrev for for(int i =0; i< ; i++)<esc>F<a<C-R>=Eatchar('\s')<cr>
autocmd FileType c iabbrev forj for (int j =0; j< ; j++)<esc>F<a<C-R>=Eatchar('\s')<cr>
augroup END
"}}}
"autocmd filetype_asm{{{
augroup filetype_asm
autocmd!
autocmd FileType asm nnoremap <F5> :w<cr>:!clear;as --32 % -o 1.o;ld -m elf_i386 1.o -o 1<cr>:!./1<cr>
autocmd FileType asm inoremap 3<cr> <cr>#<esc>a
augroup END
"}}}
"autocmd filetype_html{{{
augroup filetype_html
autocmd!
autocmd FileType html nnoremap <buffer> <localleader>f Vatzf
augroup END
"}}}
"autocmd filetype_sh{{{
augroup filetype_sh
autocmd!
autocmd Filetype sh nnoremap <buffer> <F5> :w<cr>:!./%<cr>
augroup END
"}}}
"autocmd filetype_perl{{{
augroup filetype_perl
autocmd!
autocmd Filetype perl inoremap <leader>3 #!/usr/bin/perl<cr>
autocmd Filetype perl nnoremap <leader>3 i#!/usr/bin/perl<cr>
autocmd Filetype perl nnoremap <F5> :w<cr>:!clear;chmod +x %;./%<cr>
autocmd FileType perl inoremap <F5> <esc>:w<cr>:!clear;chmod +x %;./%<cr>
autocmd Filetype perl iabbrev pr print "\n";<esc>2F"a
autocmd Filetype perl inoremap <leader>l <esc>f;s
autocmd Filetype perl inoremap <localleader>s <esc>maggouse strict;<esc>`aa
augroup END
"}}}

How to enable mapping only if there is no quickfix window opened in Vim?

I would like do disable following mapping when I open quickfix window.
map <F5> :ZoomWin<cr>
Did you mean quickfix? If so, there are three ways:
Use <expr> mappings:
nnoremap <expr> <F5> (&buftype is# "quickfix" ? "" : ":\<C-u>ZoomWin\n")
Use BufEnter event to set/restore mapping:
augroup F5Map
autocmd! BufEnter * :if &buftype is# 'quickfix' | nunmap <F5> | else | nnoremap <F5> :<C-u>ZoomWin<CR> | endif
augroup END
Create mapping locally only for buffers where it is needed:
augroup F5Map
autocmd! BufEnter * :if &buftype isnot# 'quickfix' && empty(maparg('<F5>')) | nnoremap <buffer> <F5> :<C-u>ZoomWin<CR> | endif
augroup END
Update: to disable mapping when any of the opened windows contains quickfix buffer use the following:
nnoremap <expr> <F5> (&buftype is# "quickfix" || empty(filter(tabpagebuflist(), 'getbufvar(v:val, "&buftype") is# "quickfix"')) ? ":\<C-u>ZoomWin\n" : "")

Resources