-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvimrc
277 lines (231 loc) · 8.27 KB
/
nvimrc
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
let g:python_host_prog='/usr/bin/python2'
let g:mapleader = "\<Space>"
source ~/.config/nvim/plugins
" General settings {{{
" ====================================================================
set clipboard=unnamed,unnamedplus
set number " show line numbers
set noswapfile " disable creating of *.swp files
set hidden " hide buffers instead of closing
set lazyredraw " speed up on large files
set scrolloff=10 " Keep 10 lines (top/bottom) for scope
set sidescrolloff=10 " Keep 5 lines at the size
set virtualedit=onemore " allow the cursor to move just past the end of the line
set undolevels=5000 " set maximum undo levels
" ! save global variables that doesn't contains lowercase letters
" h disable the effect of 'hlsearch' when loading the viminfo
" f1 store marks
" '100 remember 100 previously edited files
set viminfo=!,h,f1,'100
set foldmethod=marker " Fold on the marker
set foldopen=block,hor,mark,percent,quickfix,tag " what movements
" open folds
set diffopt=filler,vertical " default behavior for diff
" ignore pattern for wildmenu
set wildignore+=*.a,*.o,*.pyc,*~,*.swp,*.tmp
set wildmode=list:longest,full
set list " show hidden characters
set listchars=tab:•·,trail:·,extends:❯,precedes:❮,nbsp:×
set laststatus=2 " always show status line
set showcmd " always show current command
set nowrap " disable wrap for long lines
set textwidth=0 " disable auto break long lines
" }}}
" Indentation {{{
" ====================================================================
set expandtab " replace <Tab with spaces
set tabstop=2 " number of spaces that a <Tab> in the file counts for
set softtabstop=2 " remove <Tab> symbols as it was spaces
set shiftwidth=2 " indent size for << and >>
set shiftround " round indent to multiple of 'shiftwidth' (for << and >>)
" }}}
" Search {{{
" ====================================================================
set ignorecase " ignore case of letters
set smartcase " override the 'ignorecase' when there is uppercase letters
set gdefault " when on, the :substitute flag 'g' is default on
" }}}
" Colors and highlightings {{{
" ====================================================================
colorscheme jellybeans
"let g:lightline#colorscheme#jellybeans_mod#palette = lightline#colorscheme#flatten(s:p)
set cursorline " highlight current line
set colorcolumn=80 " highlight column
highlight! ColorColumn ctermbg=233 guibg=#131313
" Various columns
highlight! SignColumn ctermbg=233 guibg=#0D0D0D
highlight! FoldColumn ctermbg=233 guibg=#0D0D0D
" Syntastic
highlight SyntasticErrorSign guifg=black guibg=#E01600 ctermfg=16 ctermbg=160
highlight SyntasticErrorLine guibg=#0D0D0D ctermbg=232
highlight SyntasticWarningSign guifg=black guibg=#FFED26 ctermfg=16 ctermbg=11
highlight SyntasticWargningLine guibg=#171717
highlight SyntasticStyleWarningSign guifg=black guibg=#bcbcbc ctermfg=16 ctermbg=250
highlight SyntasticStyleErrorSign guifg=black guibg=#ff8700 ctermfg=16 ctermbg=208
" Language-specific
highlight! link elixirAtom rubySymbol
" }}}
" === Key Mappings " {{{
" edit nvimrc
nnoremap <leader>vi :tabedit $MYVIMRC<CR>
" quick way to save file
nnoremap <leader>w :w<CR>
" fix common typos
:map :W :w
cabbrev Wq wq
cabbrev W w
cabbrev Q q
" disable search highlighting
nnoremap // :nohlsearch<CR>
" Toggle quickfix
map <silent> <F8> :copen<CR>
" Y behave like D or C
nnoremap Y y$
" enable visual shifting
vnoremap < <gv
vnoremap > >gv
" faster navigation
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" also allow scroll in insert mode
inoremap <C-e> <C-o><C-e>
inoremap <C-y> <C-o><C-y>
" improve up/down movement on wrapped lines
nnoremap j gj
nnoremap k gk
" remap cw & dw
nnoremap cw ciw
nnoremap dw daw
"set window movement leading char to 's' so you dont get emacs fingers
nnoremap s <C-W>
" keep cursor in place while joining lines
nnoremap J mzJ`z
" rempaping ` to '
" 'a will jump to the line marked with ma
" `a will jump to the line and column so it's better
nnoremap ' `
nnoremap ` '
" keep search terms in the middle of the buffer
nmap n :norm! nzzzv<CR>
nmap N :norm! Nzzzv<CR>
" map CTRL+] to ctrl J (follow link in help file)
noremap <C-m> <C-]>
" set undo point after typing one of these characters
inoremap , ,<C-g>u
inoremap . .<C-g>u
inoremap ! !<C-g>u
inoremap ? ?<C-g>u
inoremap : :<C-g>u
" When using { and } you never want my cursor to be on an empty line,
" but rather the first or last line of text in a paragraph.
:nnoremap <expr> { len(getline(line('.')-1)) > 0 ? '{+' : '{-'
:nnoremap <expr> } len(getline(line('.')+1)) > 0 ? '}-' : '}+'
" Copy current file path to clipboard
nnoremap <leader>% :call CopyCurrentFilePath()<CR>
function! CopyCurrentFilePath() " {{{
let @+ = expand('%')
echo @+
endfunction
" }}}
" Select all text
noremap vA ggVG
" Buffer management
nmap <C-tab> :bn<CR>
imap <C-tab> <ESC>:bn<CR>i
nmap <C-h> :bp<CR>
nmap <C-l> :bn<CR>
" Creating splits with empty buffers in all directions
nnoremap <Leader>hn :leftabove vnew<CR>
nnoremap <Leader>ln :rightbelow vnew<CR>
nnoremap <Leader>kn :leftabove new<CR>
nnoremap <Leader>jn :rightbelow new<CR>
" If split in given direction exists - jump, else create new split
function! JumpOrOpenNewSplit(key, cmd, fzf) " {{{
let current_window = winnr()
execute 'wincmd' a:key
if current_window == winnr()
execute a:cmd
if a:fzf
Files
endif
else
if a:fzf
Files
endif
endif
endfunction " }}}
nnoremap <silent> <Leader>hh :call JumpOrOpenNewSplit('h', ':leftabove vsplit', 0)<CR>
nnoremap <silent> <Leader>ll :call JumpOrOpenNewSplit('l', ':rightbelow vsplit', 0)<CR>
nnoremap <silent> <Leader>kk :call JumpOrOpenNewSplit('k', ':leftabove split', 0)<CR>
nnoremap <silent> <Leader>jj :call JumpOrOpenNewSplit('j', ':rightbelow split', 0)<CR>
" Remove trailing whitespaces in current buffer
nnoremap <Leader><BS>s :1,$s/[ ]*$//<CR>:nohlsearch<CR>1G
" Universal closing behavior
nnoremap <silent> Q :call CloseSplitOrDeleteBuffer()<CR>
nnoremap <silent> Й :call CloseSplitOrDeleteBuffer()<CR>
function! CloseSplitOrDeleteBuffer() " {{{
if winnr('$') > 1
wincmd c
else
execute 'bdelete'
endif
endfunction " }}}
" Delete all hidden buffers
nnoremap <silent> <Leader><BS>b :call DeleteHiddenBuffers()<CR>
function! DeleteHiddenBuffers() " {{{
let tpbl=[]
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1')
silent execute 'bwipeout' buf
endfor
endfunction " }}}
let g:session_dir = '$HOME/.nvim/sessions/'
nnoremap <Leader>sl :wall<Bar>execute "source " . g:session_dir . fnamemodify(getcwd(), ':t')<CR>
nnoremap <Leader>ss :execute "mksession! " . g:session_dir . fnamemodify(getcwd(), ':t')<CR>
" }}}
" Terminal {{{
" ====================================================================
nnoremap <silent> <leader><Enter> :tabnew<CR>:terminal<CR>
" Opening splits with terminal in all directions
nnoremap <Leader>h<Enter> :leftabove vnew<CR>:terminal<CR>
nnoremap <Leader>l<Enter> :rightbelow vnew<CR>:terminal<CR>
nnoremap <Leader>k<Enter> :leftabove new<CR>:terminal<CR>
nnoremap <Leader>j<Enter> :rightbelow new<CR>:terminal<CR>
" Open tig
nnoremap <Leader>gg :tabnew<CR>:terminal tig<CR>
tnoremap <F1> <C-\><C-n>
tnoremap <C-\><C-\> <C-\><C-n>:bd!<CR>
function! TerminalInSplit(args)
botright split
execute 'terminal' a:args
endfunction
" }}}
" Autocommands {{{
" ====================================================================
augroup vimGeneralCallbacks
autocmd!
autocmd BufWritePost .nvimrc nested source ~/.nvimrc
augroup END
augroup quickFixSettings
autocmd!
autocmd FileType qf
\ nnoremap <buffer> <silent> q :close<CR> |
\ map <buffer> <silent> <F4> :close<CR> |
\ map <buffer> <silent> <F8> :close<CR>
augroup END
augroup terminalCallbacks
autocmd!
autocmd TermClose * call feedkeys('<cr>')
augroup END
"}}}
" Cursor configuration {{{
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" }}}
" vim: set sw=2 ts=2 et foldlevel=0 foldmethod=marker: