From 3036a0300a292b7cff7735915982fe30a0cf1f0e Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 5 Dec 2019 14:25:46 +0530 Subject: [PATCH] nvim: init.vim: Group key bindings as per filetype --- nvim/init.vim | 96 ++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/nvim/init.vim b/nvim/init.vim index 6e505cf..e82a816 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -255,10 +255,6 @@ nnoremap ghu :GitGutterUndoHunk nnoremap ghr :GitGutterPreviewHunk nnoremap gqf :GitGutterQuickFix nnoremap ggf :GitGutterFold -" For Cscope & tags -nnoremap ct :NeomakeSh ctags -R . -nnoremap cu :NeomakeSh cscope -bqR -nnoremap cr :cs reset " For Neomake nnoremap nm :Neomake nnoremap nc :NeomakeClean @@ -269,16 +265,6 @@ nnoremap njc :NeomakeCancelJob " For workspace nnoremap sw :ToggleWorkspace -" Haskell specific -nnoremap ht :NeomakeSh stack exec -- fast-tags -R . -" For ghcid -nnoremap hg :Ghcid -nnoremap hk :GhcidKill -" For Hoogle -nnoremap hc :HoogleClose -nnoremap ho :exe ':Hoogle ' . expand('') -nnoremap hi :exe ':HoogleInfo ' . expand('') - " Quickfix & Location list mappings nnoremap fn :cnext nnoremap fp :cprevious @@ -309,42 +295,58 @@ noremap noremap noremap -nnoremap ss :call Cscope("s", expand('')) -nnoremap sg :call Cscope("g", expand('')) -nnoremap sd :call Cscope("d", expand('')) -nnoremap sc :call Cscope("c", expand('')) -nnoremap st :call Cscope("t", expand('')) -nnoremap se :call Cscope("e", expand('')) -nnoremap sf :call Cscope("f", expand('')) -nnoremap si :call Cscope("i", expand('')) -nnoremap sa :call Cscope("a", expand('')) - -nnoremap ss :call CscopeQuery("s") -nnoremap sg :call CscopeQuery("g") -nnoremap sd :call CscopeQuery("d") -nnoremap sc :call CscopeQuery("c") -nnoremap st :call CscopeQuery("t") -nnoremap se :call CscopeQuery("e") -nnoremap sf :call CscopeQuery("f") -nnoremap si :call CscopeQuery("i") -nnoremap sa :call CscopeQuery("a") - nnoremap :WhichKey '' " --------------------------- Autocmd groups --------------------------------- +augroup HaskellMaps + au! + au FileType haskell nmap ht :NeomakeSh stack exec -- fast-tags -R . + au FileType haskell nmap hg :Ghcid + au FileType haskell nmap hk :GhcidKill + au FileType haskell nmap hc :HoogleClose + au FileType haskell nmap ho :exe ':Hoogle ' . expand('') + au FileType haskell nmap hi :exe ':HoogleInfo ' . expand('') +augroup END + +augroup CMaps + au! + au FileType c nmap ct :NeomakeSh ctags -R . + au FileType c nmap cu :NeomakeSh cscope -bqR + au FileType c nmap cr :cs reset + + au FileType c nmap ss :call Cscope("s", expand('')) + au FileType c nmap sg :call Cscope("g", expand('')) + au FileType c nmap sd :call Cscope("d", expand('')) + au FileType c nmap sc :call Cscope("c", expand('')) + au FileType c nmap st :call Cscope("t", expand('')) + au FileType c nmap se :call Cscope("e", expand('')) + au FileType c nmap sf :call Cscope("f", expand('')) + au FileType c nmap si :call Cscope("i", expand('')) + au FileType c nmap sa :call Cscope("a", expand('')) + + au FileType c nmap ss :call CscopeQuery("s") + au FileType c nmap sg :call CscopeQuery("g") + au FileType c nmap sd :call CscopeQuery("d") + au FileType c nmap sc :call CscopeQuery("c") + au FileType c nmap st :call CscopeQuery("t") + au FileType c nmap se :call CscopeQuery("e") + au FileType c nmap sf :call CscopeQuery("f") + au FileType c nmap si :call CscopeQuery("i") + au FileType c nmap sa :call CscopeQuery("a") +augroup END + augroup deopleteMaps - au! - " For deoplete Rust - au FileType rust nmap rd DeopleteRustGoToDefinitionDefault - au FileType rust nmap rc DeopleteRustShowDocumentation - au FileType rust nmap rv DeopleteRustGoToDefinitionVSplit - au FileType rust nmap rh DeopleteRustGoToDefinitionSplit - au FileType rust nmap rt DeopleteRustGoToDefinitionTab + au! + au FileType rust nmap rd DeopleteRustGoToDefinitionDefault + au FileType rust nmap rc DeopleteRustShowDocumentation + au FileType rust nmap rv DeopleteRustGoToDefinitionVSplit + au FileType rust nmap rh DeopleteRustGoToDefinitionSplit + au FileType rust nmap rt DeopleteRustGoToDefinitionTab augroup END augroup rainbow_lisp - autocmd! - autocmd FileType lisp,clojure,scheme RainbowParentheses + autocmd! + autocmd FileType lisp,clojure,scheme RainbowParentheses augroup END " Starts the REPL. @@ -363,8 +365,8 @@ augroup END " Close QF window if it is last window augroup QFClose - au! - au WinEnter * if winnr('$') == 1 && &buftype == "quickfix"|q|endif + au! + au WinEnter * if winnr('$') == 1 && &buftype == "quickfix"|q|endif augroup END " Taken from http://seenaburns.com/vim-setup-for-rust/ @@ -378,8 +380,8 @@ au BufEnter *.rs let s:quitting = 0 au BufWritePost *.rs if ! s:quitting | Neomake | else | echom "Neomake disabled"| endif augroup Terminal - au! - au TermOpen * setlocal statusline=%{b:terminal_job_id} + au! + au TermOpen * setlocal statusline=%{b:terminal_job_id} augroup END " Default indentations