forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
155 lines (138 loc) · 3.93 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"" Use Vim settings, rather then Vi settings (much better!).
"" This must be first, because it changes other options as a side effect.
set nocompatible
"" UI settings
set esckeys " Allow cursor keys in insert mode
set wildmenu " Enhance command-line completion
set history=200 " keep X lines of command line history
set ttyfast " Optimize for fast terminal connections
set encoding=utf-8 nobomb " Use UTF-8 without BOM
set noerrorbells
set visualbell
let mapleader="," " Change mapleader
set ruler
set incsearch
set hlsearch "highlight search terms
set number
set ignorecase
set smartcase
"set binary " Don’t add empty newlines at the end of files
"set noeol
set nostartofline " Show the cursor position
set laststatus=2 " Always show status line
set shortmess=atI " Don’t show the intro message when starting vim
set showmode " Show the current mode
set title " Show the filename in the window titlebar
set showcmd " Show the (partial) command as it’s being typed
"set colorcolumn=80
"highlight ColorColumn ctermbg=8
"highlight ColorColumn guibg=Black
highlight OverLength ctermbg=darkgrey guibg=darkgrey
match OverLength /\%>80v.\+/
" setup backup settings
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
if exists("&undodir")
set undodir=~/.vim/undo
endif
set backup
"" set filetype check on
:filetype plugin indent on
" encodings configure
set fileencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,gb2312,cp936
set sessionoptions+=unix,slash
" indentation related settings
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set backspace=indent,eol,start
set autoindent
set smartindent
" setting about old window resizing behavior when open a new window
set winfixheight
" not let all windows keep the same height/width
set noequalalways
" syntax highlighting settings
syntax on
set t_Co=256 " 256 colors
set background=dark
"set cursorline " Highlight current line
set lcs=tab:▸\ ,trail:·,nbsp:_ " Show “invisible” characters
set list
if filereadable(expand("$HOME/.vim/colors/peaksea.vim"))
colorscheme peaksea
end
" some macros to execute script in ruby
nmap ;e :w<CR>:exe ":!ruby " . getreg("%") . "" <CR>
nmap ;c :w<CR>:exe ":!ruby -c " . getreg("%") . "" <CR>
nmap ,o o<Esc>
"folding settings
"za = toggle fold on this scope
"zM = fold all
"zR = unfold all
"#zo = unfold # scopes down
"#zc = fold # scopes up
set foldmethod=syntax "fold based on syntax. Alt method: "indent"
set foldnestmax=20 "deepest fold is 20 levels
set nofoldenable "dont fold by default
set foldlevel=1 "this is just what i use
highlight Folded ctermbg=black ctermfg=darkgrey
if has("folding")
function! UnfoldCur()
if !&foldenable
return
endif
let cl = line(".")
if cl <= 1
return
endif
let cf = foldlevel(cl)
let uf = foldlevel(cl - 1)
let min = (cf > uf ? uf : cf)
if min
execute "normal!" min . "zo"
return 1
endif
endfunction
endif
function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
if has("folding")
autocmd BufWinEnter * if ResCur() | call UnfoldCur() | endif
else
autocmd BufWinEnter * call ResCur()
endif
augroup END
" Strip trailing whitespace (,ss)
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
noremap <leader>ss :call StripWhitespace()<CR>
" Save a file as root (,W)
noremap <leader>W :w !sudo tee % > /dev/null<CR>
noremap <leader>n :set nonumber!<CR>
noremap <leader>c I#<Esc><Esc>
" Automatic commands
if has("autocmd")
" Enable file type detection
filetype on
" Treat .json files as .js
autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript
endif
" Syntax for Vagrantfile
au BufRead,BufNewFile Vagrantfile setfiletype ruby
au BufRead,BufNewFile Berksfile setfiletype ruby
au BufRead,BufNewFile Berksfile.lock setfiletype ruby