From 0be70b348690a6231adb6b420ff428d9ba4f8139 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Mon, 14 Aug 2017 22:10:20 +1000 Subject: [PATCH] vimrc: portable, simplified --- .vim/.gitignore | 2 - .vim/commenter.vim | 101 ------------------------- .vim/display.vim | 57 -------------- .vim/filetypes.vim | 38 ---------- .vim/indent.vim | 31 -------- .vim/macros.vim | 177 -------------------------------------------- .vim/state.vim | 25 ------- .vimrc | 180 +++++++++++++++++++++++++++++++++++++++++---- README.md | 4 +- 9 files changed, 168 insertions(+), 447 deletions(-) delete mode 100644 .vim/.gitignore delete mode 100644 .vim/commenter.vim delete mode 100644 .vim/display.vim delete mode 100644 .vim/filetypes.vim delete mode 100644 .vim/indent.vim delete mode 100644 .vim/macros.vim delete mode 100644 .vim/state.vim diff --git a/.vim/.gitignore b/.vim/.gitignore deleted file mode 100644 index df05fc0..0000000 --- a/.vim/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.netrwhist -viminfo* diff --git a/.vim/commenter.vim b/.vim/commenter.vim deleted file mode 100644 index 3ff213d..0000000 --- a/.vim/commenter.vim +++ /dev/null @@ -1,101 +0,0 @@ -" Commenting of lines! Stolen & modified from vim.org's ToggleCommentify -map :call ToggleCommentify()j -imap :call ToggleCommentify()j -" The nice thing about these mapping is that you don't have to select a visual -" block to comment ... just keep the CTRL-key pressed down and tap on 'c' as -" often as you need. - -function! ToggleCommentify() - let lineString = getline(".") - if strlen(lineString) == 0 - " don't comment empty lines - return - endif - - let isCommented = strpart(lineString,0,3) - let commentSymbol = '' - - let commentMapping = { - \'###': [ - \'conf', - \'debsources', - \'exports', - \'fstab', - \'make', - \'mplayerconf', - \'muttrc', - \'perl', - \'procmail', - \'python', - \'readline', - \'ruby', - \'screen', - \'sh', - \'sshconfig', - \'sudoers', - \'terminfo', - \'vrml', - \'xf86conf', - \], -\ - \'///': [ - \'c', - \'cpp', - \'java', - \'javascript', - \'objc', - \'ox', - \'php', - \'groovy', - \], -\ - \'"""': [ - \'vim', - \], -\ - \'!!!': [ - \'xdefaults', - \], -\ - \'%%%': [ - \'matlab', - \'tex', - \], -\ - \'---': [ - \'sql', - \'haskell', - \] - \} - - for commentChar in keys(commentMapping) - for name in commentMapping[commentChar] - if &filetype == name - let commentSymbol = commentChar - endif - endfor - endfor - - if commentSymbol == '' - execute 'echo "ToggleCommentify has not (yet) been implemented for the file-type " . &filetype' - else - if isCommented == commentSymbol - " if the line is already commented, uncomment - call UnCommentify(commentSymbol) - else - " if the line is uncommented, comment - call Commentify(commentSymbol) - endif - endif -endfunction - -function! Commentify(commentSymbol) - execute ':s+^+'.a:commentSymbol.'+' - nohlsearch -endfunction - -function! UnCommentify(commentSymbol) - execute ':s+'.a:commentSymbol.'++' - nohlsearch -endfunction - diff --git a/.vim/display.vim b/.vim/display.vim deleted file mode 100644 index 12c478d..0000000 --- a/.vim/display.vim +++ /dev/null @@ -1,57 +0,0 @@ -" Pretty syntax highlighting -syntax on - -" Show the line/column positions at the bottom -set ruler - -" Display as much as possible of the last line of text -" (instead of displaying an @ character) -set display+=lastline - -" Wrapping is annoying -set nowrap - -" If wordwrap is on, don't split words across lines -set linebreak - -" String to put at the start of lines that have been wrapped -"set showbreak=+ -set showbreak= - -" Display current mode and partially typed commands -set showmode -set showcmd - -" When a bracket is inserted, briefly jump to the matching one ( -set showmatch - -" Show the filename title in xterms -set title -set t_ts=]0; -set t_fs= - -" Make the autocompletion of filenames,etc behave like bash -set wildmode=longest,list - -" Allow splits to have 0 height (use C-W _) -set wmh=0 - -" Always keep one line of context around the cursor -set scrolloff=1 - -" Match search results as you type -set incsearch - -" Ignore case when searching -set ignorecase - -" Ignore the ignorecase character if search contains uppercase chars -set smartcase - -" Highlight search terms -set hlsearch - -" Mouse options -set mouse=a -set mousehide - diff --git a/.vim/filetypes.vim b/.vim/filetypes.vim deleted file mode 100644 index fbdd84a..0000000 --- a/.vim/filetypes.vim +++ /dev/null @@ -1,38 +0,0 @@ -" Make vim aware of filetypes, this loads files in -" vimdir/{ftplugin,indent}/lang.vim -" where vimdir is /usr/share/vim/vimXX/ or ~/.vim/ -" The intention is for vim to set up sensible indentation rules and other -" settings depending on the filetype. -filetype plugin indent on - -" Pick up some filetypes from their extensions -autocmd BufNewFile,BufRead *.txt setlocal ft=text -autocmd BufNewFile,BufRead mutt* setlocal ft=mail -autocmd BufNewFile,BufRead *.tex setlocal ft=tex -autocmd BufNewFile,BufRead CMakeLists.txt setlocal ft=cmake -autocmd BufNewFile,BufRead buildfile setlocal ft=ruby -autocmd BufNewFile,BufRead build.gradle setlocal ft=groovy - -" Set options based on filetypes, overriding the filetype plugin/indent options -autocmd FileType text call WrapOn() -autocmd FileType markdown call WrapOn() -autocmd FileType bib setlocal textwidth=78 nocindent smartindent -autocmd FileType mail setlocal textwidth=0 -autocmd FileType mail call WrapOn() -autocmd FileType tex call WrapOn() -autocmd FileType objc setlocal nocindent smartindent -autocmd FileType cmake setlocal nowrap -autocmd FileType vim setlocal formatoptions-=r - -" Don't allow syntax/sh.vim to change my iskeyword setting -let g:sh_noisk=1 - -" Who uses octal anyway? -set nrformats-=octal - -" Don't automatically continue comments on new lines -"""autocmd BufNewFile,BufRead * setlocal formatoptions-=r - -" Use space for indendation in some files -" autocmd BufNewFile,BufRead /path/to/someproject setlocal expandtab tabstop=8 softtabstop=4 shiftwidth=4 - diff --git a/.vim/indent.vim b/.vim/indent.vim deleted file mode 100644 index 1219c79..0000000 --- a/.vim/indent.vim +++ /dev/null @@ -1,31 +0,0 @@ -" Indentation - -" Automatically continue indentation across lines -set autoindent -" Keep indentation structure (tabs, spaces, etc) when autoindenting. -set copyindent - -" Expand tab to spaces -set expandtab -" Size of a \t -set tabstop=8 -" Delete this many space chars when pressing backspace -set softtabstop=4 -set shiftwidth=4 - -" < and > will hit indentation levels instead of adding/subtracting shiftwidth -set shiftround - -" Single indent for line continuations -set cinoptions=+1s -set cinoptions=(1s -let g:pyindent_open_paren = &sw -let g:pyindent_continue = &sw -let g:vim_indent_cont = &sw - -" Single space after full stop -set nojoinspaces - -" Use :retab to change the file to entirely space indents -" Use :retab! to change the file to entirely tab indents - diff --git a/.vim/macros.vim b/.vim/macros.vim deleted file mode 100644 index cb8ef4b..0000000 --- a/.vim/macros.vim +++ /dev/null @@ -1,177 +0,0 @@ -" Function key mappings -map :call ToggleSpelling() -imap :call ToggleSpelling() -map :call InvShow() -imap :call InvShow() -map :call WrapToggle() -imap :call WrapToggle() -map :call PasteToggle() -imap :call PasteToggle() - -" Unhighlight search results and redraw the screen -nmap :nohlsearch:redraw! - -" Map Y to be consistent with D, C, etc -nmap Y y$ - -" CTRL-n and CTRL-p to go forwards and backwards through files -nmap :next -nmap :prev - -" CTRL-J/K to move up and down, collapsing open windows -map j_ -map k_ - -" Press CTRL-z after pasting something to fix up formatting -imap u:set paste.:set nopastei - -" Tab to switch between split windows -nmap -nmap [Z W - -" Q to reformat paragraph. I never use ex mode anyway (default binding for Q) -nmap Q gwip - -" Save using sudo -command SudoWrite call SudoWriteFunction() - -" I frequently type :Q or :WQ, etc instead of :q, :wq -command WQA :wqa -command WqA :wqa -command WQa :wqa -command Wqa :wqa -command WA :wa -command Wa :wa -command WQ :wq -command Wq :wq -command W :w -command Wn :wn -command WN :wn -command Wp :wp -command WP :wp -command QA :qa -command Qa :qa -command Q :q - -" Make the number pad work -map OX = -imap OX = -set t_KC=Op " 0 -set t_KD=Oq " 1 -set t_KE=Or " 2 -set t_KF=Os " 3 -set t_KG=Ot " 4 -set t_KH=Ou " 5 -set t_KI=Ov " 6 -set t_KJ=Ow " 7 -set t_KK=Ox " 8 -set t_KL=Oy " 9 - -" Toggle wordwrap -function WrapToggle() - if &wrap - call WrapOff() - echo "Word wrap off" - else - call WrapOn() - echo "Word wrap on" - endif -endfunction - -" Turn word wrap off, reset arrows, home, end, etc to default bindings -function WrapOff() - setlocal nowrap - " Go up and down by physical linebreaks when not wordwrapped - iunmap - iunmap - iunmap - iunmap - nunmap - nunmap - nunmap - nunmap - nunmap 0 - nunmap ^ - nunmap $ - vunmap - vunmap - vunmap - vunmap - vunmap 0 - vunmap ^ - vunmap $ - " Allow only backspace & space - set whichwrap=b,s -endfunction - -" Turn word wrapping on and bind arrows, home, end, etc to display lines -function WrapOn() - setlocal wrap - " Go up and down by display lines, not linebreaks when wordwrapped - imap g$ - imap g0 - imap gj - imap gk - nmap gj - nmap gk - nmap g$ - nmap g0 - nmap 0 g0 - nmap ^ g^ - nmap $ g$ - vmap gj - vmap gk - vmap g$ - vmap g0 - vmap 0 g0 - vmap ^ g^ - vmap $ g$ - " Allow backspace, space, left/right keys to move across lines - set whichwrap=b,s,<,>,[,] -endfunction - - -" Toggle show invisible characters -function InvShow() - if &list - echo "Invisible characters off" - set nolist - else - echo "Invisible characters on" - set listchars=tab:.\ ,trail:! - set list - endif -endfunction - - -" Spell checking mode toggle -function ToggleSpelling() - if !exists("s:spell_check") || s:spell_check == 0 - echo "Spell check on" - let s:spell_check = 1 - setlocal spell spelllang=en_au - else - echo "Spell check off" - let s:spell_check = 0 - setlocal spell spelllang= - endif -endfunction - - -" Save using sudo -function SudoWriteFunction() - :w !sudo tee % - :e! -endfunction - -" Toggle paste mode -function PasteToggle() - if &paste - set nopaste - echo "Paste mode disabled" - else - set paste - echo "Paste mode enabled" - endif -endfunction - diff --git a/.vim/state.vim b/.vim/state.vim deleted file mode 100644 index 9df6ea6..0000000 --- a/.vim/state.vim +++ /dev/null @@ -1,25 +0,0 @@ -" Keep viminfo -set viminfo=%,'100,\"100,:100,n~/.vim/viminfo - -" Vim jumps to the last position when reading a file -au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif - -" Keep history -set history=100 - -" Make a backup (i. e. 'file~') and save it. -set backup -" create ~/tmp/vimbak if it doesn't exist and use it to save the backups -if has("unix") - if !isdirectory(expand("~/tmp/vimbak/.")) - !mkdir -p ~/tmp/vimbak - endif - set backupdir=~/tmp/vimbak -endif - -" Create backups by copying files to backup directory instead of renaming -set backupcopy=yes - -" Use modelines -set modelines=5 - diff --git a/.vimrc b/.vimrc index 21abecb..50b5897 100644 --- a/.vimrc +++ b/.vimrc @@ -1,17 +1,169 @@ -" Don't try to be like vi set nocompatible +set backspace=indent,eol,start -" Backspace should work across lines -set bs=2 - -" Read files from ~/.vim -source ~/.vim/state.vim -source ~/.vim/display.vim -source ~/.vim/indent.vim -source ~/.vim/macros.vim -source ~/.vim/commenter.vim -source ~/.vim/filetypes.vim -if filereadable(expand("~/.vim/local.vim")) - source ~/.vim/local.vim -endif + +set backup +set backupdir=~/tmp/vimbak +set backupcopy=yes +silent exec "!mkdir -p ~/tmp/vimbak" +silent exec "!find ~/tmp/vimbak -type f -mtime +3 -delete" + + +syntax on +filetype plugin indent on + +" restore position when opening files +autocmd BufReadPost * + \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' + \ | exe "normal! g`\"" + \ | endif + +" don't automatically continue comments on new lines +autocmd BufNewFile,BufRead * setlocal formatoptions-=r + + +" xterm mouse +set mouse=a + +" xterm titles +set title +set t_ts=]0; +set t_fs= + + +" show useful things on the status line +set showmode +set showcmd +set ruler + +" display as much as possible of the last line, instead of @ +set display+=lastline + +" matching brackets +set showmatch + +" auto-complete should work like bash +set wildmode=longest,list + +" show one extra line when scrolling +set scrolloff=1 + +" decent searching +set incsearch +set ignorecase +set smartcase +set hlsearch + + +" decent indentation +set autoindent +set copyindent +set shiftround + +" spaces over tabs +set expandtab +set tabstop=8 +set softtabstop=4 +set shiftwidth=4 + +" single indent for line continuations +set cinoptions=+1s +set cinoptions=(1s +let g:pyindent_open_paren = &sw +let g:pyindent_continue = &sw +let g:vim_indent_cont = &sw + +" don't allow syntax/sh.vim to change my iskeyword setting +let g:sh_noisk=1 + +" single space after full stop +set nojoinspaces + +" disable octal +set nrformats-=octal + + +nmap :next +nmap :prev + +nmap :nohlsearch:redraw! + +command SudoWrite call SudoWriteFunction() + +map :call ToggleSpelling() +imap :call ToggleSpelling() +map :call InvShow() +imap :call InvShow() +map :call WrapToggle() +imap :call WrapToggle() +map :call PasteToggle() +imap :call PasteToggle() + + +function ToggleSpelling() + if !exists("s:spell_check") || s:spell_check == 0 + echo "Spell check on" + let s:spell_check = 1 + setlocal spell spelllang=en_au + else + echo "Spell check off" + let s:spell_check = 0 + setlocal spell spelllang= + endif +endfunction + +function WrapToggle() + if &wrap + set nowrap + echo "Word wrap off" + else + set wrap + echo "Word wrap on" + endif +endfunction + +function InvShow() + if &list + echo "Invisible characters off" + set nolist + else + echo "Invisible characters on" + set listchars=tab:.\ ,trail:! + set list + endif +endfunction + +function SudoWriteFunction() + :w !sudo tee % + :e! +endfunction + +function PasteToggle() + if &paste + set nopaste + echo "Paste mode disabled" + else + set paste + echo "Paste mode enabled" + endif +endfunction + + +" typos +command WQA :wqa +command WqA :wqa +command WQa :wqa +command Wqa :wqa +command WA :wa +command Wa :wa +command WQ :wq +command Wq :wq +command W :w +command Wn :wn +command WN :wn +command Wp :wp +command WP :wp +command QA :qa +command Qa :qa +command Q :q diff --git a/README.md b/README.md index 8a44855..675dc0f 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ Make a backup of any existing files: ``` cd mkdir -p backup -mv .bash .bash_profile .bashrc .gitconfig .inputrc .pythonrc.py .screenrc .vim .vimrc backup/ +mv .bash .bash_profile .bashrc .gitconfig .inputrc .pythonrc.py .screenrc .vimrc backup/ ``` Symlink the config files into your home directory: ``` -ln -sf ~/.dotfiles/{.bash,.bash_profile,.bashrc,.gitconfig,.inputrc,.pythonrc.py,.screenrc,.vim,.vimrc} ~/ +ln -sf ~/.dotfiles/{.bash,.bash_profile,.bashrc,.gitconfig,.inputrc,.pythonrc.py,.screenrc,.vimrc} ~/ ln -sf ~/.dotfiles/.gitignore_global ~/.gitignore ln -sf ~/.dotfiles/.ssh/config ~/.ssh/ ``` -- 2.39.2