-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
148 lines (119 loc) · 3.3 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
" Disable vi compatibility
set nocompatible
" Map the leader key to a spacebar
map <Space> <leader>
" Configure working directory
autocmd BufEnter * lcd %:p:h
" Stops comments from being extended to newlines
autocmd BufNewFile,BufRead * setlocal formatoptions-=ro
" History
set history=100
" Filetype plugins
filetype on
filetype plugin on
filetype indent on
" Ignore compiled files
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=.git\*,.hg\*,.svn\*
else
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
endif
" Text encoding
set encoding=utf8
" Filetype
set ffs=unix,dos,mac
" Spaces vs. tabs
set tabstop=4
set shiftwidth=4
set expandtab
" Show current file and status bar
set title
set titlestring=%F\ %r\ %m
set laststatus=2
" Line numbers
set number
set relativenumber
set cursorline
highlight LineNr ctermfg=grey
highlight CursorLine cterm=NONE ctermbg=NONE ctermfg=NONE
highlight CursorLineNr cterm=bold ctermbg=NONE ctermfg=white
" Syntax highlighting
syntax enable
highlight MatchParen cterm=none ctermbg=white ctermfg=black
" Show matching brackets
set showmatch
set mat=2
" Enables yank to system clipboard, use `unnamedplus` if broken on Linux
set clipboard=unnamed
" Return to last cursor position when reopening file
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Disable bells
set visualbell
set noerrorbells
set t_vb=
set tm=500
" Configure search
set ignorecase
set smartcase
set incsearch
set magic
nnoremap <CR> :noh<CR><CR>:<backspace>
" Mouse support (depends on terminal)
set mouse+=a
" Enable hidden buffers
set hidden
" Regex
set regexpengine=0
" Visual mode searching for current selection
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> " :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
" Don't redraw
set lazyredraw
" Enable autoread
set autoread
autocmd FocusGained,BufEnter * checktime
" Backup
set nobackup
set nowb
set noswapfile
" Shows commands
set showcmd
" Remapping
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Follow symlinks to target
function! MyFollowSymlink(...)
if exists('w:no_resolve_symlink') && w:no_resolve_symlink
return
endif
let fname = a:0 ? a:1 : expand('%')
if fname =~ '^\w+:\/' " Don't mess with 'fugitive://' etc.
return
endif
let fname = simplify(fname)
let resolvedfile = resolve(fname)
if resolvedfile == fname
return
endif
let resolvedfile = fnameescape(resolvedfile)
echohl WarningMsg | echomsg 'Resolved symlink' fname '-->' resolvedfile | echohl None
exec 'file ' . resolvedfile
silent! w! " Workaround for 'file exists' error on write
endfunction
command! FollowSymlink call MyFollowSymlink()
command! ToggleFollowSymlink let w:no_resolve_symlink = !get(w:, 'no_resolve_symlink', 0) | echo "w:no_resolve_symlink =>" w:no_resolve_symlink
autocmd BufReadPost * call MyFollowSymlink(expand('<afile>'))
" Remove trailing whitespace on save
fun! CleanExtraSpaces()
let save_cursor = getpos(".")
let old_query = getreg('/')
silent! %s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfun
if has("autocmd")
autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
endif