From: Silvio Rhatto Date: Sun, 28 Jul 2024 13:01:50 +0000 (-0300) Subject: Fix: split logic into separate plugins X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=bf08c80af54044e8a4fc4a120f12434d2bd799f2;p=rhatto%2Fdotfiles%2Fvim.git Fix: split logic into separate plugins --- diff --git a/vim.dot.link/filetype.vim b/vim.dot.link/filetype.vim index 6401d41..fb73703 100644 --- a/vim.dot.link/filetype.vim +++ b/vim.dot.link/filetype.vim @@ -33,7 +33,8 @@ augroup END " Puppet augroup puppet - autocmd BufRead,BufNewFile *.pp setfiletype puppet + autocmd! + autocmd BufRead,BufNewFile *.pp setfiletype puppet augroup END " Drupal *.module and *.install files. diff --git a/vim.dot.link/plugin/key_mappings.vim b/vim.dot.link/plugin/key_mappings.vim new file mode 100644 index 0000000..0c1fe95 --- /dev/null +++ b/vim.dot.link/plugin/key_mappings.vim @@ -0,0 +1,193 @@ +" key_mappings.vim - Custom Key Mappings +" +" Author: Silvio Rhatto +" +" References: +" +" * https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim +" * https://stackoverflow.com/questions/45244245/why-alt-and-esc-keys-behave-differently-in-emacs +" * http://vim.wikia.com/wiki/Mapping_fast_keycodes_in_terminal_Vim +" * https://github.com/vim-utils/vim-alt-mappings +" * https://github.com/drmikehenry/vim-fixkey +" +" Notes: +" +" Keys were chosen not to conflict of to be close to window manager combos +" Like Awesome has a combo (Meta-q) which could be confused with a VIM quit +" mapping (Alt-q). +" +" Other keys were chosen not to conflict with existing VIM functionality +" like Alt-t (OpenNerdTree). +" +" While we could try to map other meta keys like Menu or AltGr, this +" is currently not supported by VIM and could even cause more confusion with +" other applications. +" +" For the quit combo, an approach like listening to VimLeave would work if +" this event would be triggered by the window manager when killing VIM window, +" but this does not seem to be the case. Anyway there's interesting discussion at +" https://stackoverflow.com/questions/5142099/how-to-auto-save-vim-session-on-quit-and-auto-reload-on-start-including-split-wi +" +" Pressing Alt- simultaneously is equivalent to pressing ESC and then , +" so the big difference between the ESC combos and Alt combos are mainly of +" config file notation. +" +" Typing ESC keys combos have the advantage over Alt combos as they are +" difficult to be mistaken for the Meta key, but thats mainly a user and not +" config convention since they're almost the same in VIM. +" +" In the other hand, there's an disadvantage of using ESC simultaneously for +" going to normal mode and doing other stuff, with can be in ambiguous. +" +" The sollution is to decrease ESC timeout. +" +" See https://www.johnhawthorn.com/2012/09/vi-escape-delays/ +"set timeoutlen=1000 ttimeoutlen=0 +set timeoutlen=0 ttimeoutlen=0 + +" Write, quit and close shortcuts using Esc notation (works also with ) +nnoremap n :tabnew +nnoremap t :NERDTree +nnoremap T :T +"nnoremap q :wqa +"noremap c :wqa +nnoremap f :wq +nnoremap c :tabclose +"noremap e :tabclose +nnoremap b :NERDTreeFromBookmark +nnoremap B :B +nnoremap s :OpenSession +"nnoremap m :q! +" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers +nnoremap m :bd +nnoremap w :w +nnoremap u :!up +inoremap n :tabnew +inoremap t :NERDTree +inoremap t :T +"inoremap q :wqa +"noremap c :wqa +inoremap f :wq +inoremap c :tabclose +"noremap e :tabclose +"inoremap m :q! +" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers +inoremap m :bd +inoremap w :w + +" Write, quit and close shortcuts using Alt-key combo notation +"noremap n :tabnew +"noremap t :OpenNERDTree +"noremap q :wqa +"noremap c :wqa +"noremap f :wq +"noremap c :tabclose +"noremap e :tabclose +"nnoremap b :NERDTreeFromBookmark +"nnoremap B :B +"nnoremap s :OpenSession +"noremap m :q! +"noremap w :w +"noremap u :!up +"inoremap n :tabnew +"inoremap t :OpenNERDTree +"inoremap q :wqa +"inoremap c :wqa +"inoremap f :wq +"inoremap c :tabclose +"inoremap e :tabclose +"inoremap m :q! +"inoremap w :w + +" Write, quit and close shortcuts using Ctrl-key combos +" We're using these due to a conflict with wyrd(1) +"nnoremap :tabnew +"nnoremap :OpenNERDTree +"nnoremap :wqa +"nnoremap :wqa +"nnoremap :wq +"nnoremap :tabclose +"nnoremap :tabclose +"nnoremap :NERDTreeFromBookmark +"nnoremap :B +"nnoremap :OpenSession +"nnoremap :q! +"nnoremap :w +"inoremap :tabnew +"inoremap :OpenNERDTree +"inoremap :wqa +"inoremap :wqa +"inoremap :wq +"inoremap :tabclose +"inoremap :tabclose +"inoremap :q! +"inoremap :w + +" Write, quit and close shortcuts +noremap q :Wipeout:wqa +"noremap f :wq +"noremap t :tabclose +"noremap m :q! +"noremap w :w +noremap h :tabnew + +" Tab navigation +" See http://vim.wikia.com/wiki/Alternative_tab_navigation +" http://comments.gmane.org/gmane.os.cygwin.xfree/16419 +nnoremap [5^ +nnoremap [6^ +nnoremap :tabn +nnoremap :tabp +nnoremap 1 1gt +nnoremap 2 2gt +nnoremap 3 3gt +nnoremap 4 4gt +nnoremap 5 5gt +nnoremap 6 6gt +nnoremap 7 7gt +nnoremap 8 8gt +nnoremap 9 9gt +nnoremap 0 10gt + +" Buffer navigation: Alt-{Up,Down} +noremap Od :bprevious +noremap Oc :bnext + +" Window navigation +"noremap +"noremap +"noremap +"noremap +"inoremap +"inoremap +"inoremap +"inoremap +"noremap  +"noremap  +"noremap  +"noremap  +"inoremap  +"inoremap  +"inoremap  +"inoremap  +nnoremap +nnoremap +nnoremap +nnoremap +inoremap +inoremap +inoremap +inoremap + +" Recording +nnoremap Q q + +" See http://superuser.com/questions/10588/how-to-make-cut-copy-paste-in-gvim-on-ubuntu-work-with-ctrlx-ctrlc-ctrlv +"imap + +"vmap c"+p +vnoremap "+yi +vnoremap "+c + +" For email: unfold and delete to your signature +" See https://hroy.eu/tips/vim/email-delete-til-signature/ +noremap ,dd zi:.;/^-- $/dO-- zi diff --git a/vim.dot.link/plugin/nerdtree_customizations.vim b/vim.dot.link/plugin/nerdtree_customizations.vim new file mode 100644 index 0000000..f2e42ec --- /dev/null +++ b/vim.dot.link/plugin/nerdtree_customizations.vim @@ -0,0 +1,43 @@ +" nedtree_customizations.vim - NERDTree customizations +" +" Initially adapted from +" http://stackoverflow.com/questions/1447334/how-do-you-add-nerdtree-to-your-vimrc +" +" Author: Silvio Rhatto + +let NERDTreeMinimalUI=1 + +augroup nerdtree + autocmd! + + " Open NERDTree when vim starts + "autocmd VimEnter * NERDTree + "autocmd VimEnter * wincmd p + + autocmd FileType nerdtree set relativenumber + autocmd FileType taglist set relativenumber +augroup END + +function TabNew(address) + execute ":tabnew" + execute ":NERDTree " a:address +endfunction + +function TabNewBookmark(bookmark) + execute ":tabnew" + execute ":NERDTreeFromBookmark " a:bookmark +endfunction + +function OpenNERDTree() + execute ":NERDTree" +endfunction + +" Shortcuts +cnoreabbrev t NERDTree +cnoreabbrev b NERDTreeFromBookmark +cnoreabbrev s OpenSession +cnoreabbrev sload OpenSession +cnoreabbrev ssave SaveSession +command -nargs=1 -complete=dir T :call TabNew() +command -nargs=1 -complete=customlist,nerdtree#completeBookmarks B :call TabNewBookmark() +command -nargs=0 OpenNERDTree :call OpenNERDTree() diff --git a/vim.dot.link/plugin/window_title.vim b/vim.dot.link/plugin/window_title.vim new file mode 100644 index 0000000..bb82977 --- /dev/null +++ b/vim.dot.link/plugin/window_title.vim @@ -0,0 +1,27 @@ +" window_title.vim - Window title handling +" +" Author: Silvio Rhatto + +" Basic settings +set title +set titleold="terminal" +set titlestring=vim:\ %F + +" Handling titles when vim is embedded in specific programs +augroup vimleave + autocmd! + au VimLeave *mutt/* silent call ResetTitle("mutt") + au VimLeave *remind/* silent call ResetTitle("calendar") +augroup END + +" Reset window titles +" +" Thanks to http://stackoverflow.com/questions/1673649/vimrc-action-onclose +function! ResetTitle(title) + " disable vim's ability to set the title + exec "set title t_ts='' t_fs=''" + + " and restore it + "exec ":!echo -e '\033kbash\033\\'\" + exec ":!xtitle -q " a:title +endfunction diff --git a/vimrc.dot.link b/vimrc.dot.link index 9c19dfd..5c5a1fd 100644 --- a/vimrc.dot.link +++ b/vimrc.dot.link @@ -19,49 +19,13 @@ set laststatus=2 set shortmess+=I set ignorecase set smartcase -filetype indent off let mapleader="-" -" Window title handling -set title -set titleold="terminal" -set titlestring=vim:\ %F - -" See http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file -"set autochdir -augroup changedir - autocmd! - autocmd BufEnter * silent! lcd %:p:h -augroup END - -" Thanks to http://stackoverflow.com/questions/1673649/vimrc-action-onclose -function! ResetTitle(title) - " disable vim's ability to set the title - exec "set title t_ts='' t_fs=''" - - " and restore it - "exec ":!echo -e '\033kbash\033\\'\" - exec ":!xtitle -q " a:title -endfunction - -" Avoid autocmd spam by using augroups and reseting autocmd -" https://stackoverflow.com/questions/19030290/syntax-highlighting-causes-terrible-lag-in-vim -augroup vimleave - autocmd! - au VimLeave *mutt/* silent call ResetTitle("mutt") - au VimLeave *remind/* silent call ResetTitle("calendar") -augroup END - -" Command mode completion -" See https://stackoverflow.com/questions/526858/how-do-i-make-vim-do-normal-bash-like-tab-completion-for-file-names -"set wildmode=longest,list -set wildmode=longest,list,full -set wildmenu - " Syntax highlight syntax on " Indenting +filetype indent off filetype plugin indent on " Folding @@ -78,6 +42,19 @@ filetype plugin indent on "let vimsyn_folding='af' "let xml_syntax_folding=1 +" See http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file +"set autochdir +augroup changedir + autocmd! + autocmd BufEnter * silent! lcd %:p:h +augroup END + +" Command mode completion +" See https://stackoverflow.com/questions/526858/how-do-i-make-vim-do-normal-bash-like-tab-completion-for-file-names +"set wildmode=longest,list +set wildmode=longest,list,full +set wildmenu + " PHP let php_sql_query=1 @@ -93,235 +70,6 @@ let g:syntastic_mode_map={ 'mode': 'passive', \ 'active_filetypes': [], \ 'passive_filetypes': [] } -" -" Key Mappings -" https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim -" https://stackoverflow.com/questions/45244245/why-alt-and-esc-keys-behave-differently-in-emacs -" http://vim.wikia.com/wiki/Mapping_fast_keycodes_in_terminal_Vim -" https://github.com/vim-utils/vim-alt-mappings -" https://github.com/drmikehenry/vim-fixkey -" -" Notes: -" -" Keys were chosen not to conflict of to be close to window manager combos -" Like Awesome has a combo (Meta-q) which could be confused with a VIM quit -" mapping (Alt-q). -" -" Other keys were chosen not to conflict with existing VIM functionality -" like Alt-t (OpenNerdTree). -" -" While we could try to map other meta keys like Menu or AltGr, this -" is currently not supported by VIM and could even cause more confusion with -" other applications. -" -" For the quit combo, an approach like listening to VimLeave would work if -" this event would be triggered by the window manager when killing VIM window, -" but this does not seem to be the case. Anyway there's interesting discussion at -" https://stackoverflow.com/questions/5142099/how-to-auto-save-vim-session-on-quit-and-auto-reload-on-start-including-split-wi -" -" Pressing Alt- simultaneously is equivalent to pressing ESC and then , -" so the big difference between the ESC combos and Alt combos are mainly of -" config file notation. -" -" Typing ESC keys combos have the advantage over Alt combos as they are -" difficult to be mistaken for the Meta key, but thats mainly a user and not -" config convention since they're almost the same in VIM. -" -" In the other hand, there's an disadvantage of using ESC simultaneously for -" going to normal mode and doing other stuff, with can be in ambiguous. -" -" The sollution is to decrease ESC timeout. -" -" See https://www.johnhawthorn.com/2012/09/vi-escape-delays/ -"set timeoutlen=1000 ttimeoutlen=0 -set timeoutlen=0 ttimeoutlen=0 - -" Write, quit and close shortcuts using Esc notation (works also with ) -nnoremap n :tabnew -nnoremap t :NERDTree -nnoremap T :T -"nnoremap q :wqa -"noremap c :wqa -nnoremap f :wq -nnoremap c :tabclose -"noremap e :tabclose -nnoremap b :NERDTreeFromBookmark -nnoremap B :B -nnoremap s :OpenSession -"nnoremap m :q! -" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers -nnoremap m :bd -nnoremap w :w -nnoremap u :!up -inoremap n :tabnew -inoremap t :NERDTree -inoremap t :T -"inoremap q :wqa -"noremap c :wqa -inoremap f :wq -inoremap c :tabclose -"noremap e :tabclose -"inoremap m :q! -" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers -inoremap m :bd -inoremap w :w - -" Write, quit and close shortcuts using Alt-key combo notation -"noremap n :tabnew -"noremap t :OpenNERDTree -"noremap q :wqa -"noremap c :wqa -"noremap f :wq -"noremap c :tabclose -"noremap e :tabclose -"nnoremap b :NERDTreeFromBookmark -"nnoremap B :B -"nnoremap s :OpenSession -"noremap m :q! -"noremap w :w -"noremap u :!up -"inoremap n :tabnew -"inoremap t :OpenNERDTree -"inoremap q :wqa -"inoremap c :wqa -"inoremap f :wq -"inoremap c :tabclose -"inoremap e :tabclose -"inoremap m :q! -"inoremap w :w - -" Write, quit and close shortcuts using Ctrl-key combos -" We're using these due to a conflict with wyrd(1) -"nnoremap :tabnew -"nnoremap :OpenNERDTree -"nnoremap :wqa -"nnoremap :wqa -"nnoremap :wq -"nnoremap :tabclose -"nnoremap :tabclose -"nnoremap :NERDTreeFromBookmark -"nnoremap :B -"nnoremap :OpenSession -"nnoremap :q! -"nnoremap :w -"inoremap :tabnew -"inoremap :OpenNERDTree -"inoremap :wqa -"inoremap :wqa -"inoremap :wq -"inoremap :tabclose -"inoremap :tabclose -"inoremap :q! -"inoremap :w - -" Write, quit and close shortcuts -noremap q :Wipeout:wqa -"noremap f :wq -"noremap t :tabclose -"noremap m :q! -"noremap w :w -noremap h :tabnew - -" Tab navigation -" See http://vim.wikia.com/wiki/Alternative_tab_navigation -" http://comments.gmane.org/gmane.os.cygwin.xfree/16419 -nnoremap [5^ -nnoremap [6^ -nnoremap :tabn -nnoremap :tabp -nnoremap 1 1gt -nnoremap 2 2gt -nnoremap 3 3gt -nnoremap 4 4gt -nnoremap 5 5gt -nnoremap 6 6gt -nnoremap 7 7gt -nnoremap 8 8gt -nnoremap 9 9gt -nnoremap 0 10gt - -" Buffer navigation: Alt-{Up,Down} -noremap Od :bprevious -noremap Oc :bnext - -" Window navigation -"noremap -"noremap -"noremap -"noremap -"inoremap -"inoremap -"inoremap -"inoremap -"noremap  -"noremap  -"noremap  -"noremap  -"inoremap  -"inoremap  -"inoremap  -"inoremap  -nnoremap -nnoremap -nnoremap -nnoremap -inoremap -inoremap -inoremap -inoremap - -" Recording -nnoremap Q q - -" NERDTree section -" Thanks to http://stackoverflow.com/questions/1447334/how-do-you-add-nerdtree-to-your-vimrc - -let NERDTreeMinimalUI=1 - -augroup nerdtree - autocmd! - " Open NERDTree when vim starts - "autocmd VimEnter * NERDTree - "autocmd VimEnter * wincmd p - - autocmd FileType nerdtree set relativenumber - autocmd FileType taglist set relativenumber -augroup END - -function TabNew(address) - execute ":tabnew" - execute ":NERDTree " a:address -endfunction - -function TabNewBookmark(bookmark) - execute ":tabnew" - execute ":NERDTreeFromBookmark " a:bookmark -endfunction - -function OpenNERDTree() - execute ":NERDTree" -endfunction - -" Shortcuts -cnoreabbrev t NERDTree -cnoreabbrev b NERDTreeFromBookmark -cnoreabbrev s OpenSession -cnoreabbrev sload OpenSession -cnoreabbrev ssave SaveSession -command -nargs=1 -complete=dir T :call TabNew() -command -nargs=1 -complete=customlist,nerdtree#completeBookmarks B :call TabNewBookmark() -command -nargs=0 OpenNERDTree :call OpenNERDTree() - -" See http://superuser.com/questions/10588/how-to-make-cut-copy-paste-in-gvim-on-ubuntu-work-with-ctrlx-ctrlc-ctrlv -"imap + -"vmap c"+p -vnoremap "+yi -vnoremap "+c - -" For email: unfold and delete to your signature -" See https://hroy.eu/tips/vim/email-delete-til-signature/ -noremap ,dd zi:.;/^-- $/dO-- zi - " Color scheme "colorscheme github "colorscheme solarized @@ -351,9 +99,9 @@ endif "python powerline_setup() "python del powerline_setup -set laststatus=2 " Always display the statusline in all windows +set laststatus=2 " Always display the statusline in all windows set showtabline=2 " Always display the tabline, even if there is only one tab -set noshowmode " Hide the default mode text (e.g. -- INSERT -- below the statusline) +set noshowmode " Hide the default mode text (e.g. -- INSERT -- below the statusline) " See " http://vim.wikia.com/wiki/Have_Vim_check_automatically_if_the_file_has_changed_externally