├── chocolatey ├── vim48x48.png ├── tools │ ├── chocolateyInstall.ps1 │ ├── chocolateyUninstall.ps1 │ └── Install-ContextMenu.ps1 └── vim-dwiw2015.nuspec ├── Makefile ├── bootstrap.sh ├── plugin └── dwiw2015.vim ├── bootstrap.ps1 └── README.md /chocolatey/vim48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkropat/vim-dwiw2015/HEAD/chocolatey/vim48x48.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test 2 | test: 3 | shellcheck --exclude SC2088 bootstrap.sh 4 | checkbashisms bootstrap.sh 5 | 6 | -------------------------------------------------------------------------------- /chocolatey/tools/chocolateyInstall.ps1: -------------------------------------------------------------------------------- 1 | $toolsPath = Split-Path -parent $MyInvocation.MyCommand.Definition 2 | $bootstrapPath = Join-Path $toolsPath bootstrap.ps1 3 | $installCtxPath = Join-Path $toolsPath 'Install-ContextMenu.ps1' 4 | 5 | & $bootstrapPath 6 | 7 | Start-ChocolateyProcessAsAdmin "& `'$installCtxPath`'" 8 | -------------------------------------------------------------------------------- /chocolatey/tools/chocolateyUninstall.ps1: -------------------------------------------------------------------------------- 1 | $packageName = 'vim-dwiw2015' 2 | 3 | $toolsPath = Split-Path -parent $MyInvocation.MyCommand.Definition 4 | $bootstrapPath = Join-Path $toolsPath bootstrap.ps1 5 | 6 | try { 7 | & $bootstrapPath -Uninstall 8 | Write-ChocolateySuccess "$packageName" 9 | } catch { 10 | Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)" 11 | throw 12 | } 13 | -------------------------------------------------------------------------------- /chocolatey/tools/Install-ContextMenu.ps1: -------------------------------------------------------------------------------- 1 | function Get-GvimExePath { 2 | # Find Vim directory from the *Cream* Vim Installer's UninstallString 3 | $is64bit = [IntPtr]::size -eq 8 4 | if ($is64bit) { 5 | $hklmSoftwareWindows = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion' 6 | } else { 7 | $hklmSoftwareWindows = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' 8 | } 9 | $uninstallVim = Join-Path $hklmSoftwareWindows 'Uninstall\Vim' 10 | $uninstallString = (Get-ItemProperty $uninstallVim UninstallString).UninstallString 11 | $installDir = Split-Path -Parent $uninstallString 12 | return Join-Path $installDir 'gvim.exe' 13 | } 14 | 15 | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT ` 16 | -ErrorAction SilentlyContinue | Out-Null 17 | 18 | Set-Location -LiteralPath HKCR:\*\shell 19 | New-Item -Name vim -Force | Out-Null 20 | Set-Item -Path vim -Value 'Edit with &Vim' 21 | 22 | $path = Get-GvimExePath 23 | New-Item -Path vim -Name command | Out-Null 24 | Set-Item -Path vim\command -Value """${path}"" ""%1""" 25 | -------------------------------------------------------------------------------- /chocolatey/vim-dwiw2015.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | vim-dwiw2015 5 | vim-dwiw2015 6 | 0.5 7 | Michael Kropat 8 | Minimal Vim Distribution - Do What I Want In 2015 9 | A minimal Vim distribution. Sets up Vim with the sensible defaults that you'd expect from a modern text editor. 10 | Benefits at a glance: 11 | * No cruft in your `_vimrc` 12 | * Default settings are cleanly segregated into a plug-in 13 | * Modern plug-in management with Vundle 14 | * Includes a *small*, curated set of plug-ins to provide modern text editor functionality 15 | See the Project Site for more details. 16 | 17 | https://github.com/mkropat/vim-dwiw2015 18 | vim distribution editor admin 19 | http://vimdoc.sourceforge.net/htmldoc/uganda.html 20 | false 21 | https://raw.github.com/mkropat/vim-dwiw2015/master/chocolatey/vim48x48.png 22 | 23 | 24 | 25 | 26 | 27 | 28 | 0.5 - Add "Edit with Vim" context menu action 29 | 0.4 - Update to new Vundle interface 30 | - Add `cuninst` support 31 | - Install to correct `%HOME%` folder 32 | 0.3 - Fix ArgumentList error in bootstrap.ps1 33 | 0.2 - Bundle The Silver Searcher 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # bootstrap.sh -- install the dwiw2015 Vim distribution 3 | 4 | # See the Github page (https://github.com/mkropat/vim-dwiw2015) for details 5 | 6 | # It should be safe to run -- even on an existing Vim set up. Re-running the 7 | # `bootstrap.sh` script is safe — it simply resumes the installation and checks 8 | # for updates on any plug-ins already installed. 9 | 10 | main() { 11 | parse_options "$@" && 12 | check_for_prerequisites && 13 | locate_paths && 14 | 15 | ensure_vundle_installed && 16 | 17 | # Create `~/.vim/dwiw-loader.vim` script to load Vundle and then call 18 | # `bundles.vim`. Do not modify the loader file. 19 | ensure_loader_file_exists && 20 | 21 | # Create `~/.vim/bundles.vim` script, which contains a list of Vundle 22 | # plug-ins. Feel free to make local modifications to this file. 23 | ensure_bundles_file_populated && 24 | 25 | # Prepand a one-line hook in `~/.vimrc` to call `dwiw-loader.vim`. 26 | ensure_vimrc_hook_exists && 27 | 28 | install_or_update_bundles && 29 | 30 | msg 'Bootstrap successful! Run `vim` or `gvim` to get started' 31 | } 32 | 33 | parse_options() { 34 | quiet=--quiet 35 | 36 | while getopts v opt; do 37 | case "$opt" in 38 | v) # be verbose 39 | quiet= 40 | ;; 41 | esac 42 | done 43 | 44 | shift $(( OPTIND - 1 )) 45 | } 46 | 47 | check_for_prerequisites() { 48 | local missing='' 49 | for command in git vim; do 50 | if ! hash "$command" 2>/dev/null; then 51 | missing="$missing $command" 52 | fi 53 | done 54 | if [ -n "$missing" ]; then 55 | die "Error: missing dependencies:$missing" 56 | fi 57 | } 58 | 59 | locate_paths() { 60 | myvimrc_path=$(resolve_symlinks ~/.vimrc) 61 | 62 | local myvimfiles_path myvimfiles_tlde 63 | myvimfiles_path=~/.vim 64 | myvimfiles_tlde="~/.vim" 65 | 66 | loader_file_path=$(resolve_symlinks "$myvimfiles_path/dwiw-loader.vim") 67 | loader_file_tlde="$myvimfiles_tlde/dwiw-loader.vim" 68 | 69 | bundles_file_path=$(resolve_symlinks "$myvimfiles_path/bundles.vim") 70 | bundles_file_tlde="$myvimfiles_tlde/bundles.vim" 71 | 72 | vundle_path=$(resolve_symlinks "$myvimfiles_path/bundle/vundle") 73 | vundle_tlde="$myvimfiles_tlde/bundle/vundle" 74 | } 75 | 76 | ensure_vundle_installed() { 77 | if [ -d "$vundle_path/.git" ]; then 78 | return 79 | fi 80 | 81 | msg "Installing Vundle into $vundle_path" 82 | git clone "$quiet" https://github.com/gmarik/vundle.git "$vundle_path" || 83 | die "Error: unable to clone Vundle repo" 84 | } 85 | 86 | ensure_loader_file_exists() { 87 | local loader_version="1.1" 88 | if [ ! -e "$loader_file_path" ]; then 89 | msg "Creating loader script at '$loader_file_path'" 90 | write_loader_script_to "$loader_file_path" "$loader_version" || 91 | die "Error: unable to create loader script at $loader_file_path" 92 | elif [ "$(get_script_version "$loader_file_path")" != "$loader_version" ]; then 93 | msg "Upgrading loader script at '$loader_file_path' to latest version" 94 | write_loader_script_to "$loader_file_path" "$loader_version" || 95 | die "Error: unable to create loader script at $loader_file_path" 96 | fi 97 | } 98 | 99 | get_script_version() { 100 | perl -ne '/^" Version: (.*)/ && do { print "$1\n"; exit }' "$1" 2>/dev/null 101 | } 102 | 103 | write_loader_script_to() { 104 | local script="\" dwiw-loader.vim - Load Vundle and tell it about bundles 105 | \" Version: $2 106 | set nocompatible 107 | filetype off 108 | set rtp+=$vundle_tlde/ 109 | call vundle#rc() 110 | source $bundles_file_tlde 111 | filetype plugin indent on 112 | runtime! plugin/sensible.vim 113 | runtime! plugin/dwiw2015.vim" 114 | printf '%s\n' "$script" >|"$1" 115 | } 116 | 117 | ensure_bundles_file_populated() { 118 | if [ ! -e "$bundles_file_path" ]; then 119 | msg "Creating bundles file at $bundles_file_path" 120 | fi 121 | 122 | # Migrate from old Vundle interface to new interface 123 | perl -pi -e 's/^Bundle /Plugin /' "$bundles_file_path" 124 | 125 | ensure_bundle_line 'gmarik/vundle' 126 | 127 | ensure_bundle_line 'tpope/vim-sensible' 128 | ensure_bundle_line 'mkropat/vim-dwiw2015' 129 | 130 | ensure_bundle_line 'bling/vim-airline' 131 | ensure_bundle_line 'ctrlpvim/ctrlp.vim' 132 | ensure_bundle_line 'mileszs/ack.vim' 133 | ensure_bundle_line 'tpope/vim-commentary' 134 | ensure_bundle_line 'tpope/vim-sleuth' 135 | } 136 | 137 | ensure_bundle_line() { 138 | if ! fgrep -qe "$1" "$bundles_file_path" 2>/dev/null; then 139 | printf "Plugin '%s'\n" "$1" >>"$bundles_file_path" 140 | fi 141 | } 142 | 143 | ensure_vimrc_hook_exists() { 144 | if ! grep -qe "^source $loader_file_tlde" "$myvimrc_path" 2>/dev/null; then 145 | msg "Adding hook to .vimrc" 146 | prepend_line "source $loader_file_tlde" "$myvimrc_path" || 147 | die "Error: unable to add loader hook to $myvimrc_path" 148 | fi 149 | } 150 | 151 | install_or_update_bundles() { 152 | msg "Calling Vundle's :PluginInstall!" 153 | echo | vim -u "$loader_file_path" +PluginInstall! +qall - || 154 | die "Error: unable to start vim" 155 | } 156 | 157 | msg() { 158 | printf '%s\n' "$*" 159 | } 160 | 161 | die() { 162 | printf '%s\n' "$*" 163 | exit 1 164 | } 165 | 166 | resolve_symlinks() { 167 | _resolve_symlinks "$1" 168 | } 169 | 170 | _resolve_symlinks() { 171 | _assert_no_path_cycles "$@" || return 172 | 173 | local dir_context path 174 | path=$(readlink -- "$1") 175 | if [ $? -eq 0 ]; then 176 | dir_context=$(dirname -- "$1") 177 | _resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@" 178 | else 179 | printf '%s\n' "$1" 180 | fi 181 | } 182 | 183 | _prepend_dir_context_if_necessary() { 184 | if [ "$1" = . ]; then 185 | printf '%s\n' "$2" 186 | else 187 | _prepend_path_if_relative "$1" "$2" 188 | fi 189 | } 190 | 191 | _prepend_path_if_relative() { 192 | case "$2" in 193 | /* ) printf '%s\n' "$2" ;; 194 | * ) printf '%s\n' "$1/$2" ;; 195 | esac 196 | } 197 | 198 | _assert_no_path_cycles() { 199 | local target path 200 | 201 | target=$1 202 | shift 203 | 204 | for path in "$@"; do 205 | if [ "$path" = "$target" ]; then 206 | return 1 207 | fi 208 | done 209 | } 210 | 211 | prepend_line() { 212 | local tempfile=$(make_tempfile) 213 | touch "$2" 214 | printf '%s\n' "$1" | cat - "$2" >"$tempfile" && mv "$tempfile" "$2" 215 | } 216 | 217 | make_tempfile() { 218 | mktemp "${TMPDIR:-/tmp}/dwiw2015.XXXXX" 219 | } 220 | 221 | main "$@" 222 | -------------------------------------------------------------------------------- /plugin/dwiw2015.vim: -------------------------------------------------------------------------------- 1 | " dwiw2015.vim -- sensible defaults for a modern text editor 2 | 3 | " Maintainer: Michael Kropat 4 | 5 | " Run-once guard 6 | if exists('g:loaded_dwiw2015') || &compatible 7 | finish 8 | else 9 | let g:loaded_dwiw2015 = 1 10 | endif 11 | 12 | " Group script autocmds so they can be identified with `:autocmd dwiw` 13 | augroup dwiw 14 | autocmd! 15 | 16 | if has('win32') 17 | let s:vimfiles = $HOME . '/vimfiles' 18 | else 19 | let s:vimfiles = $HOME . '/.vim' 20 | endif 21 | 22 | " ###### Settings ###### 23 | 24 | " backup -- when overwriting a file, take a backup copy 25 | set backup 26 | let &backupdir = s:vimfiles . '/tmp/backup//' 27 | if !isdirectory(expand(&backupdir)) 28 | call mkdir(expand(&backupdir), "p") 29 | endif 30 | 31 | " cursorline -- highlight the entire line the cursor is on 32 | set cursorline 33 | 34 | " guioptions -- disable GUI elements to prevent unintended window resizing 35 | if has("win32") && has("gui_running") 36 | set guioptions-=e 37 | endif 38 | 39 | " hidden -- let user switch away from (hide) buffers with unsaved changes 40 | set hidden 41 | 42 | " hlsearch -- highlight search term matches 43 | set hlsearch 44 | 45 | " ignorecase -- case-insensitive searching, but... 46 | " smartcase -- become case-sensitive when search term contains upper case 47 | set ignorecase smartcase 48 | 49 | " lazyredraw -- don't update screen interactively when running macros etc. 50 | set lazyredraw 51 | 52 | " linebreak -- wrap long lines at word breaks instead of fixed length 53 | set linebreak 54 | 55 | " listchars -- characters for rendering tab character etc. with :list 56 | if !has('win32') && (&termencoding ==# 'utf-8' || &encoding ==# 'utf-8') 57 | let &listchars = "tab:\u21e5 ,trail:\u2423,extends:\u21c9,precedes:\u21c7,nbsp:\u00b7" 58 | endif 59 | 60 | " modeline -- whether to run lines like '# vim: noai:ts=4:sw=4' in any file 61 | " Disabled, as it tends to be a source of security vulnerabilities 62 | " Look at the 'securemodelines' plugin for a better alternative 63 | set nomodeline 64 | 65 | " number -- show line numbers at the beginning of each line 66 | " Only enabled in GUI mode, where it is less obtrusive 67 | if has("gui_running") == 1 68 | set number 69 | endif 70 | 71 | " showmatch -- flash matching pair when typing a closing paren, bracket etc. 72 | " matchtime -- tenths of a second to display a showmatch (default: 5) 73 | set showmatch matchtime=3 74 | 75 | " showmode -- outputs the "-- INSERT --", etc. messages on the last line 76 | " Disabled, since vim-airline displays the mode 77 | set noshowmode 78 | 79 | " splitbelow -- open horizontal splits below the current window 80 | set splitbelow 81 | 82 | " splitright -- open vertical splits to the right of the current window 83 | set splitright 84 | 85 | " swapfile -- keep a swap file to help recover from file corruption 86 | " Disabled since it's so rare and any important file is version controlled 87 | " (Avoids annoying "recover swap file??" questions) 88 | set noswapfile 89 | let &directory = s:vimfiles . '/tmp/swap//' 90 | if !isdirectory(expand(&directory)) 91 | call mkdir(expand(&directory), "p") 92 | endif 93 | 94 | " undofile -- keep a file to persist undo history after file is closed 95 | if has("persistent_undo") == 1 96 | set undofile 97 | let &undodir = s:vimfiles . '/tmp/undo//' 98 | if !isdirectory(expand(&undodir)) 99 | call mkdir(expand(&undodir), "p") 100 | endif 101 | endif 102 | 103 | " visualbell -- instead of audible bell, output terminal code 't_vb' 104 | " Disable annoying bell by setting 't_vb' to '' 105 | set visualbell t_vb= 106 | " When GUI starts, 't_vb' is reset, so set it again to '' 107 | autocmd GUIEnter * set t_vb= 108 | 109 | " wildmode -- behavior of command-line tab completion 110 | " = list -- print possible matches 111 | " = longest -- complete until amibguous (same as bash/readline) 112 | set wildmode=list:longest 113 | 114 | " Settings inherited from ** vim-sensible ** [3]: 115 | " 116 | " * autoindent 117 | " * autoread 118 | " * backspace 119 | " * complete 120 | " * display 121 | " * encoding 122 | " * fileformats 123 | " * history 124 | " * incsearch 125 | " * laststatus 126 | " * listchars 127 | " * nrformats 128 | " * ruler 129 | " * scrolloff 130 | " * shell 131 | " * shiftround 132 | " * showcmd 133 | " * sidescrolloff 134 | " * sidescrolloff 135 | " * smarttab 136 | " * tabpagemax 137 | " * ttimeout 138 | " * ttimeoutlen100 139 | " * viminfo 140 | " * wildmenu 141 | 142 | " ack.vim: prefer ag over ack (if available) 143 | if !exists('g:ackprg') && executable('ag') 144 | let g:ackprg = 'ag --vimgrep' 145 | endif 146 | 147 | 148 | " ###### Key Bindings ###### 149 | 150 | " Load Windows keybindings on all platforms except OS-X GUI 151 | " Maps the usual suspects: Ctrl-{A,C,S,V,X,Y,Z} 152 | if has("gui_macvim") == 0 153 | source $VIMRUNTIME/mswin.vim 154 | 155 | " bad, mswin.vim! bad! 156 | silent! nunmap 157 | 158 | " Let arrow keys work with visual select 159 | set keymodel-=stopsel 160 | endif 161 | 162 | " C-V -- Gvim: paste [All Modes] 163 | " Terminal: enter Visual Block mode [Normal / Visual Mode] 164 | " Terminal: insert literal character [Insert Mode] 165 | " C-Q -- Gvim: enter Visual Block mode [Normal / Visual Mode] 166 | " Gvim: insert literal character [Insert Mode] 167 | if has("gui_running") == 0 && ! empty(maparg('')) 168 | unmap 169 | iunmap 170 | endif 171 | 172 | " C-Y -- scroll window upwards [Normal / Visual Mode] 173 | if ! empty(maparg('')) 174 | unmap 175 | endif 176 | 177 | " C-Z -- Gvim: undo [All Modes] 178 | " Terminal: suspend vim and return to shell [Normal / Visual Mode] 179 | if has("gui_running") == 0 && ! empty(maparg('')) 180 | unmap 181 | " Technically still performs undo in Terminal during insert mode 182 | endif 183 | 184 | " C-/ -- Terminal: toggle whether line is commented [Normal / Visual Mode] 185 | " (Only works in terminals where is equivalent to ) 186 | noremap :Commentary 187 | 188 | " & -- repeate last `:s` substitute (preserves flags) 189 | nnoremap & :&& 190 | xnoremap & :&& 191 | 192 | " Y -- yank to end of line; see `:help Y` [Normal Mode] 193 | nnoremap Y y$ 194 | 195 | " Enter key -- insert a new line above the current [Normal Mode] 196 | if empty(maparg('', 'n')) 197 | nnoremap Oj 198 | " ...but not in the Command-line window (solution by Ingo Karkat [2]) 199 | autocmd CmdwinEnter * nnoremap 200 | " ...nor in the Quickfix window 201 | autocmd BufReadPost * if &buftype ==# 'quickfix' | nnoremap | endif 202 | endif 203 | 204 | " Ctrl-Tab -- Gvim: switch to next tab [Normal Mode] 205 | nnoremap :tabnext 206 | 207 | " Ctrl-Shift-Tab -- Gvim: switch to previous tab [Normal Mode] 208 | nnoremap :tabprev 209 | 210 | " Q{motion} -- format specified lines [Normal / Visual Mode] 211 | noremap Q gq 212 | 213 | " j -- move down one line on the screen [Normal / Visual Mode] 214 | nnoremap j gj 215 | vnoremap j gj 216 | 217 | " gj -- move down one line in the file [Normal / Visual Mode] 218 | nnoremap gj j 219 | vnoremap gj j 220 | 221 | " k -- move up one line on the screen [Normal / Visual Mode] 222 | nnoremap k gk 223 | vnoremap k gk 224 | 225 | " gk -- move up one line in the file [Normal / Visual Mode] 226 | nnoremap gk k 227 | vnoremap gk k 228 | 229 | " > -- shift selection rightwards (preserve selection) [Visual Mode] 230 | vnoremap > >gv 231 | 232 | " < -- shift selection leftwards (preserve selection) [Visual Mode] 233 | vnoremap < =DwiwITab() 237 | inoremap 238 | 239 | " Taken from Gary Bernhardt's vimrc [1] 240 | function! DwiwITab() 241 | let col = col('.') - 1 242 | if !col || getline('.')[col - 1] !~ '\k' 243 | return "\" 244 | else 245 | return "\" 246 | endif 247 | endfunction 248 | 249 | 250 | augroup END 251 | 252 | " ##### References ##### 253 | " 254 | " [1] https://github.com/garybernhardt/dotfiles/blob/master/.vimrc 255 | " [2] http://stackoverflow.com/a/11983449/27581 256 | " [3] https://github.com/tpope/vim-sensible/blob/master/plugin/sensible.vim 257 | -------------------------------------------------------------------------------- /bootstrap.ps1: -------------------------------------------------------------------------------- 1 | # bootstrap.ps1 -- install the dwiw2015 Vim distribution 2 | 3 | # See the Github page (https://github.com/mkropat/vim-dwiw2015) for details 4 | 5 | # It should be safe to run -- even on an existing Vim set up. Re-running the 6 | # `bootstrap.ps1` script is safe — it simply resumes the installation and 7 | # checks for updates on any plug-ins already installed. 8 | 9 | 10 | param ( 11 | [switch]$Uninstall = $false 12 | ) 13 | 14 | if (Test-Path Env:Home) { 15 | $home_path = $Env:Home 16 | } else { 17 | $home_path = $Home 18 | } 19 | 20 | $myvimrc_path = Join-Path $home_path _vimrc 21 | $myvimfiles_path = Join-Path $home_path vimfiles 22 | $myvimfiles_tlde = '~/vimfiles' 23 | $loader_file_path = Join-Path $myvimfiles_path dwiw-loader.vim 24 | $loader_file_tlde = "$myvimfiles_tlde/dwiw-loader.vim" 25 | $bundles_file_path = Join-Path $myvimfiles_path bundles.vim 26 | $bundles_file_tlde = "$myvimfiles_tlde/bundles.vim" 27 | $bundle_path = Join-Path $myvimfiles_path bundle 28 | $bundle_tlde = "$myvimfiles_tlde/bundle" 29 | $vundle_path = Join-Path $bundle_path vundle 30 | $vundle_tlde = "$bundle_tlde/vundle" 31 | 32 | function main { 33 | if ($Uninstall) { 34 | Uninstall-Dwiw 35 | } else { 36 | Install-Dwiw 37 | } 38 | } 39 | 40 | function Install-Dwiw { 41 | Ensure-GitOnPath 42 | 43 | EnsureInstalled-Vundle 44 | 45 | # Create `~\vimfiles\dwiw-loader.vim` script to load Vundle and then call 46 | # `bundles.vim`. Do not modify the loader file. 47 | EnsureCreated-LoaderFile 48 | 49 | # Create `~\vimfiles\bundles.vim` script, which contains a list of Vundle 50 | # plug-ins. Feel free to make local modifications to this file. 51 | EnsurePopulated-BundlesFile 52 | 53 | # Prepand a one-line hook in `~\_vimrc` to call `dwiw-loader.vim`. 54 | EnsureAdded-VimrcHook 55 | 56 | InstallOrUpdate-Plugins 57 | } 58 | 59 | function Uninstall-Dwiw { 60 | Remove-VimrcHook 61 | Remove-Item $loader_file_path -ErrorAction Silent 62 | 63 | Remove-DwiwBundle 64 | $plugin_path = Join-Path $bundle_path 'vim-dwiw2015' 65 | Remove-Item -Recurse $plugin_path -Force -ErrorAction Silent 66 | } 67 | 68 | function Ensure-GitOnPath { 69 | if (Get-Command git -ErrorAction SilentlyContinue) { 70 | return 71 | } 72 | 73 | $gitPath = Get-GitPathFromRegistry 74 | if (-not $gitPath) { 75 | throw 'Unable to locate git.exe' 76 | } 77 | 78 | Add-EnvPath -Container User (Split-Path $gitPath) 79 | } 80 | 81 | function EnsureInstalled-Vundle { 82 | if (Test-Path -LiteralPath (Join-Path $vundle_path '.git') -PathType Container) { 83 | return 84 | } 85 | 86 | Write-Output "Installing Vundle into $vundle_path" 87 | 88 | New-Item -Path $bundle_path -Type Directory -Force | Out-Null 89 | Push-Location $bundle_path 90 | try { 91 | & git clone --quiet https://github.com/gmarik/vundle.git vundle 92 | } finally { 93 | Pop-Location 94 | } 95 | } 96 | 97 | $loader_version = '1.1' 98 | $dwiw_loader_script = @" 99 | " dwiw-loader.vim - Load Vundle and tell it about bundles 100 | " Version: $loader_version 101 | set nocompatible 102 | filetype off 103 | set rtp+=$vundle_tlde/ 104 | call vundle#rc("$bundle_tlde") 105 | source $bundles_file_tlde 106 | filetype plugin indent on 107 | runtime! plugin/sensible.vim 108 | runtime! plugin/dwiw2015.vim 109 | "@ 110 | 111 | function EnsureCreated-LoaderFile { 112 | if (! (Test-Path -LiteralPath $loader_file_path)) { 113 | Write-Output "Creating loader script at $loader_file_path" 114 | $dwiw_loader_script | Out-FileVimSafe $loader_file_path 115 | } elseif ((Get-ScriptVersion $loader_file_path) -ne '1.1') { 116 | Write-Output "Updating loader script at $loader_file_path to version $loader_version" 117 | $dwiw_loader_script | Out-FileVimSafe $loader_file_path 118 | } 119 | } 120 | 121 | function EnsurePopulated-BundlesFile { 122 | try { 123 | $existing_lines = Get-Content $bundles_file_path -ErrorAction Stop 124 | } catch { 125 | Write-Output "Creating bundles file at $bundles_file_path" 126 | $existing_lines = @() 127 | } 128 | 129 | # Migrate from old Vundle interface to new interface 130 | $existing_lines = $existing_lines | foreach { $_ -replace '^Bundle','Plugin' } 131 | 132 | $bundles = 133 | 'gmarik/vundle', 134 | 'tpope/vim-sensible', 135 | 'mkropat/vim-dwiw2015', 136 | 'bling/vim-airline', 137 | 'ctrlpvim/ctrlp.vim', 138 | 'mileszs/ack.vim', 139 | 'tpope/vim-commentary', 140 | 'tpope/vim-sleuth' 141 | $lines_to_add = $bundles | %{ "Plugin '$_'" } 142 | $lines = $existing_lines + $lines_to_add | Select-Object -Unique 143 | $lines | Out-FileVimSafe $bundles_file_path 144 | } 145 | 146 | function Remove-DwiwBundle { 147 | try { 148 | Get-Content $bundles_file_path -ErrorAction Stop | 149 | Where-Object { $_ -notmatch "^Plugin 'mkropat/vim-dwiw2015'$" } | 150 | Out-FileVimSafe $bundles_file_path 151 | } catch { 152 | # Oh well 153 | } 154 | } 155 | 156 | function EnsureAdded-VimrcHook { 157 | try { 158 | $lines = Get-Content $myvimrc_path -ErrorAction Stop 159 | } catch { 160 | Write-Output "Adding hook to $myvimrc_path" 161 | $lines = @() 162 | } 163 | if (! ($lines | Select-String -Pattern "source $loader_file_tlde")) { 164 | $lines = ,"source $loader_file_tlde" + $lines 165 | $lines | Out-FileVimSafe $myvimrc_path 166 | } 167 | } 168 | 169 | function Remove-VimrcHook { 170 | try { 171 | Get-Content $myvimrc_path -ErrorAction Stop | 172 | Where-Object { $_ -notmatch "^source $loader_file_tlde$" } | 173 | Out-FileVimSafe $myvimrc_path 174 | } catch { 175 | # Oh well 176 | } 177 | } 178 | 179 | function InstallOrUpdate-Plugins { 180 | Write-Output "Calling Vundle's :PluginInstall!" 181 | $gvim_args = @( "-u", "`"$loader_file_path`"", "+PluginInstall!", "+qall" ) 182 | try { 183 | # Try to find gvim.exe in $Env:Path or in App Paths 184 | Start-Process gvim -ArgumentList $gvim_args 185 | } catch { 186 | try { 187 | # Failing that, try to locate it manually 188 | Start-Process (Get-GvimExePath) -ArgumentList $gvim_args 189 | } catch { 190 | throw "Unable to locate gvim.exe" 191 | } 192 | } 193 | } 194 | 195 | function Get-GvimExePath { 196 | # Find Vim directory from the *Cream* Vim Installer's UninstallString 197 | $is64bit = [IntPtr]::size -eq 8 198 | if ($is64bit) { 199 | $hklmSoftwareWindows = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion' 200 | } else { 201 | $hklmSoftwareWindows = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' 202 | } 203 | $uninstallVim = Join-Path $hklmSoftwareWindows 'Uninstall\Vim' 204 | $uninstallString = (Get-ItemProperty $uninstallVim UninstallString).UninstallString 205 | $installDir = Split-Path -Parent $uninstallString 206 | return Join-Path $installDir 'gvim.exe' 207 | } 208 | 209 | function Get-ScriptVersion($script_path) { 210 | return Get-Content $script_path -ErrorAction SilentlyContinue | 211 | Select-String '^" Version: (.*)' | 212 | select -First 1 -ExpandProperty Matches | 213 | select -ExpandProperty Groups | 214 | select -Index 1 | 215 | select -ExpandProperty Value 216 | } 217 | 218 | function Out-FileVimSafe { 219 | param ( 220 | [string]$FilePath 221 | ) 222 | 223 | # Vim chokes on BOM outputted by Out-File 224 | [System.IO.File]::WriteAllLines($FilePath, @($input)) 225 | } 226 | 227 | function Get-GitPathFromRegistry { 228 | $gitDir = Get-ItemProperty HKLM:\SOFTWARE\GitForWindows InstallPath -ErrorAction SilentlyContinue | 229 | select -ExpandProperty InstallPath -ErrorAction SilentlyContinue 230 | if ($gitDir) { 231 | @('bin', 'usr\bin') | 232 | foreach { Join-Path (Join-Path $gitDir $_) 'git.exe' } | 233 | where { Test-Path $_ } | 234 | select -First 1 235 | } 236 | } 237 | 238 | function Add-EnvPath { 239 | param( 240 | [Parameter(Mandatory=$true)] 241 | [string] $Path, 242 | 243 | [ValidateSet('Machine', 'User', 'Session')] 244 | [string] $Container = 'Session' 245 | ) 246 | 247 | if ($Container -ne 'Session') { 248 | $containerMapping = @{ 249 | Machine = [EnvironmentVariableTarget]::Machine 250 | User = [EnvironmentVariableTarget]::User 251 | } 252 | $containerType = $containerMapping[$Container] 253 | 254 | $persistedPaths = [Environment]::GetEnvironmentVariable('Path', $containerType) -split ';' 255 | if ($persistedPaths -notcontains $Path) { 256 | $persistedPaths = $persistedPaths + $Path | where { $_ } 257 | [Environment]::SetEnvironmentVariable('Path', $persistedPaths -join ';', $containerType) 258 | } 259 | } 260 | 261 | $envPaths = $env:Path -split ';' 262 | if ($envPaths -notcontains $Path) { 263 | $envPaths = $envPaths + $Path | where { $_ } 264 | $env:Path = $envPaths -join ';' 265 | } 266 | } 267 | 268 | main 269 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dwiw2015.vim — Vim Do What I Want 2 | 3 | *Sensible Defaults For A Modern Text Editor* 4 | 5 | __2017/4/23 Update:__ Now that [Vim 8 is out](https://github.com/vim/vim/blob/master/runtime/doc/version8.txt), a number of improvements that this distribution makes no longer make sense (thanks to better defaults and built-in plugin suport). It is unlikely future development will go into dwiw2015.vim, outside of re-working it into a brand new distribution built for Vim 8. 6 | 7 | Building on top of [Tim Pope's 8 | sensible.vim](https://github.com/tpope/vim-sensible/), **vim-dwiw is a minimal 9 | Vim distribution** that sets up Vim with the behavior and features that you 10 | would expect from a modern text editor. 11 | 12 | Benefits at a glance: 13 | 14 | - One-step install for Windows, Linux, and OS X 15 | - No cruft in your `.vimrc`, since default settings are cleanly segregated into a plug-in 16 | - Modern plug-in management with [Vundle](https://github.com/gmarik/Vundle.vim) 17 | - Includes a __small__ [curated set of plug-ins](#modern-features) to provide modern text editor functionality 18 | - Optimized for both Terminal and GUI Vim 19 | 20 | Vim-dwiw is well suited for new Vim users. It smoothes out the roughest of 21 | edges of Vim (the stuff that no longer makes sense today), but in a way that 22 | doesn't try to change or go far beyond the core Vim behavior. 23 | 24 | And for experienced users, vim-dwiw cuts out the boilerplate code that you and 25 | everyone else puts in their `.vimrc`, making it that much easier to get Vim 26 | configured on a new machine. 27 | 28 | ## Installation 29 | 30 | ### Linux, OS X, and Friends 31 | 32 | One command will get you going: 33 | 34 | curl -sS https://raw.githubusercontent.com/mkropat/vim-dwiw2015/master/bootstrap.sh | sh 35 | 36 | It should be safe to run — even on an existing Vim set up. See the [bootstrap 37 | script source](bootstrap.sh) for details. 38 | 39 | ### Windows 40 | 41 | Assuming you have [Chocolatey](http://chocolatey.org/) installed, open a 42 | command prompt and run: 43 | 44 | cinst vim-dwiw2015 45 | 46 | It should be safe to run — even on an existing Vim set up. See the [bootstrap 47 | script source](bootstrap.ps1) for details. 48 | 49 | Alternatively, you can download the [bootstrap script](bootstrap.ps1) and run 50 | it manually from the PowerShell console: 51 | 52 | & .\bootstrap.ps1 53 | 54 | ### Plug-in Only 55 | 56 | If you already have Vundle set up and the plug-ins you want installed, you can 57 | include just the **dwiw2015.vim** plug-in by adding the following lines to your 58 | `.vimrc`: 59 | 60 | Plugin 'tpope/vim-sensible' 61 | Plugin 'mkropat/vim-dwiw2015' 62 | 63 | (dwiw2015.vim pairs best with vim-sensible) 64 | 65 | And then run the following from Vim: 66 | 67 | :PluginInstall 68 | 69 | ## Updating 70 | 71 | If you've already installed vim-dwiw, you can update the **dwiw2015.vim** 72 | plug-in and all other installed plugins to the latest version by running the 73 | following from Vim: 74 | 75 | :PluginUpdate 76 | 77 | ## Default Settings 78 | 79 | The authoritative source for the provided default settings is the 80 | (well-documented) [source file itself](plugin/dwiw2015.vim). 81 | 82 | ### New Key Shortcuts 83 | 84 | Vim-dwiw adds in the most ubiquitous editor shortcuts, and makes some 85 | old key mappings act a little more modern. 86 | 87 | #### All Modes 88 | 89 | Shortcut | Description 90 | -------------------|------------------------------- 91 | Ctrl-A | select all 92 | Ctrl-S | save 93 | Ctrl-Z | undo (GUI only) 94 | 95 | #### Normal / Visual Mode 96 | 97 | Shortcut | Description 98 | -----------------------|------------------------------- 99 | Ctrl-Q | enter Visual Block mode 100 | Ctrl-V | paste from clipboard (GUI only) 101 | Ctrl-/ | toggles commenting of selected line(s) (Terminal only; not all terminals supported) 102 | Q`{motion}` | format specified lines (like `gq`) 103 | gQ | enter Ex mode (since `Q` is re-mapped) 104 | j | move down one line on the screen 105 | gj | move down one line in the file 106 | k | move up one line on the screen 107 | gk | move up one line in the file 108 | 109 | #### Normal Mode Only 110 | 111 | Shortcut | Description 112 | --------------------------|------------------------------- 113 | & | repeat last `:s` substitue (preserves flags) 114 | Y | yank to end of line (to be consistent with C and D) 115 | Enter | insert blank line above current 116 | Ctrl-Tab | switch to next tab (GUI only) 117 | Ctrl-Shift-Tab | switch to previous tab (GUI only) 118 | Ctrl-L | clear search term highlighting 119 | 120 | #### Visual Mode Only 121 | 122 | Shortcut | Description 123 | -------------------|------------------------------- 124 | Ctrl-C | copy selection to clipboard (GUI only) 125 | Ctrl-X | cut selection to clipboard (GUI only) 126 | 127 | #### Insert Mode 128 | 129 | Shortcut | Description 130 | ---------------------|------------------------------- 131 | Tab | indent at beginning of line, otherwise autocomplete 132 | Shift-Tab | select previous autocompletion 133 | Ctrl-Q | insert literal character 134 | Ctrl-V | paste from clipboard (GUI only) 135 | 136 | ### Overriding the Defaults 137 | 138 | Add your custom settings to `.vimrc` **after** the hook line `source … 139 | dwiw-loader.vim`. The `dwiw-loader.vim` script pre-loads both the 140 | `dwiw2015.vim` and `sensible.vim` plugins, allowing you to set custom overrides 141 | in your `.vimrc`. 142 | 143 | ## Modern Features 144 | 145 | Vim-dwiw ships with a number of plug-ins out-of-the-box: 146 | 147 | - [ag.vim](https://github.com/rking/ag.vim) — like `grep`, but better 148 | - [ctrlp.vim](https://github.com/kien/ctrlp.vim) — fuzzy file, buffer, mru, tag, etc finder 149 | - [vim-airline](https://github.com/bling/vim-airline) — lean & mean status/tabline for Vim that's light as air 150 | - [vim-commentary](https://github.com/tpope/vim-commentary) — comment and un-comment lines easily 151 | - [vim-sensible](https://github.com/tpope/vim-sensible) — defaults everyone can agree on 152 | - [vim-sleuth](https://github.com/tpope/vim-sleuth) — heuristically set buffer options 153 | - [Vundle](https://github.com/gmarik/Vundle.vim) — the plug-in manager for Vim 154 | 155 | ### Plug-in Management 156 | 157 | Install packages straight from Vim at any time with 158 | [Vundle](https://github.com/gmarik/Vundle.vim). For example, to install Tim 159 | Pope's fantastic Git wrapper, available on Github at 160 | [tpope/vim-fugitive](https://github.com/tpope/vim-fugitive), simply add the 161 | following line to your `.vimrc`: 162 | 163 | Plugin 'tpope/vim-fugitive' 164 | 165 | Then run `:PluginInstall`. 166 | 167 | To update all installed plugins to the latest version, run `:PluginUpdate`. 168 | 169 | ### Fuzzy-Filename Open 170 | 171 | ![Screenshot](http://i.imgur.com/ElV0Tjr.png) 172 | 173 | Vim's built-in file opener and swtiching (see `:help :e` and `:help :b`) works 174 | fine, but for truly fast file-switching you need a fuzzy-file opener, like the 175 | [ctrlp plug-in](http://kien.github.io/ctrlp.vim/). Pressing Ctrl-P 176 | in normal mode activates the the plug-in. Once activated, start typing any 177 | part of the filename you're interested (`partial/paths` work too) and press 178 | Enter to open the file. 179 | 180 | ### Find In Files 181 | 182 | ![Screenshot](http://i.imgur.com/4N8XtLR.png) 183 | 184 | Vim already provides an interface to the `grep` command with `:grep`, however 185 | the `grep` command is less than ideal for searching most directories, because 186 | it automatically searches inside lots of irrelevant filetypes (like compiled 187 | files, version control internals, etc.). 188 | 189 | A better alternative is [The Silver 190 | Searcher](http://geoff.greer.fm/2011/12/27/the-silver-searcher-better-than-ack/) 191 | a.k.a. `ag`. Using the [ack.vim plug-in](https://github.com/mileszs/ack.vim) 192 | (configured for `ag`), you can search straight from Vim with the command `:Ack 193 | `. 194 | 195 | Note: before `ag.vim` can be used, the The Silver Searcher must be installed. 196 | Fortunately, packages exist for all the major platforms (called perhaps 197 | `silversearcher-ag` or `the_silver_searcher`) and it's installed automatically 198 | for you on Windows by Chocolatey! 199 | 200 | ### Informative Statusline 201 | 202 | ![Screenshot](http://i.imgur.com/3NcgspK.png) 203 | 204 | Vim-dwiw includes the [vim-airline 205 | plug-in](https://github.com/bling/vim-airline), which packs a whole lot of 206 | information into your status while looking great at the same time. 207 | 208 | ### Toggle Line Commenting With a Single Keypress 209 | 210 | (Terminal Only) Press Ctrl-/ to comment out the current line (or 211 | un-comment it, if it's currently commented out). Select multiple lines in 212 | Visual mode and press Ctrl-/ to comment them all out. 213 | 214 | (All Versions) Or more powerfully, use Vim motions with gc to 215 | comment out any sized block of code: 216 | 217 | - gcap — comment out the current paragraph 218 | - gcG — comment out the rest of the file 219 | - etc. 220 | 221 | ### Auto-Detection of Indent Settings 222 | 223 | We all have our preferred idea of how far to indent and when to use tabs vs 224 | spaces, but when editing a file created by someone else, the important thing is 225 | *to stay consistent with their indent settings*. The [sleuth.vim 226 | plug-in](https://github.com/tpope/vim-sleuth) inspects newly opened files and 227 | sets the relevant settings (`shiftwidth` and `expandtab`) automatically. 228 | 229 | ## Troubleshooting 230 | 231 | #### Slow Scrolling 232 | 233 | If you experience slow scrolling in `:list` mode in a file with long lines, the 234 | issue may be a result of [the font in use misisng certain 235 | characters](https://code.google.com/p/vim/issues/detail?id=210). As a 236 | workaround, you can set the following in your `.vimrc` to display ascii 237 | characters (which are present in any font): 238 | 239 | set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+ 240 | 241 | ## Inspiration 242 | 243 | I may be proficient at editing with Vim, but I'm a novice when it comes to Vim 244 | customization. Without reading other people's `.vimrc` files and plug-in 245 | source code, I'd have gotten nowhere. Particular shout-outs go to: 246 | 247 | * Tim Pope's [vim-sensible](https://github.com/tpope/vim-sensible) and [vimrc](https://github.com/tpope/tpope/blob/master/.vimrc) 248 | * Gary Bernhardt's [vimrc](https://github.com/garybernhardt/dotfiles/blob/master/.vimrc) 249 | * Steve Losh's [Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com/), [Vim blog post](http://stevelosh.com/blog/2010/09/coming-home-to-vim/) and [vimrc](https://bitbucket.org/sjl/dotfiles/src/tip/vim/vimrc) 250 | * Bailey Ling's [vimrc](https://github.com/bling/dotvim/blob/master/vimrc) 251 | * Steve Francia's [everything and the kitchen sink Vim distribution](http://vim.spf13.com/) 252 | 253 | ## License 254 | 255 | Copyright © Michael Kropat. Distributed under the same terms as Vim itself. 256 | See `:help license`. 257 | --------------------------------------------------------------------------------