-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
229 lines (177 loc) · 6.19 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
syn on
set t_Co=256
set mouse=
colorscheme lucius
LuciusBlack
" Lucius Customizations
highlight def link rubySymbol Identifier
let g:go_def_mode = "gopls"
let g:go_info_mode = "gopls"
let g:go_metalinter_autosave_enabled = ['all']
let g:go_auto_type_info = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
let g:fzf_command_prefix = 'Fzf'
let g:fzf_preview_window = ['hidden']
let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.6, 'relative': v:true, 'yoffset': 1.0 } }
let g:ctrlp_user_command = 'ag %s --ignore-case --nocolor --nogroup --hidden -g ""'
" Load a local .vimrc if present (allows for project-specific settings)
set exrc
" Disable neovim's cursor changing
set guicursor=
" Go to last position if known when opening a file
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") && &filetype != "gitcommit" | exe "normal! g`\"zz" | endif
" Change active leader to ' '
let mapleader = " "
" Always show status bar
set laststatus=2
set wildignore+=*/vendor/bundle*
set wildignore+=*/node_modules*
" Default tabs to 2 spaces and auto indent
set tabstop=2 shiftwidth=2
set autoindent
" disable text wrapping
set nowrap
" Open new buffers when splitting in natural directions
set splitright
set splitbelow
" Rebalance buffers on window resize
autocmd VimResized * wincmd =
autocmd VimResized * vertical wincmd =
" No swap files, etc
set nobackup
set nowritebackup
set noswapfile
" Enable indent plugin
filetype plugin indent on
set expandtab " Replace tabs with spaces
set number " Show line numbers
set cursorline " Highlight current line
set cursorcolumn " Highlight current column
set ruler
set scrolloff=4 " Always show 4 lines of context at the top/bottom
" Hide buffers rather than closing them to maintain undo history
set hidden
" Don't redraw during macros
set lazyredraw
" Reduce the lag of pressing O just after Esc
set notimeout
set ttimeout
" Column limit highlighting plus file specific limit definitions
set colorcolumn=+1
set textwidth=80
" Set textwidth to 72 for git commits
autocmd FileType gitcommit setlocal spell textwidth=72
" Don't have sticky search highlight but do highlight whilst searching
set nohlsearch
set incsearch
set fillchars+=vert:\
" Visible whitespace
set listchars=tab:»·,precedes:<,extends:>
set list
highlight TrailingWhitespace ctermbg=DarkGray
autocmd InsertEnter * match
autocmd InsertLeave * match TrailingWhitespace /\s\+$/
" Include -, !, and ? as part of words for autocomplete and so on
set iskeyword+=\-
set iskeyword+=\!
set iskeyword+=\?
" 256 color reference http://www.mudpedia.org/mediawiki/index.php/Xterm_256_colors
highlight ColorColumn ctermbg=232
highlight CursorLine ctermbg=235
highlight CursorColumn ctermbg=235
highlight Pmenu ctermfg=Black ctermbg=DarkGray
highlight PmenuSel ctermfg=Black ctermbg=White
highlight StatusLine ctermfg=Black ctermbg=White cterm=none gui=none
highlight StatusLineNC ctermfg=Black ctermbg=DarkGray cterm=none gui=none
highlight MatchParen ctermfg=DarkGray ctermbg=Black cterm=none
highlight clear SpellBad
highlight SpellBad ctermfg=009
" CtrlP - Open created files in the current window
let g:ctrlp_open_new_file = 'r'
" CtrlP - Don't jump to open buffers for the selected file
let g:ctrlp_switch_buffer = 0
" CtrlP - Add .ctrlp as a custom root file
let g:ctrlp_root_markers = ['.ctrlp']
" CtrlP - Use ag to list files instead
let g:ctrlp_user_command = 'ag %s --ignore-case --nocolor --nogroup --hidden -g ""'
" CtrlP - Don't use caching
let g:ctrlp_use_caching = 0
" Grep - custom setup
set grepprg=ag\ --nogroup\ --nocolor\ --vimgrep
set grepformat^=%f:%l:%c:%m " file:line:column:message
function! CustomSearch()
let grep_term = input("Enter search term: ")
if !empty(grep_term)
execute 'silent grep' grep_term | copen
else
echo "Empty search term"
endif
redraw!
endfunction
command! CustomSearch call CustomSearch()
nnoremap <leader>f :CustomSearch<CR>
" HTML formatting - treat li and p as blocks
let g:html_indent_tags = 'li\|p'
" Markdown formatting - syntax highlighting for ```ruby style blocks
let g:markdown_fenced_languages = ['coffee', 'css', 'erb=eruby', 'javascript', 'js=javascript', 'json=javascript', 'ruby', 'sass', 'xml', 'html']
" COMMENTING HELPERS
function! ObeyTextWidth()
return "normal! 0" . &textwidth . "llF r\<CR>"
endfunction
" Ctrl+f whilst in normal mode breaks the line for col80 formatting.
nnoremap <C-f> :execute ObeyTextWidth()<CR>
" Ctrl+j whilst in normal mode joins this line with the next one.
nnoremap <C-j> Jd2wi <Esc>w
" Ctrl+k whilst in normal mode joins this line with the previous one.
nnoremap <C-k> kJd2wi <Esc>
" Map K to join line above rather than default of search for command
nnoremap <S-k> kJ
vnoremap <S-k> J
" F8 in normal mode removes all trailing whitespace and extra blank lines.
nnoremap <F8> my:%s/\s\+$//e<CR>:%s/\n\{3,}/\r\r/e<CR>`y
" Shortcut for editing and save-with-reload for .vimrc
nmap <silent> <leader>re :e $MYVIMRC<CR>
nmap <silent> <leader>rs :source $MYVIMRC<CR>
" Quick save
nmap <leader>w :w<CR>
nmap <leader>q :wq<CR>
" Fuzzy finding aliases
nmap <leader>p :FzfFiles<CR>
" Split creation
nmap <leader>v :vsplit<CR>:FzfFiles<CR>
nmap <leader>s :split<CR>:FzfFiles<CR>
" Map ; to : for less shift-key action
nnoremap ; :
" Create a log message 'hiding' toggle
syn match LogMessage /\c^\s*log.*/
hi link LogMessage NONE
let s:hide_logs = "no"
function! ToggleLogs()
if s:hide_logs == "yes"
hi link LogMessage NONE
let s:hide_logs = "no"
else
hi link LogMessage Comment
let s:hide_logs = "yes"
endif
endfunction
nnoremap <silent> <F10> :call ToggleLogs()<CR>
" Simpler split navigation
noremap <leader>h <c-w>h
noremap <leader>j <c-w>j
noremap <leader>k <c-w>k
noremap <leader>l <c-w>l
" Tab for paragraph movement
noremap <TAB> }
noremap <S-TAB> {
set undofile " Save undos after file closes
set undodir=~/.vim/undodir/ " Where to save undo histories
set undolevels=1000 " How many undos
set undoreload=10000 " Number of lines to save for undo