diff options
Diffstat (limited to 'vim.dot.link/plugin')
-rw-r--r-- | vim.dot.link/plugin/auto_file.vim | 28 | ||||
-rw-r--r-- | vim.dot.link/plugin/key_mappings.vim | 260 | ||||
-rw-r--r-- | vim.dot.link/plugin/lib.vim | 45 | ||||
-rw-r--r-- | vim.dot.link/plugin/nerdtree_customizations.vim | 54 | ||||
-rw-r--r-- | vim.dot.link/plugin/session_workarounds.vim | 102 | ||||
-rw-r--r-- | vim.dot.link/plugin/ui.vim | 47 | ||||
-rw-r--r-- | vim.dot.link/plugin/window_title.vim | 30 |
7 files changed, 566 insertions, 0 deletions
diff --git a/vim.dot.link/plugin/auto_file.vim b/vim.dot.link/plugin/auto_file.vim new file mode 100644 index 0000000..2d46efc --- /dev/null +++ b/vim.dot.link/plugin/auto_file.vim @@ -0,0 +1,28 @@ +" auto_file.vim - Automatically file reading, saving; directory change {{{ + +" Autoread {{{ +" +" http://vim.wikia.com/wiki/Have_Vim_check_automatically_if_the_file_has_changed_externally +" http://stackoverflow.com/questions/2490227/how-does-vims-autoread-work +" http://stackoverflow.com/questions/2490227/how-does-vims-autoread-work +"au FocusGained,BufEnter * :silent! ! +"au FocusLost,WinLeave * :silent! w +" }}} + +" Autosave {{{ +" See https://github.com/vim-scripts/vim-auto-save +"let g:auto_save = 1 +" }}} + +" Auto change dir {{{ +" +" Automatically set the current working directory to the current buffer file's +" directory +" +" 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 +" }}} diff --git a/vim.dot.link/plugin/key_mappings.vim b/vim.dot.link/plugin/key_mappings.vim new file mode 100644 index 0000000..5e9c315 --- /dev/null +++ b/vim.dot.link/plugin/key_mappings.vim @@ -0,0 +1,260 @@ +" 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. +" + +" Decrease ESC delays {{{ +" See https://www.johnhawthorn.com/2012/09/vi-escape-delays/ +"set timeoutlen=1000 ttimeoutlen=0 +set timeoutlen=0 ttimeoutlen=0 +" }}} + +" ESC-based shortcuts {{{ +" 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> +" }}} + +" Alt-based shortcuts {{{ +" 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> +" }}} + +" Crtl-based shortcuts {{{ +" 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 +" }}} + +" Copy and paste {{{ +" +" 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 +" }}} + +" 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 +" }}} + +" Task lists {{{ +" https://github.com/vitalk/vim-simple-todo/ +let g:simple_todo_map_keys = 0 +let g:simple_todo_list_symbol = '*' +nmap <Leader>i <Plug>(simple-todo-new-list-item) +nmap <Leader>I <Plug>(simple-todo-new-list-item-start-of-line) +nmap <Leader>o <Plug>(simple-todo-below) +nmap <Leader>x <Plug>(simple-todo-mark-as-done) +nmap <Leader>X <Plug>(simple-todo-mark-as-undone) +nmap <Leader>s <Plug>(simple-todo-mark-switch) +imap <Leader>i <Plug>(simple-todo-new-list-item) +imap <Leader>I <Plug>(simple-todo-new-list-item-start-of-line) +imap <Leader>o <Plug>(simple-todo-below) +imap <Leader>X <Plug>(simple-todo-mark-as-undone) +imap <Leader>x <Plug>(simple-todo-mark-as-done) +imap <Leader>s <Plug>(simple-todo-mark-switch) +vmap <Leader>I <Plug>(simple-todo-new-list-item-start-of-line) +vmap <Leader>X <Plug>(simple-todo-mark-as-undone) +vmap <Leader>x <Plug>(simple-todo-mark-as-done) +vmap <Leader>s <Plug>(simple-todo-mark-switch) + +" From lib.vim +"nnoremap <Leader>c :call ToggleCheckbox()<CR> +" }}} + +"" Leader behavior {{{ +" Cleanup the buffer {{{ +noremap <leader>c :call BufferCleansing()<CR> +" }}} + +" Insert the current date in ISO format {{{ +" +" Thanks https://vimtricks.com/p/insert-the-current-date-or-time/ +"map <leader>d :0put =strftime('%Y-%m-%d')<CR> +nnoremap <leader>d i<C-R>=strftime('%Y-%m-%d')<CR> +inoremap <leader>d <C-R>=strftime('%Y-%m-%d')<CR> +" }}} + +" Insert the current date in format useful for ChangeLog.md entries {{{ +"nnoremap <leader>e :put =strftime('## %Y-%m-%d ')<CR> +nnoremap <leader>e o<CR><C-R>=strftime('## %Y-%m-%d - ')<CR> + +" Remind shortcuts +inoremap <leader>s SATISFY [expire()] +" }}} +" }}} diff --git a/vim.dot.link/plugin/lib.vim b/vim.dot.link/plugin/lib.vim new file mode 100644 index 0000000..1c3212e --- /dev/null +++ b/vim.dot.link/plugin/lib.vim @@ -0,0 +1,45 @@ +" lib.vim - Miscelaneous functions {{{ +" +" Author: Silvio Rhatto <rhatto@riseup.net> +" + +" Checkbox handling {{{ +" +" This is commented out because vitalk/vim-simple-todo is being used instead. +" +" Thanks https://www.reddit.com/r/vim/comments/slqsao/readymade_solution_for_handling_markdown/ +"function! ToggleCheckbox() +" let line = getline('.') +" +" if line =~ '- \[ \]' +" call setline('.', substitute(line, '- \[ \]', '- \[x\]', '')) +" elseif line =~ '- \[x\]' +" call setline('.', substitute(line, '- \[x\]', '- \[ \]', '')) +" elseif line =~ '- ' +" call setline('.', substitute(line, '- ', '- \[ \] ', '')) +" endif +"endf +" }}} + +" Remove trailing spaces {{{ +" +" Thanks https://vi.stackexchange.com/a/456 +fun! TrimWhitespace() + let l:save = winsaveview() + keeppatterns %s/\s\+$//e + call winrestview(l:save) +endfun + +command! TrimWhitespace call TrimWhitespace() +" }}} + +" Cleanup the buffer {{{ +" +" Implement miscelaneous buffer cleansing procedures +function BufferCleansing() + " Trim white spaces + call TrimWhitespace() +endfunction + +command! BufferCleansing call BufferCleansing() +" }}} diff --git a/vim.dot.link/plugin/nerdtree_customizations.vim b/vim.dot.link/plugin/nerdtree_customizations.vim new file mode 100644 index 0000000..1cbb207 --- /dev/null +++ b/vim.dot.link/plugin/nerdtree_customizations.vim @@ -0,0 +1,54 @@ +" 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> + +" Use the minimal UI {{{ +let NERDTreeMinimalUI=1 +" }}} + +" NERDTree autogroup {{{ +augroup nerdtree + autocmd! + + " Open NERDTree when vim starts + "autocmd VimEnter * NERDTree + "autocmd VimEnter * wincmd p + + autocmd FileType nerdtree setlocal relativenumber + autocmd FileType taglist setlocal relativenumber +augroup END +" }}} + +" TabNew {{{ +function TabNew(address) + execute ":tabnew" + execute ":NERDTree " a:address +endfunction +" }}} + +" TabNewBookmark {{{ +function TabNewBookmark(bookmark) + execute ":tabnew" + execute ":NERDTreeFromBookmark " a:bookmark +endfunction +" }}} + +" OpenNERDTree {{{ +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/session_workarounds.vim b/vim.dot.link/plugin/session_workarounds.vim new file mode 100644 index 0000000..75d59cb --- /dev/null +++ b/vim.dot.link/plugin/session_workarounds.vim @@ -0,0 +1,102 @@ +" session_workarounds.vim - Session restoration workarounds {{{ +" +" Author: Silvio Rhatto <rhatto@riseup.net> +" + +" Fix NERDTree width {{{ +" +" Useful after restoring sessions between screen size changes (such +" as when you share sessions between different computers). +function FixWindowWidths() + " Make sure NERDTree is focused + execute ":NERDTreeFocus" + + " Set a fixed width + execute ":vertical resize 30" + + " Move to the left pane + wincmd l +endfunction + +" In case you want to invoke FixWindowWidths explicitly +command! -bang FixWindowWidths :call FixWindowWidths() +" }}} + +" Fix window widths on all tabs {{{ +function FixAllWindowWidths() + " Make sure to run this only once + if exists("did_fixed_window_widths") + return + endif + + " Save the last active window + let l:current_win = win_getid() + + tabdo :call FixWindowWidths() + + " Restore the active window + call win_gotoid(l:current_win) + + " An additional, last move to the left pane + wincmd l + + let did_fixed_window_widths=1 +endfunction +" }}} + +" Ensure the window has maximized height {{{ +" +" This helps restoring the window size after reopening sessions after +" switching monitors (like from laptop screen to external HDMI monitor). +" +" We just want to quickly maximize the window and then restore it to +" it's original size, to ensure all windows are refreshed. +" +" Maybe this is not a NERDTree workaround itself, but more like a +" session workaround. +" +" https://superuser.com/questions/140419/how-to-start-gvim-maximized +" https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size +" https://vi.stackexchange.com/questions/8926/is-it-possible-to-obtain-the-displayable-area-width-and-height-of-current-buffe +"let lines_initial=&l:lines +function FixWindowHeights() + " Set the maximum available height + set lines=999 + + " Set the lines depending on the LINES environment variable + " or through tput. + " + " This is not always inherited by vim: + " https://github.com/vim/vim/issues/12160 + if $LINES != "" + execute ':set lines=' . $LINES + else + let available_lines = system('tput lines') + execute ':set lines=' . available_lines + " Old, and not working approach that tries to reuse the initial height + "else + " execute ':set lines=' . lines_initial + " set lines=999 + " execute ':set lines=' . winheight(0) - 3 + endif +endfunction +" }}} + +" Restore all window sizes {{{ +function RestoreWindowSizes() + call FixWindowHeights() + call FixAllWindowWidths() +endfunction +" }}} + +" Fix all window sizes {{{ +augroup workaround + autocmd! + " This tends to fire for every buffer + autocmd workaround SessionLoadPost * call RestoreWindowSizes() + + " This seems to fire only once, but even when there's no session to be + " restored. + "autocmd workaround VimEnter * call FixAllWindowWidths() +augroup END +" }}} diff --git a/vim.dot.link/plugin/ui.vim b/vim.dot.link/plugin/ui.vim new file mode 100644 index 0000000..f0985cb --- /dev/null +++ b/vim.dot.link/plugin/ui.vim @@ -0,0 +1,47 @@ +" ui.vim - UI customization {{{ +" +" Author: Silvio Rhatto <rhatto@riseup.net> + +" Status and tab lines {{{ +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) +" }}} + +" Powerline {{{ +"python from powerline.vim import setup as powerline_setup +"python powerline_setup() +"python del powerline_setup +" }}} + +" Airline {{{ +if $WINDOWID != "" + " Use powerline symbols + let g:airline_powerline_fonts=1 + + " Enable tabline + let g:airline#extensions#tabline#enabled=1 + + " Tab numbering + let g:airline#extensions#tabline#tab_nr_type = 1 +else + let g:loaded_airline = 1 +endif +" }}} + +" Color scheme {{{ +"colorscheme github +"colorscheme solarized +"colorscheme gentooish +"colorscheme revolutions +"colorscheme two2tango +"colorscheme vj +"colorscheme wood +"colorscheme zenburn +"colorscheme inkpot +if $WINDOWID != "" + colorscheme xoria256 +else + colorscheme zenburn +endif +" }}} diff --git a/vim.dot.link/plugin/window_title.vim b/vim.dot.link/plugin/window_title.vim new file mode 100644 index 0000000..af0ce01 --- /dev/null +++ b/vim.dot.link/plugin/window_title.vim @@ -0,0 +1,30 @@ +" 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 +" }}} |