.vimrc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. " set background=dark
  2. colorscheme sunburst
  3. " let g:solarized_termtrans=1
  4. " Make Vim more useful
  5. set nocompatible
  6. " Use the OS clipboard by default (on versions compiled with `+clipboard`)
  7. set clipboard=unnamed
  8. " Enhance command-line completion
  9. set wildmenu
  10. " Allow cursor keys in insert mode
  11. set esckeys
  12. " Allow backspace in insert mode
  13. set backspace=indent,eol,start
  14. " Optimize for fast terminal connections
  15. set ttyfast
  16. " Add the g flag to search/replace by default
  17. set gdefault
  18. " Use UTF-8 without BOM
  19. set encoding=utf-8 nobomb
  20. " Change mapleader
  21. let mapleader=","
  22. " Don’t add empty newlines at the end of files
  23. set binary
  24. set noeol
  25. " Centralize backups, swapfiles and undo history
  26. set backupdir=~/.vim/backups
  27. set directory=~/.vim/swaps
  28. if exists("&undodir")
  29. set undodir=~/.vim/undo
  30. endif
  31. " Don’t create backups when editing files in certain directories
  32. set backupskip=/tmp/*,/private/tmp/*
  33. " Respect modeline in files
  34. set modeline
  35. set modelines=4
  36. " Enable per-directory .vimrc files and disable unsafe commands in them
  37. set exrc
  38. set secure
  39. " Enable line numbers
  40. set number
  41. " Enable syntax highlighting
  42. syntax on
  43. " Highlight current line
  44. set cursorline
  45. " Make tabs as wide as two spaces
  46. set tabstop=2
  47. " Show “invisible” characters
  48. set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
  49. set list
  50. " Highlight searches
  51. set hlsearch
  52. " Ignore case of searches
  53. set ignorecase
  54. " Highlight dynamically as pattern is typed
  55. set incsearch
  56. " Always show status line
  57. set laststatus=2
  58. " Enable mouse in all modes
  59. set mouse=a
  60. " Disable error bells
  61. set noerrorbells
  62. " Don’t reset cursor to start of line when moving around.
  63. set nostartofline
  64. " Show the cursor position
  65. set ruler
  66. " Don’t show the intro message when starting Vim
  67. set shortmess=atI
  68. " Show the current mode
  69. set showmode
  70. " Show the filename in the window titlebar
  71. set title
  72. " Show the (partial) command as it’s being typed
  73. set showcmd
  74. " Use relative line numbers
  75. if exists("&relativenumber")
  76. set relativenumber
  77. au BufReadPost * set relativenumber
  78. endif
  79. " Start scrolling three lines before the horizontal window border
  80. set scrolloff=3
  81. " Strip trailing whitespace (,ss)
  82. function! StripWhitespace()
  83. let save_cursor = getpos(".")
  84. let old_query = getreg('/')
  85. :%s/\s\+$//e
  86. call setpos('.', save_cursor)
  87. call setreg('/', old_query)
  88. endfunction
  89. noremap <leader>ss :call StripWhitespace()<CR>
  90. " Save a file as root (,W)
  91. noremap <leader>W :w !sudo tee % > /dev/null<CR>
  92. " Automatic commands
  93. if has("autocmd")
  94. " Enable file type detection
  95. filetype on
  96. " Treat .json files as .js
  97. autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript
  98. " Treat .md files as Markdown
  99. autocmd BufNewFile,BufRead *.md setlocal filetype=markdown
  100. endif