-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
214 lines (183 loc) · 6.15 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
" Styled and colored underline support
let &t_AU = "\e[58:5:%dm"
let &t_8u = "\e[58:2:%lu:%lu:%lum"
let &t_Us = "\e[4:2m"
let &t_Cs = "\e[4:3m"
let &t_ds = "\e[4:4m"
let &t_Ds = "\e[4:5m"
let &t_Ce = "\e[4:0m"
" Strikethrough
let &t_Ts = "\e[9m"
let &t_Te = "\e[29m"
" Truecolor support
let &t_8f = "\e[38:2:%lu:%lu:%lum"
let &t_8b = "\e[48:2:%lu:%lu:%lum"
let &t_RF = "\e]10;?\e\\"
let &t_RB = "\e]11;?\e\\"
" Bracketed paste
let &t_BE = "\e[?2004h"
let &t_BD = "\e[?2004l"
let &t_PS = "\e[200~"
let &t_PE = "\e[201~"
" Cursor control
let &t_RC = "\e[?12$p"
let &t_SH = "\e[%d q"
let &t_RS = "\eP$q q\e\\"
let &t_SI = "\e[5 q"
let &t_SR = "\e[3 q"
let &t_EI = "\e[1 q"
let &t_VS = "\e[?12l"
" Focus tracking
let &t_fe = "\e[?1004h"
let &t_fd = "\e[?1004l"
execute "set <FocusGained>=\<Esc>[I"
execute "set <FocusLost>=\<Esc>[O"
" Window title
let &t_ST = "\e[22;2t"
let &t_RT = "\e[23;2t"
" vim hardcodes background color erase even if the terminfo file does
" not contain bce. This causes incorrect background rendering when
" using a color theme with a background color in terminals such as
" kitty that do not support background color erase.
let &t_ut=''
colorscheme nord
syntax enable
filetype on
filetype plugin on
filetype plugin on
"VimTex
let g:vimtex_view_method = 'zathura'
if empty(v:servername) && exists('*remote_startserver')
call remote_startserver('VIM')
endif
"nmap <localleader>vv <plug>(vimtex-view)
set omnifunc=syntaxcomplete#Complete
" aux file clean on close
augroup vimtex_config
autocmd!
autocmd Filetype tex autocmd BufUnload <buffer> VimtexClean
augroup END
augroup MarkdownMappings
autocmd!
autocmd FileType markdown nnoremap <buffer> <silent> <Up> g<Up>
autocmd FileType markdown nnoremap <buffer> <silent> <Down> g<Down>
autocmd FileType markdown inoremap <buffer> <silent> <Up> <C-o>g<Up>
autocmd FileType markdown inoremap <buffer> <silent> <Down> <C-o>g<Down>
augroup END
let g:clipbrdDefaultReg = '+'
set autoindent
set backup
set backupdir=$XDG_CACHE_HOME/vim,~/,/tmp
set belloff=all
set directory=$XDG_CACHE_HOME/vim,~/,/tmp
set expandtab
set foldmethod=marker
set hlsearch
set ignorecase
set incsearch
set mouse=a
set noerrorbells
set number relativenumber
set showcmd
set showmatch
set showmatch
set smartcase
set smartindent
set smarttab
set term=kitty
set undofile
set viminfo+=n$XDG_CACHE_HOME/vim/viminfo
set wildmenu
set wildmode=list:longest,full
set wrap linebreak
source $VIMRUNTIME/vimrc_example.vim
"set undodir=~/.vim/undodir
"set directory=~/.vim/tmp
"set backupdir=~/.vim/backup
"inoremap { {}<ESC>ha
"inoremap \" \""<ESC>ha
"inoremap { {}<ESC>ha
"inoremap ] ]<ESC>ha
"inoremap ) )<ESC>ha
" Indentation settings
set tabstop=4 " Number of spaces that a <Tab> in the file counts for
set shiftwidth=4 " Number of spaces to use for each step of (auto)indent
set expandtab " Use spaces instead of tabs
:nmap <c-s> :w<CR>
:imap <c-s> <Esc>:w<CR>a
" portable bracket handling
" inoremap " ""<left>
" inoremap ' ''<left>
"inoremap ( ()<left>
"inoremap [ []<left>
"inoremap { {}<left>
"inoremap {<CR> {<CR>}<ESC>O
"inoremap {;<CR> {<CR>};<ESC>O
"autocmd FileType tex,markdown setlocal spell spelllang=en_us
autocmd FileType markdown setlocal spell spelllang=en_us
inoremap <C-l> <c-g>u<Esc>[s1z=`]a<c-g>u
" Save *.tex files when focus is lost
"autocmd FocusLost *.tex :wa
" Save *.tex files when idle for 'updatetime'
"set updatetime=300
"autocmd CursorHold,CursorHoldI *tex silent! :wa
" ctrl-click forward search to zathura
" nnoremap <C-LeftMouse> <plug>(vimtex-view)
set clipboard=unnamedplus
autocmd BufNewFile,BufReadPre,BufRead *.md setfiletype markdown
autocmd Filetype markdown setlocal com=s1:/*,mb:*,ex:*/,://,b:%,:XCOMM,n:>,b:- | set formatoptions=tcroqln
autocmd FileType markdown inoremap $ $$<ESC>ha
"UltiSnips
let g:UltiSnipsExpandTrigger = '<Tab>' " use Tab to expand snippets
let g:UltiSnipsJumpForwardTrigger = '<Tab>' " use Tab to move forward through tabstops
let g:UltiSnipsJumpBackwardTrigger = '<S-Tab>' " use Shift-Tab to move backward through tabstops
let g:UltiSnipsSnippetDirectories=[$HOME.'/.vim/UltiSnips']
"reload snippets in vim
nnoremap <leader>u :call UltiSnips#RefreshSnippets()<CR>:echom "UltiSnips: Snippets refreshed."<CR>
"reload vimrc
nnoremap <leader>v :source $MYVIMRC<CR>:echom "Vim configuration reloaded"<CR>
" Toggle comment at the beginning of the line with Ctrl+D for various file types
autocmd FileType tex,python,vim,bash,haskell,markdown nnoremap <silent> <C-d> :call ToggleComment()<CR>
function! ToggleComment()
let s:line_num = line('.')
let s:line = getline(s:line_num)
" Check the file type and set the comment character accordingly
let s:comment_char =
\ (&ft == 'tex' ? '%' :
\ &ft == 'python' ? '#' :
\ &ft == 'vim' ? '"' :
\ &ft == 'bash' ? '#' :
\ &ft == 'haskell' ? '--' :
\ &ft == 'markdown' ? '<!--' : '')
" Check if the line starts with the comment character
if s:line =~ '^\s*' . s:comment_char
" Remove the comment character at the beginning of the line
execute 's/^\s*' . s:comment_char . '//'
else
" Add the comment character at the beginning of the line
execute 's/^\(\s*\)/\1' . s:comment_char . '/'
endif
endfunction
"spelling dropdown
nnoremap <Leader>s ea<C-X><C-S>
inoremap <expr> <CR> pumvisible() ? "\<C-y><Esc>" : "\<CR>"
" Toggle format in LaTex files
function! ToggleFormatting(format)
let word = expand('<cword>')
let line = getline('.')
let cursor_col = col('.')
let start_col = searchpos('\%'.cursor_col.'c' . word, 'n', line('.'))[1]
if line =~ '\v\\' . a:format . '\{' . word . '\}'
" Word is already in the specified format, remove formatting
execute 'silent s/\\' . a:format . '{' . word . '}/' . word . '/ge'
else
" Word is not in the specified format, add formatting
execute 'silent s/' . word . '/\\' . a:format . '{' . word . '}/ge'
endif
endfunction
"normal:
nnoremap <silent> <C-b> :call ToggleFormatting('textbf')<CR>
nnoremap <silent> <C-e> :call ToggleFormatting('emph')<CR>
"insert:
inoremap <silent> <C-b> <C-o>:call ToggleFormatting('textbf')<CR>
inoremap <silent> <C-e> <C-o>:call ToggleFormatting('emph')<CR>