-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
192 lines (173 loc) · 5.85 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
" -- vim-plug ------------------------------------------------------------------
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-dispatch'
Plug 'NLKNguyen/papercolor-theme'
Plug 'vimwiki/vimwiki'
Plug 'cormacrelf/vim-colors-github'
Plug 'chriskempson/base16-vim'
Plug 'wellle/context.vim'
" Plug 'vim-airline/vim-airline'
call plug#end()
" -- status line ---------------------------------------------------------------
set statusline+=%F " show full path of current file
"display a warning if &paste is set
set statusline+=%#error#
set statusline+=%{&paste?'[paste]':''}
set statusline+=%*
set statusline+=%= " left/right separator
set statusline+=%c, " cursor column
set statusline+=%l/%L " cursor line/total lines
set statusline+=\ %P " percent through file
set laststatus=2 " always show status line
" -- general -------------------------------------------------------------------
" colorscheme
set t_Co=256 " This is may or may not needed.
set background=light
colorscheme PaperColor
" let g:airline_theme='papercolor'
" vimwiki required settings
set nocompatible
:filetype plugin on
syntax on
let g:vimwiki_list = [{'path': '~/vimwiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]
" incomplete tasks
function! VimwikiFindIncompleteTasks()
lvimgrep /- \[ \]/ %:p
lopen
endfunction
function! VimwikiFindAllIncompleteTasks()
VimwikiSearch /- \[ \]/
lopen
endfunction
" line numbers
set number
set relativenumber
" indenting
set tabstop=2
set shiftwidth=3
set softtabstop=3
set expandtab
set autoindent
autocmd FileType python setlocal tabstop=3 shiftwidth=3 softtabstop=3
" copy and paste to and from Vim
set clipboard=unnamed
" remove error bells
set noerrorbells
set vb t_vb =
set belloff=all
" removes backup
set nobackup
set undodir=~/.vim/undodir
set undofile
" search as you type
set incsearch
" remove highlight search
set nohlsearch
" search case sensitive when there are uppercase letters
" set smartcase
set ignorecase
" disables auto comments after newline of original comment
autocmd FileType c,java inoreabbrev <buffer> /** /**<CR>/<Up>
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" natural splits
set splitbelow
set splitright
" resize split when resize terminal
autocmd VimResized * wincmd =
" escape to normal mode from terminal mode for nvim
if has('nvim')
tnoremap <C-[> <C-\><C-n>
endif
" indented text wrapping when whitespace
set breakindent
set breakindentopt=shift:2
set linebreak
" set leader key
let mapleader = " "
" auto close {
function! s:CloseBracket()
let line = getline('.')
if line =~# '^\s*\(struct\|class\|enum\) '
return "{\<Enter>};\<Esc>O"
elseif searchpair('(', '', ')', 'bmn', '', line('.'))
" Probably inside a function call. Close it off.
return "{\<Enter>});\<Esc>O"
else
return "{\<Enter>}\<Esc>O"
endif
endfunction
inoremap <expr> {<Enter> <SID>CloseBracket()
" reformat file and retain current position
nnoremap g= mmgg=G`m
set backspace=indent,eol,start
" shows the file name in the title bar
set title
" remove swp files
set noswapfile
" always show sign column
" set signcolumn=yes
" Allow j and k commands to navigate soft-wrapped lines without 'g'
nnoremap <expr> j v:count ? 'j' : 'gj'
nnoremap <expr> k v:count ? 'k' : 'gk'
" python mode
let g:pymode_python = 'python3'
let g:pymode_trim_whitespaces = 0
" paste mode toggle
set pastetoggle=<F10>
" --- fzf ----------------------------------------------------------------------
" default fzf layout
" - Popup window
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'PreProc'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" --- template -----------------------------------------------------------------
autocmd BufNewFile *.cpp 0r ~/.vim/templates/skeleton.cpp
" --- compile run settings -----------------------------------------------------
" <leader>m to test for errors
" <leader>n to show output
" Java
autocmd FileType java nnoremap <leader>m :w <bar> :set makeprg=javac\ %<CR>:Make<CR>
autocmd FileType java nnoremap <leader>n :w <bar> :ter java -cp %:p:h %:t:r <CR>
" C++
autocmd FileType cpp nnoremap <leader>m :w <bar> :set makeprg=g++\ --std=c++17\ %\ -o\ %<<CR>:Make<CR>
autocmd FileType cpp nnoremap <leader>n :w <bar> :ter ./%< <CR>
" the following code only works with nvim
set hidden
function! TermWrapper(command) abort
if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
if g:split_term_style ==# 'vertical'
let buffercmd = 'vnew'
elseif g:split_term_style ==# 'horizontal'
let buffercmd = 'new'
else
echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
endif
if exists('g:split_term_resize_cmd')
exec g:split_term_resize_cmd
endif
exec buffercmd
exec 'term ' . a:command
exec 'setlocal nornu nonu'
exec 'startinsert'
endfunction
command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++11 %s && ./a.out', expand('%')))
command! -nargs=1 CompileAndRunWithFile call TermWrapper(printf('g++ -std=c++11 %s && ./a.out < %s', expand('%'), <args>))
autocmd FileType cpp nnoremap <leader>r :w<bar>:CompileAndRun<CR>
let g:split_term_style = 'vertical'