From 7b43075070da9811d08d78531a24974addd3194a Mon Sep 17 00:00:00 2001 From: Jakub Fojt Date: Sun, 9 Feb 2020 11:49:54 +0100 Subject: [PATCH] vimrc: Group autocommands, change colorcolumn color --- .vimrc | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.vimrc b/.vimrc index ea58e72..277efb0 100755 --- a/.vimrc +++ b/.vimrc @@ -34,19 +34,35 @@ else command CloneVundle execute "!git clone " . vundle_repo . " " . vundle_dir endif -set updatetime=1000 " Default is 4s, but reduce it to make things more real time, like git gutter -highlight Search ctermbg=5 +if !exists("vimrc_autocmds_loaded") + let vimrc_autocmds_loaded = 1 -filetype plugin indent on " required -syntax on -" -" Set the filetype based on the file's extension, but only if -" 'filetype' has not already been set -augroup filetypedetect + " Set the filetype based on the file's extension, but only if + " 'filetype' has not already been set au BufRead,BufNewFile .i3initrc setfiletype sh au BufRead,BufNewFile *.config setfiletype conf au BufRead,BufNewFile [Ss]nakefile.* setfiletype snakemake -augroup END + + au BufWritePost * if search('\s\+$', 'wn') | call WhitespaceWarn() | endif + + au BufRead,BufNewFile * setlocal textwidth=0 | setlocal colorcolumn= + au BufRead,BufNewFile *.md setlocal textwidth=80 | setlocal colorcolumn=80 + + if exists(":NERDTree") + " Open NERDTree if no file specified + au StdinReadPre * let s:std_in=1 + au VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif + endif + + au BufEnter,FocusGained,InsertLeave * set rnu + au BufLeave,FocusLost,InsertEnter * set nornu +endif +set updatetime=1000 " Default is 4s, but reduce it to make things more real time, like git gutter +highlight Search ctermbg=5 +highlight ColorColumn ctermbg=4 + +filetype plugin indent on " required +syntax on set tabstop=4 " show existing tab with 4 spaces width set shiftwidth=4 " when indenting with '>', use 4 spaces width @@ -75,17 +91,11 @@ function! StripTrailingWhitespace() call winrestview(l:save) echo "Stripped trailing whitespace" endfunction -au BufRead,BufNewFile *.md setlocal textwidth=80 -autocmd BufWritePost * if search('\s\+$', 'wn') | call WhitespaceWarn() | endif + command TrailWhitespace call StripTrailingWhitespace() " Hybrid line numbers on active buffer set nu rnu -augroup numbertoggle - autocmd! - autocmd BufEnter,FocusGained,InsertLeave * set rnu - autocmd BufLeave,FocusLost,InsertEnter * set nornu -augroup END " Do incremental searching when it's possible to timeout. if has('reltime') @@ -118,11 +128,6 @@ set statusline+=\ %l:%c" set statusline+=%#MoreMsg# set statusline+=\ " -if exists(":NERDTree") - " Open NERDTree if no file specified - autocmd StdinReadPre * let s:std_in=1 - autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif -endif " CtrlP let g:ctrlp_working_path_mode = 'ra' @@ -172,11 +177,6 @@ vnoremap * y:%sno/"//g nmap :NERDTreeToggle nmap :NERDTreeFind map :call CurtineIncSw() -nmap :silent !/home/efjtjkb/bin/comp -" Remap (c-vim uses this) -"nmap :silent !/home/efjtjkb/bin/run -autocmd VimEnter * noremap :silent !/home/efjtjkb/bin/run -nmap :silent !/home/efjtjkb/bin/run old nmap cf :cd %:p:h " Change dir to parent of current file nmap cg :cd $git_root_location " Change dir to git root