├── .gitignore ├── LICENSE ├── README.md └── plugin └── default.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *.un~ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Liu-Cheng Xu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vim-better-default 2 | ================== 3 | 4 | There are some general settings for convenience in almost everyone's `.vimrc` file. Let's shorten your `.vimrc` and make the default vim better. 5 | 6 | ## Features 7 | 8 | - **Out-of-the-box**: address a ton of deficiencies of the default vim configurations that nearly everyone can agree upon. 9 | 10 | - **Mnemonic key bindings**: commands have mnemonic prefixes like ` b` for the buffer commands or ` w` for the window commands. `SPC` key is recommended as the leader key. You could also see the key bindings in [wiki](https://github.com/liuchengxu/vim-better-default/wiki/a-brief-introduction-to-key-bindings). 11 | 12 | If new to Vim, you can install [vim-better-default](https://github.com/liuchengxu/vim-better-default) as a starting point, rather than copying some random vimrc you found. 13 | 14 | If you have been a vimmer for quite a while, please see [default.vim](https://github.com/liuchengxu/vim-better-default/blob/master/plugin/default.vim) directly. In the beginning [vim-better-default](https://github.com/liuchengxu/vim-better-default) is intended for simplifying the tedious `.vimrc` file, so you may also use it to shorten your `.vimrc`. 15 | 16 | ## Installation 17 | 18 | This plugin can be installed with a varity of plugin managers, such as: 19 | 20 | - [Vundle](https://github.com/VundleVim/Vundle.vim) 21 | - Add `Plugin 'liuchengxu/vim-better-default` to .vimrc 22 | - Run `:source $MYVIMRC` and `:PluginInstall` 23 | - [Plug](https://github.com/junegunn/vim-plug) 24 | - Add `Plug 'liuchengxu/vim-better-default` to .vimrc 25 | - Run `:source $MYVIMRC` and `:PlugInstall` 26 | 27 | ## Options 28 | 29 | Option | Description | Default | 30 | :---- | :---- | :----: 31 | `vim_better_default_minimum` | Only add essential funationalities | 0 32 | `vim_better_default_backup_on` | Set backup | 0 33 | `vim_better_default_persistent_undo` | Persistent undo | 0 34 | `vim_better_default_enable_folding` | Enable fold | 1 35 | `vim_better_default_key_mapping` | Whole key (re)mappings | 1 36 | `vim_better_default_basic_key_mapping` | Basic key (re)mappings | 1 37 | `vim_better_default_buffer_key_mapping` | Buffer key mappings | 1 38 | `vim_better_default_file_key_mapping` | File key mappings | 1 39 | `vim_better_default_fold_key_mapping` | Fold key mappings | 1 40 | `vim_better_default_window_key_mapping` | Window key mappings | 1 41 | 42 | 43 | If you set the `vim_better_default_minumum` option, then vim seemingly looks like no difference with the default vim, it only adds some essential funtionalities. 44 | 45 | ```vim 46 | let g:vim_better_default_minimum = 1 47 | ``` 48 | 49 | If you want to exclude key mappings in [vim-better-default](https://github.com/liuchengxu/vim-better-default), just set the value as 0. 50 | 51 | ```vim 52 | let g:vim_better_default_key_mapping = 0 53 | ``` 54 | 55 | For more details, please refer to the [default.vim](https://github.com/liuchengxu/vim-better-default/blob/master/plugin/default.vim). Don't worry. It is extremely simple and just part of your own `.vimrc` file alike. 56 | 57 | You can also fork [vim-better-default](https://github.com/liuchengxu/vim-better-default) and modify `plugin/default.vim` for more customization. 58 | 59 | ## How to override the existing settings? 60 | 61 | `default.vim` normally loads after your `.vimrc`, making it a bit tricky to override. If you want to load it earlier, add the following content to your `.vimrc`, then follow on the settings you want to override. 62 | 63 | For instance, if you don't like relativenumber: 64 | 65 | ```vim 66 | runtime! plugin/default.vim 67 | set norelativenumber 68 | ``` 69 | 70 | ## Contributions 71 | 72 | If you have any ideas or suggestions to improve [vim-better-default](https://github.com/liuchengxu/vim-better-default), please [open an issue](https://github.com/liuchengxu/vim-better-default/issues), or fork it and send a pull request. Your feedback is highly appreciated. 73 | 74 | ## Inspiration 75 | 76 | - [spacemacs](https://github.com/syl20bnr/spacemacs) 77 | - [better-defaults](https://github.com/technomancy/better-defaults) 78 | - [vim-sensible](https://github.com/tpope/vim-sensible) 79 | - [space-vim](https://github.com/liuchengxu/space-vim) 80 | -------------------------------------------------------------------------------- /plugin/default.vim: -------------------------------------------------------------------------------- 1 | " default.vim - Better vim than the default 2 | " Maintainer: Liu-Cheng Xu 3 | " Version: 1.0 4 | " vim: et ts=2 sts=2 sw=2 5 | 6 | scriptencoding utf-8 7 | 8 | if &compatible || exists('g:loaded_vim_better_default') 9 | finish 10 | endif 11 | let g:loaded_vim_better_default = 1 12 | 13 | let s:save_cpo = &cpo 14 | set cpo&vim 15 | 16 | " Neovim has set these as default 17 | if !has('nvim') 18 | 19 | set nocompatible 20 | 21 | syntax on " Syntax highlighting 22 | filetype plugin indent on " Automatically detect file types 23 | set autoindent " Indent at the same level of the previous line 24 | set autoread " Automatically read a file changed outside of vim 25 | set backspace=indent,eol,start " Backspace for dummies 26 | set complete-=i " Exclude files completion 27 | set display=lastline " Show as much as possible of the last line 28 | set encoding=utf-8 " Set default encoding 29 | set history=10000 " Maximum history record 30 | set hlsearch " Highlight search terms 31 | set incsearch " Find as you type search 32 | set laststatus=2 " Always show status line 33 | set mouse=a " Automatically enable mouse usage 34 | set smarttab " Smart tab 35 | set ttyfast " Faster redrawing 36 | set viminfo+=! " Viminfo include ! 37 | set wildmenu " Show list instead of just completing 38 | 39 | set ttymouse=xterm2 40 | 41 | endif 42 | 43 | set shortmess=atOI " No help Uganda information, and overwrite read messages to avoid PRESS ENTER prompts 44 | set ignorecase " Case insensitive search 45 | set smartcase " ... but case sensitive when uc present 46 | set scrolljump=5 " Line to scroll when cursor leaves screen 47 | set scrolloff=3 " Minumum lines to keep above and below cursor 48 | set nowrap " Do not wrap long lines 49 | set shiftwidth=4 " Use indents of 4 spaces 50 | set tabstop=4 " An indentation every four columns 51 | set softtabstop=4 " Let backspace delete indent 52 | set splitright " Puts new vsplit windows to the right of the current 53 | set splitbelow " Puts new split windows to the bottom of the current 54 | set autowrite " Automatically write a file when leaving a modified buffer 55 | set mousehide " Hide the mouse cursor while typing 56 | set hidden " Allow buffer switching without saving 57 | set t_Co=256 " Use 256 colors 58 | set ruler " Show the ruler 59 | set showcmd " Show partial commands in status line and Selected characters/lines in visual mode 60 | set showmode " Show current mode in command-line 61 | set showmatch " Show matching brackets/parentthesis 62 | set matchtime=5 " Show matching time 63 | set report=0 " Always report changed lines 64 | set linespace=0 " No extra spaces between rows 65 | set pumheight=20 " Avoid the pop up menu occupying the whole screen 66 | 67 | if !exists('g:vim_better_default_tabs_as_spaces') || g:vim_better_default_tabs_as_spaces 68 | set expandtab " Tabs are spaces, not tabs 69 | end 70 | 71 | " http://stackoverflow.com/questions/6427650/vim-in-tmux-background-color-changes-when-paging/15095377#15095377 72 | set t_ut= 73 | 74 | set winminheight=0 75 | set wildmode=list:longest,full 76 | 77 | set listchars=tab:→\ ,eol:↵,trail:·,extends:↷,precedes:↶ 78 | 79 | set whichwrap+=<,>,h,l " Allow backspace and cursor keys to cross line boundaries 80 | 81 | if has('+termencoding') 82 | set termencoding=utf-8 83 | endif 84 | set fileencoding=utf-8 85 | set fileencodings=ucs-bom,utf-8,default,gb18030,gbk,gb2312,cp936,latin1 86 | 87 | set wildignore+=*swp,*.class,*.pyc,*.png,*.jpg,*.gif,*.zip 88 | set wildignore+=*/tmp/*,*.o,*.obj,*.so " Unix 89 | set wildignore+=*\\tmp\\*,*.exe " Windows 90 | 91 | " Visual shifting (does not exit Visual mode) 92 | vnoremap < >gv 94 | " Treat long lines as break lines (useful when moving around in them) 95 | nmap j gj 96 | nmap k gk 97 | vmap j gj 98 | vmap k gk 99 | 100 | " :W sudo saves the file 101 | " (useful for handling the permission-denied error) 102 | command! W w !sudo tee % > /dev/null 103 | 104 | " Change cursor shape for iTerm2 on macOS { 105 | " bar in Insert mode 106 | " inside iTerm2 107 | if $TERM_PROGRAM =~# 'iTerm' 108 | let &t_SI = "\]50;CursorShape=1\x7" 109 | let &t_SR = "\]50;CursorShape=2\x7" 110 | let &t_EI = "\]50;CursorShape=0\x7" 111 | endif 112 | 113 | " inside tmux 114 | if exists('$TMUX') && $TERM != 'xterm-kitty' 115 | let &t_SI = "\Ptmux;\\]50;CursorShape=1\x7\\\" 116 | let &t_SR = "\Ptmux;\\]50;CursorShape=2\x7\\\" 117 | let &t_EI = "\Ptmux;\\]50;CursorShape=0\x7\\\" 118 | endif 119 | 120 | " inside neovim 121 | if has('nvim') 122 | let $NVIM_TUI_ENABLE_CURSOR_SHAPE=2 123 | endif 124 | " } 125 | 126 | if get(g:, 'vim_better_default_minimum', 0) 127 | finish 128 | endif 129 | 130 | if get(g:, 'vim_better_default_backup_on', 0) 131 | set backup 132 | else 133 | set nobackup 134 | set noswapfile 135 | set nowritebackup 136 | endif 137 | 138 | if get(g:, 'vim_better_default_enable_folding', 1) 139 | set foldenable 140 | set foldmarker={,} 141 | set foldlevel=0 142 | set foldmethod=marker 143 | " set foldcolumn=3 144 | set foldlevelstart=99 145 | endif 146 | 147 | set background=dark " Assume dark background 148 | set cursorline " Highlight current line 149 | set fileformats=unix,dos,mac " Use Unix as the standard file type 150 | set number " Line numbers on 151 | set relativenumber " Relative numbers on 152 | set fillchars=stl:\ ,stlnc:\ ,fold:\ ,vert:│ 153 | 154 | " Annoying temporary files 155 | set directory=/tmp//,. 156 | set backupdir=/tmp//,. 157 | if v:version >= 703 158 | set undodir=/tmp//,. 159 | endif 160 | 161 | highlight clear SignColumn " SignColumn should match background 162 | " highlight clear LineNr " Current line number row will have same background color in relative mode 163 | 164 | if has('unnamedplus') 165 | set clipboard=unnamedplus,unnamed 166 | else 167 | set clipboard+=unnamed 168 | endif 169 | 170 | if get(g:, 'vim_better_default_persistent_undo', 0) 171 | if has('persistent_undo') 172 | set undofile " Persistent undo 173 | set undolevels=1000 " Maximum number of changes that can be undone 174 | set undoreload=10000 " Maximum number lines to save for undo on a buffer reload 175 | endif 176 | endif 177 | 178 | if has('gui_running') 179 | set guioptions-=r " Hide the right scrollbar 180 | set guioptions-=L " Hide the left scrollbar 181 | set guioptions-=T 182 | set guioptions-=e 183 | set shortmess+=c 184 | " No annoying sound on errors 185 | set noerrorbells 186 | set novisualbell 187 | set visualbell t_vb= 188 | endif 189 | 190 | " Key (re)Mappings { 191 | 192 | if get(g:, 'vim_better_default_key_mapping', 1) 193 | 194 | " Basic { 195 | if get(g:, 'vim_better_default_basic_key_mapping', 1) 196 | " Add for the rhs is Ex-cmd as some GUI app, e.g., gnvim, 197 | " flashes when you use these mappings. 198 | " Quit normal mode 199 | nnoremap q :q 200 | nnoremap Q :qa! 201 | " Move half page faster 202 | nnoremap d 203 | nnoremap u 204 | " Insert mode shortcut 205 | inoremap 206 | inoremap 207 | inoremap 208 | inoremap 209 | inoremap 210 | " Bash like 211 | inoremap 212 | inoremap 213 | inoremap 214 | " Command mode shortcut 215 | cnoremap 216 | cnoremap 217 | cnoremap 218 | cnoremap 219 | cnoremap 220 | cnoremap 221 | cnoremap 222 | cnoremap 223 | " jj | escaping 224 | inoremap jj 225 | cnoremap jj 226 | " Quit visual mode 227 | vnoremap v 228 | " Move to the start of line 229 | nnoremap H ^ 230 | " Move to the end of line 231 | nnoremap L $ 232 | " Redo 233 | nnoremap U 234 | " Quick command mode 235 | nnoremap : 236 | " In the quickfix window, is used to jump to the error under the 237 | " cursor, so undefine the mapping there. 238 | autocmd BufReadPost quickfix nnoremap 239 | " Yank to the end of line 240 | nnoremap Y y$ 241 | " Auto indent pasted text 242 | " nnoremap p p=`] 243 | " Open shell in vim 244 | if has('nvim') || has('terminal') 245 | map ' :terminal 246 | else 247 | map ' :shell 248 | endif 249 | " Search result highlight countermand 250 | nnoremap sc :nohlsearch 251 | " Toggle pastemode 252 | nnoremap tp :setlocal paste! 253 | endif 254 | " } 255 | 256 | " Buffer { 257 | if get(g:, 'vim_better_default_buffer_key_mapping', 1) 258 | nnoremap bp :bprevious 259 | nnoremap bn :bnext 260 | nnoremap bf :bfirst 261 | nnoremap bl :blast 262 | nnoremap bd :bd 263 | nnoremap bk :bw 264 | endif 265 | " } 266 | 267 | " File { 268 | if get(g:, 'vim_better_default_file_key_mapping', 1) 269 | " File save 270 | nnoremap fs :update 271 | endif 272 | " } 273 | 274 | " Fold { 275 | if get(g:, 'vim_better_default_fold_key_mapping', 1) 276 | nnoremap f0 :set foldlevel=0 277 | nnoremap f1 :set foldlevel=1 278 | nnoremap f2 :set foldlevel=2 279 | nnoremap f3 :set foldlevel=3 280 | nnoremap f4 :set foldlevel=4 281 | nnoremap f5 :set foldlevel=5 282 | nnoremap f6 :set foldlevel=6 283 | nnoremap f7 :set foldlevel=7 284 | nnoremap f8 :set foldlevel=8 285 | nnoremap f9 :set foldlevel=9 286 | endif 287 | " } 288 | 289 | " Window { 290 | if get(g:, 'vim_better_default_window_key_mapping', 1) 291 | nnoremap ww w 292 | nnoremap wr r 293 | nnoremap wd c 294 | nnoremap wq q 295 | nnoremap wj j 296 | nnoremap wk k 297 | nnoremap wh h 298 | nnoremap wl l 299 | if has('nvim') || has('terminal') 300 | tnoremap wj j 301 | tnoremap wk k 302 | tnoremap wh h 303 | tnoremap wl l 304 | endif 305 | nnoremap wH 5< 306 | nnoremap wL 5> 307 | nnoremap wJ :resize +5 308 | nnoremap wK :resize -5 309 | nnoremap w= = 310 | nnoremap ws s 311 | nnoremap w- s 312 | nnoremap wv v 313 | nnoremap w\| v 314 | nnoremap w2 v 315 | endif 316 | " } 317 | 318 | endif 319 | 320 | " } 321 | 322 | let &cpo = s:save_cpo 323 | unlet s:save_cpo 324 | --------------------------------------------------------------------------------