diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-07-28 10:01:50 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-07-28 10:01:50 -0300 |
commit | bf08c80af54044e8a4fc4a120f12434d2bd799f2 (patch) | |
tree | a7ee48adbb88abe2ab6e955efefef6b433392b75 /vim.dot.link | |
parent | 23e4d875310c6520782d1605b8c3909053d58442 (diff) | |
download | vim-bf08c80af54044e8a4fc4a120f12434d2bd799f2.tar.gz vim-bf08c80af54044e8a4fc4a120f12434d2bd799f2.tar.bz2 |
Fix: split logic into separate plugins
Diffstat (limited to 'vim.dot.link')
-rw-r--r-- | vim.dot.link/filetype.vim | 3 | ||||
-rw-r--r-- | vim.dot.link/plugin/key_mappings.vim | 193 | ||||
-rw-r--r-- | vim.dot.link/plugin/nerdtree_customizations.vim | 43 | ||||
-rw-r--r-- | vim.dot.link/plugin/window_title.vim | 27 |
4 files changed, 265 insertions, 1 deletions
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 <rhatto@riseup.net> +" +" 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-<key> simultaneously is equivalent to pressing ESC and then <key>, +" 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 <key> notation (works also with <Alt-key>) +nnoremap <ESC>n :tabnew<CR> +nnoremap <ESC>t :NERDTree +nnoremap <ESC>T :T +"nnoremap <ESC>q :wqa<CR> +"noremap <ESC>c :wqa<CR> +nnoremap <ESC>f :wq<CR> +nnoremap <ESC>c :tabclose<CR> +"noremap <ESC>e :tabclose<CR> +nnoremap <ESC>b :NERDTreeFromBookmark +nnoremap <ESC>B :B +nnoremap <ESC>s :OpenSession +"nnoremap <ESC>m :q!<CR> +" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers +nnoremap <ESC>m :bd<CR> +nnoremap <ESC>w :w<CR> +nnoremap <ESC>u :!up<CR> +inoremap <ESC>n <ESC>:tabnew<CR> +inoremap <ESC>t <ESC>:NERDTree +inoremap <ESC>t <ESC>:T +"inoremap <ESC>q <ESC>:wqa<CR> +"noremap <ESC>c <ESC>:wqa<CR> +inoremap <ESC>f <ESC>:wq<CR> +inoremap <ESC>c <ESC>:tabclose<CR> +"noremap <ESC>e <ESC>:tabclose<CR> +"inoremap <ESC>m <ESC>:q!<CR> +" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers +inoremap <ESC>m <ESC>:bd<CR> +inoremap <ESC>w <ESC>:w<CR> + +" Write, quit and close shortcuts using Alt-key combo notation +"noremap n :tabnew<CR> +"noremap t :OpenNERDTree<CR> +"noremap q :wqa<CR> +"noremap c :wqa<CR> +"noremap f :wq<CR> +"noremap c :tabclose<CR> +"noremap e :tabclose<CR> +"nnoremap b :NERDTreeFromBookmark +"nnoremap B :B +"nnoremap s :OpenSession +"noremap m :q!<CR> +"noremap w :w<CR> +"noremap u :!up<CR> +"inoremap n <ESC>:tabnew<CR> +"inoremap t <ESC>:OpenNERDTree<CR> +"inoremap q <ESC>:wqa<CR> +"inoremap c <ESC>:wqa<CR> +"inoremap f <ESC>:wq<CR> +"inoremap c <ESC>:tabclose<CR> +"inoremap e <ESC>:tabclose<CR> +"inoremap m <ESC>:q!<CR> +"inoremap w <ESC>:w<CR> + +" Write, quit and close shortcuts using Ctrl-key combos +" We're using these due to a conflict with wyrd(1) +"nnoremap <C-n> :tabnew<CR> +"nnoremap <C-t> :OpenNERDTree<CR> +"nnoremap <C-q> :wqa<CR> +"nnoremap <C-c> :wqa<CR> +"nnoremap <C-f> :wq<CR> +"nnoremap <C-c> :tabclose<CR> +"nnoremap <C-e> :tabclose<CR> +"nnoremap <C-b> :NERDTreeFromBookmark +"nnoremap <C-B> :B +"nnoremap <C-s> :OpenSession +"nnoremap <C-m> :q!<CR> +"nnoremap <C-w> :w<CR> +"inoremap <C-n> <ESC>:tabnew<CR> +"inoremap <C-t> <ESC>:OpenNERDTree<CR> +"inoremap <C-q> <ESC>:wqa<CR> +"inoremap <C-c> <ESC>:wqa<CR> +"inoremap <C-f> <ESC>:wq<CR> +"inoremap <C-c> <ESC>:tabclose<CR> +"inoremap <C-e> <ESC>:tabclose<CR> +"inoremap <C-m> <ESC>:q!<CR> +"inoremap <C-w> <ESC>:w<CR> + +" Write, quit and close shortcuts +noremap q :Wipeout<CR>:wqa <CR> +"noremap f :wq <CR> +"noremap t :tabclose <CR> +"noremap m :q! <CR> +"noremap w :w <CR> +noremap h :tabnew<CR> + +" Tab navigation +" See http://vim.wikia.com/wiki/Alternative_tab_navigation +" http://comments.gmane.org/gmane.os.cygwin.xfree/16419 +nnoremap <ESC>[5^ <C-PageUp> +nnoremap <ESC>[6^ <C-PageDown> +nnoremap <C-PageDown> :tabn<CR> +nnoremap <C-PageUp> :tabp<CR> +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<CR> +noremap Oc :bnext<CR> + +" Window navigation +"noremap <C-Left> <C-w><Left> +"noremap <C-Right> <C-w><Right> +"noremap <C-Down> <C-w><Down> +"noremap <C-Up> <C-w><Up> +"inoremap <C-Left> <ESC><C-w><Left> +"inoremap <C-Right> <ESC><C-w><Right> +"inoremap <C-Down> <ESC><C-w><Down> +"inoremap <C-Up> <ESC><C-w><Up> +"noremap <Left> <C-w><Left> +"noremap <Right> <C-w><Right> +"noremap <Down> <C-w><Down> +"noremap <Up> <C-w><Up> +"inoremap <Left> <ESC><C-w><Left> +"inoremap <Right> <ESC><C-w><Right> +"inoremap <Down> <ESC><C-w><Down> +"inoremap <Up> <ESC><C-w><Up> +nnoremap <ESC><Left> <C-w><Left> +nnoremap <ESC><Right> <C-w><Right> +nnoremap <ESC><Down> <C-w><Down> +nnoremap <ESC><Up> <C-w><Up> +inoremap <ESC><Left> <ESC><C-w><Left> +inoremap <ESC><Right> <ESC><C-w><Right> +inoremap <ESC><Down> <ESC><C-w><Down> +inoremap <ESC><Up> <ESC><C-w><Up> + +" 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 <C-v> <C-r><C-o>+ +"vmap <C-v> c<ESC>"+p +vnoremap <C-c> "+yi +vnoremap <C-x> "+c + +" For email: unfold and delete to your signature +" See https://hroy.eu/tips/vim/email-delete-til-signature/ +noremap ,dd zi:.;/^-- $/d<CR>O-- <UP><End><CR><CR><UP><CR><C-O>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 <rhatto@riseup.net> + +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(<f-args>) +command -nargs=1 -complete=customlist,nerdtree#completeBookmarks B :call TabNewBookmark(<f-args>) +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 <rhatto@riseup.net> + +" 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\\'\<CR>" + exec ":!xtitle -q " a:title +endfunction |