-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
157 lines (130 loc) · 3.48 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
156
157
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Mappings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader=","
let $FZF_DEFAULT_COMMAND = 'ag -l -g ""'
nnoremap <c-p> :Files<cr>
nnoremap \ :Ag<cr>
nnoremap <leader>gs :Git<cr>)
nnoremap <leader>b :Buffers<cr>
" tab navigation
map <tab> :tabnext<cr>
map <s-tab> :tabprev<cr>
" Disable Entering Ex mode
map Q <Nop>
" Disable K looking man stuff up
map K <Nop>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Custom Functions & Commands
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! TestIt(...)
let p = expand('%:h')
let f = expand('%')
let l = line(".")
let c = '!clear && rails t'
write
if a:0 == 0
exec c
elseif a:1 == 'f'
exec c . ' ' . f
elseif a:1 == 'l'
exec c . ' ' . f . ':' . l
endif
endfunction
map <leader>t :call TestIt('l')<cr>
map <leader>f :call TestIt('f')<cr>
" Preserve history and cursor position while executing the given command
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
function! StripTrailingWhitespaces()
call Preserve("%s/\\s\\+$//e")
endfunction
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
" Multipurpose tab key
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <expr> <tab> InsertTabWrapper()
inoremap <s-tab> <c-n>
" if this window is last on screen quit without warning
function! MyLastWindow()
if &buftype=="quickfix"
if winbufnr(2) == -1
quit!
endif
endif
endfunction
autocmd BufWritePre * :call mkdir(expand('%:p:h'), 'p')
autocmd BufWritePre * :call StripTrailingWhitespaces()
autocmd BufEnter * call MyLastWindow()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
silent! if plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
Plug 'sonph/onehalf', { 'rtp': 'vim/' }
call plug#end()
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
set cursorline
colorscheme onehalflight
set so=10 " Set 7 lines to the cursor - when moving vertical..
set cmdheight=2 " The commandbar height
set nocompatible
set whichwrap+=<,>,h,l " Traverse endline to next line
set nolazyredraw " Don't redraw while executing macros
set showmatch " Show matching bracets when text indicator is over them
set number " Show me the numbers
set ignorecase
set smartcase
" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Turn backup off
set nobackup
set nowb
set noswapfile
" Fold related
set foldmethod=manual
set nofoldenable
set nojoinspaces
" Tab related
set expandtab
set shiftwidth=2
set tabstop=2
set lbr
set tw=500
set autoindent
set smartindent
set wrap