From 6b7ca41818c329ad5e67b67c54c101f93ff787dc Mon Sep 17 00:00:00 2001 From: Tuan-Dat Tran Date: Tue, 18 Jun 2019 16:06:06 +0200 Subject: [PATCH] Moved config to ~/.vim/config/*.vim instead of having them all in .vimrc --- vim/.vim/config/basics.vim | 21 +++++++ vim/.vim/config/functions.vim | 26 ++++++++ vim/.vim/config/remaps.vim | 24 ++++++++ vim/.vim/config/settings.vim | 14 +++++ vim/.vimrc | 113 ++-------------------------------- 5 files changed, 90 insertions(+), 108 deletions(-) create mode 100644 vim/.vim/config/basics.vim create mode 100644 vim/.vim/config/functions.vim create mode 100644 vim/.vim/config/remaps.vim create mode 100644 vim/.vim/config/settings.vim diff --git a/vim/.vim/config/basics.vim b/vim/.vim/config/basics.vim new file mode 100644 index 0000000..41a4caa --- /dev/null +++ b/vim/.vim/config/basics.vim @@ -0,0 +1,21 @@ +" Basics +syntax on +filetype indent plugin on +set background=light +set encoding=utf-8 +set autowrite +set smartcase +set incsearch +set hlsearch +set nospell + +" Tab behavior +set expandtab +set tabstop=4 +set shiftwidth=4 +set softtabstop=4 + +"" New window positions +set splitbelow +set splitright + diff --git a/vim/.vim/config/functions.vim b/vim/.vim/config/functions.vim new file mode 100644 index 0000000..2eadcc7 --- /dev/null +++ b/vim/.vim/config/functions.vim @@ -0,0 +1,26 @@ +" This callback will be executed when the entire command is completed +function! BackgroundCommandClose(channel) + " Read the output from the command into the quickfix window + unlet g:backgroundCommandOutput +endfunction + +function! RunBackgroundCommand(command) + " Make sure we're running VIM version 8 or higher. + if v:version < 800 + echoerr 'RunBackgroundCommand requires VIM version 8 or higher' + return + endif + if exists('g:backgroundCommandOutput') + echo 'Already running task in background' + else + echo 'Running task in background' + " Launch the job. + " Notice that we're only capturing out, and not err here. This is because, for some reason, the callback + " will not actually get hit if we write err out to the same file. Not sure if I'm doing this wrong or? + let g:backgroundCommandOutput = tempname() + call job_start(a:command, {'close_cb': 'BackgroundCommandClose', 'out_io': 'file', 'out_name': g:backgroundCommandOutput}) + endif +endfunction + +" So we can use :BackgroundCommand to call our function. +command! -nargs=+ -complete=shellcmd RunBackgroundCommand call RunBackgroundCommand() diff --git a/vim/.vim/config/remaps.vim b/vim/.vim/config/remaps.vim new file mode 100644 index 0000000..4c35bf3 --- /dev/null +++ b/vim/.vim/config/remaps.vim @@ -0,0 +1,24 @@ +" Remaps +nnoremap +nnoremap +nnoremap +nnoremap +nnoremap J :bn +nnoremap K :bp +noremap y "+y +noremap :tabedit +noremap :ter +nmap 0 ^ + +" Diaeresis for e.g. german +inoremap a" ä +inoremap o" ö +inoremap u" ü +inoremap A" Ä +inoremap U" Ü +inoremap O" Ö +inoremap jj +inoremap ;s ß +inoremap ;e € + + diff --git a/vim/.vim/config/settings.vim b/vim/.vim/config/settings.vim new file mode 100644 index 0000000..7863194 --- /dev/null +++ b/vim/.vim/config/settings.vim @@ -0,0 +1,14 @@ +" Vim Settings +"" Move the swap file location to protect against CVE-2017-1000382 +if exists('$XDG_CACHE_HOME') + let &g:directory=$XDG_CACHE_HOME +else + let &g:directory=$HOME . '/.cache' +endif +let &g:directory.='/vim/swap//' +"" Create swap directory if it doesn't exist +if ! isdirectory(expand(&g:directory)) + silent! call mkdir(expand(&g:directory), 'p', 0700) +endif + + diff --git a/vim/.vimrc b/vim/.vimrc index 21e7cd4..2920e09 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -1,108 +1,5 @@ -" Plugins -set nocompatible -filetype off - -set rtp+=~/.vim/bundle/Vundle.vim -call vundle#begin() -Plugin 'VundleVim/Vundle.vim' -Plugin 'sheerun/vim-polyglot' -call vundle#end() -filetype plugin indent on - -" Filetypes -au BufNewFile,BufRead *.md set filetype=md -au BufNewFile,BufRead *.tex set filetype=tex -au BufNewFile,BufRead config set filetype=config -" Functions - -"" Move the swap file location to protect against CVE-2017-1000382 -if exists('$XDG_CACHE_HOME') - let &g:directory=$XDG_CACHE_HOME -else - let &g:directory=$HOME . '/.cache' -endif -let &g:directory.='/vim/swap//' -"" Create swap directory if it doesn't exist -if ! isdirectory(expand(&g:directory)) - silent! call mkdir(expand(&g:directory), 'p', 0700) -endif - -" Basics -syntax on -filetype indent plugin on -set background=light -set encoding=utf-8 -set autowrite -set smartcase -set incsearch -set hlsearch -set nofoldenable -set nospell -" Line Numbers -"set number -"set relativenumber - -" Tab behavior -set expandtab -set tabstop=4 -set shiftwidth=4 -set softtabstop=4 - -"" New window positions -set splitbelow -set splitright - -" Remaps -nnoremap -nnoremap -nnoremap -nnoremap -nnoremap J :bn -nnoremap K :bp -noremap y "+y -noremap :tabedit -noremap :ter -nmap 0 ^ - -" Latex -"let g:tex_nospell=1 -" Shortcuts -inoremap date =strftime("%Y/%m/%d") -inoremap time =strftime("%H:%M:%S") -" Diaeresis for e.g. german -inoremap a" ä -inoremap o" ö -inoremap u" ü -inoremap A" Ä -inoremap U" Ü -inoremap O" Ö -inoremap jj -inoremap ;s ß -inoremap ;e € - -" This callback will be executed when the entire command is completed -function! BackgroundCommandClose(channel) - " Read the output from the command into the quickfix window - unlet g:backgroundCommandOutput -endfunction - -function! RunBackgroundCommand(command) - " Make sure we're running VIM version 8 or higher. - if v:version < 800 - echoerr 'RunBackgroundCommand requires VIM version 8 or higher' - return - endif - if exists('g:backgroundCommandOutput') - echo 'Already running task in background' - else - echo 'Running task in background' - " Launch the job. - " Notice that we're only capturing out, and not err here. This is because, for some reason, the callback - " will not actually get hit if we write err out to the same file. Not sure if I'm doing this wrong or? - let g:backgroundCommandOutput = tempname() - call job_start(a:command, {'close_cb': 'BackgroundCommandClose', 'out_io': 'file', 'out_name': g:backgroundCommandOutput}) - endif -endfunction - -" So we can use :BackgroundCommand to call our function. -command! -nargs=+ -complete=shellcmd RunBackgroundCommand call RunBackgroundCommand() +" Load files from somewhere else +source ~/.vim/config/settings.vim +source ~/.vim/config/basics.vim +source ~/.vim/config/remaps.vim +source ~/.vim/config/functions.vim