" VIM configuration " Basic options syn on set nu set background=dark set nobackup set nowritebackup set noswapfile set noautoindent set nosmartindent set tabstop=2 set shiftwidth=2 set expandtab set mouse=a set autoread set nocompatible set laststatus=2 set shortmess+=I set ignorecase set smartcase " Window title handling set title set titleold="terminal" set titlestring=vim:\ %F " 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 " a:title endfunction au VimLeave *mutt/* silent call ResetTitle("mutt") au VimLeave *remind/* silent call ResetTitle("wyrd") " 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 " Folding set foldmethod=syntax set foldlevelstart=99 let g:sh_fold_enabled=1 let javaScript_fold=1 let perl_fold=1 let php_folding=1 let r_syntax_folding=1 let ruby_fold=1 let sh_fold_enabled=1 let vimsyn_folding='af' let xml_syntax_folding=1 " PHP let php_sql_query=1 " Filetypes au BufNewFile,BufRead *.vue set ft=html au BufNewFile,BufRead *.thtml set ft=php au BufNewFile,BufRead *.mdwn set ft=ikiwiki au BufNewFile,BufRead *.md set ft=ikiwiki au BufNewFile,BufRead *.rem set ft=remind au BufNewFile,BufRead *.trac set ft=tracwiki au BufNewFile,BufRead *.tracwiki set ft=tracwiki au BufNewFile,BufRead Vagrantfile set ft=ruby augroup mkd autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:> augroup END if has("autocmd") " Drupal *.module and *.install files. augroup module autocmd BufRead,BufNewFile *.profile set filetype=php autocmd BufRead,BufNewFile *.module set filetype=php autocmd BufRead,BufNewFile *.install set filetype=php autocmd BufRead,BufNewFile *.test set filetype=php augroup END endif " Pathogen - https://github.com/tpope/vim-pathogen call pathogen#infect() syntax on filetype plugin indent on " No modelines " https://lwn.net/Articles/20249/ " http://usevim.com/2012/03/28/modelines/ " http://www.techrepublic.com/blog/it-security/turn-off-modeline-support-in-vim/ set nomodeline set modelines=0 " Syntax check 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 ) nmap n :tabnew nmap t :OpenNERDTree "nmap q :wqa "map c :wqa nmap f :wq nmap c :tabclose "map e :tabclose nmap b :NERDTreeFromBookmark nmap B :B nmap s :OpenSession nmap m :q! nmap w :w imap n :tabnew imap t :OpenNERDTree "imap q :wqa "map c :wqa imap f :wq imap c :tabclose "map e :tabclose imap m :q! imap w :w " Write, quit and close shortcuts using Alt-key combo notation "map n :tabnew "map t :OpenNERDTree "map q :wqa "map c :wqa "map f :wq "map c :tabclose "map e :tabclose "nmap b :NERDTreeFromBookmark "nmap B :B "nmap s :OpenSession "map m :q! "map w :w "imap n :tabnew "imap t :OpenNERDTree "imap q :wqa "imap c :wqa "imap f :wq "imap c :tabclose "imap e :tabclose "imap m :q! "imap w :w " Write, quit and close shortcuts using Ctrl-key combos " We're using these due to a conflict with wyrd(1) "nmap :tabnew "nmap :OpenNERDTree "nmap :wqa "nmap :wqa "nmap :wq "nmap :tabclose "nmap :tabclose "nmap :NERDTreeFromBookmark "nmap :B "nmap :OpenSession "nmap :q! "nmap :w "imap :tabnew "imap :OpenNERDTree "imap :wqa "imap :wqa "imap :wq "imap :tabclose "imap :tabclose "imap :q! "imap :w " Write, quit and close shortcuts map q :wqa "map f :wq "map t :tabclose "map m :q! "map w :w " Tab navigation " See http://vim.wikia.com/wiki/Alternative_tab_navigation " http://comments.gmane.org/gmane.os.cygwin.xfree/16419 nmap [5^ nmap [6^ nnoremap :tabn nnoremap :tabp nmap 1 1gt nmap 2 2gt nmap 3 3gt nmap 4 4gt nmap 5 5gt nmap 6 6gt nmap 7 7gt nmap 8 8gt nmap 9 9gt nmap 0 10gt " Buffer navigation: Alt-{Up,Down} map Od :bprevious map Oc :bnext " Window navigation "map "map "map "map "imap "imap "imap "imap "map  "map  "map  "map  "imap  "imap  "imap  "imap  nmap nmap nmap nmap imap imap imap imap " NERDTree section " Thanks to http://stackoverflow.com/questions/1447334/how-do-you-add-nerdtree-to-your-vimrc " Open NERDTree when vim starts "autocmd VimEnter * NERDTree "autocmd VimEnter * wincmd p autocmd FileType nerdtree set relativenumber autocmd FileType taglist set relativenumber 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 vmap "+yi vmap "+c " Workaround for mail editing. There must be a plugin enabling autoindent in " mail composition, which is annoying. au FileType mail set noautoindent " 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 "colorscheme gentooish "colorscheme revolutions "colorscheme two2tango "colorscheme vj "colorscheme wood "colorscheme zenburn "colorscheme inkpot colorscheme xoria256 " Airline let g:airline_powerline_fonts=1 let g:airline#extensions#tabline#enabled=1 " Powerline "python from powerline.vim import setup as powerline_setup "python powerline_setup() "python del powerline_setup 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) " See " 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 " Session management, see: " http://usevim.com/2013/07/05/sessions/ " https://github.com/xolox/vim-session " https://github.com/tpope/vim-obsession " http://stackoverflow.com/questions/1642611/how-to-save-a-session-in-vim " https://bocoup.com/weblog/sessions-the-vim-feature-you-probably-arent-using/ " http://vimdoc.sourceforge.net/htmldoc/usr_21.html#21.4 "let g:session_autosave_periodic=1 let g:session_autosave_silent=1 let g:session_autosave='yes' let g:session_autoload='no' let g:session_directory='~/.local/share/vim/sessions' let NERDTreeMinimalUI=1 " Autosave " See https://github.com/vim-scripts/vim-auto-save "let g:auto_save = 1