我的Windows7 vim配置(VimTeX)
首先, 我所有的配置目录都在C:\Vim8\myvim\
下(下载myvim.zip).
其中, _gvimrc
, _vimrc
如下, 主要是方便写LaTeX, 使用的插件是VimTeX.
_vimrc
包含了一般设定, 插件管理, VimTeX配置, 与用户设定. 详细的配置可以参考注释.
1 |
set guitablabel=\[%N\]\ %t\ %M |
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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
" vim: foldmethod=marker " General Config {{{1 set nocompatible "Not for VI set number "Line numbers are good set spell "Spell checking set autochdir "Auto change the current directory set wildmenu "Autocomplete of vim command set nohls "Disable highlight search set is "Increase search set ruler "Show position of cursor set backspace=indent,eol,start "Allow backspace in insert mode set visualbell "No sounds colo darkblue "Color Theme "colo phd "Retro color theme "colo solarized "Simple&beautiful theme "set background =dark "Set background dark/light "colo molokai "Colorful theme "let g:molokai_original = 1 set sw=2 ts=2 bs=2 ai si sta et "Shorter spaces set wrap lbr tw=0 wm=0 "Set Wrap set nolist "List disables linebreak "set shellslash "Use forward slash set fenc=utf-8 "Encoding for file set enc=utf-8 "Encoding for file's contents set fencs=usc-bom, \utf-8, \chinese, \cp936, \gb18030, \big5, \euc-jp, \euc-kr, \latin1 "Supported encoding for file if has("autocmd") filetype plugin indent on endif " Spell check for English, escape Chinese {{{2 autocmd FileType tex setlocal spell spelllang=en_us,cjk " Add : _ - to keywords {{{2 au FileType tex let g:tex_isk='48-57,_,:,-,a-z,A-Z,192-255' " Enable TeX Fold {{{2 let g:tex_fold_enabled=1 " Add more fold by TexNewMathZones {{{2 " see :h tex-math " see $VIM/myvim/after/syntax/tex.vim " Accept @ in .tex {{{ au FileType tex let b:tex_stylish=1 " User Variable $TEXDOC and $USERHOME {{{2 let $TEXDOC =$Vim."/../CTEX/TEXDOC/" cd $TEXDOC let $USRHOME=$VIM."/myvim/" " Add Custom RUNTIMEPATH {{{3 if has('win32') || has('win64') let &rtp .=','.$VIM.'/myvim/,'.$VIM.'/myvim/after' endif " Plugin Admin {{{1 " vim-plug https://github.com/junegunn/vim-plug " Add Plug owner/projname then run PlugInstall " The root of plug is $Vim/myvim/plugged call plug#begin('$Vim/myvim/plugged') " for latex Plug 'lervag/vimtex' " for snips Plug 'Sirver/ultisnips' " for fold Plug 'Konfekt/FastFold' "Plug 'nelstrom/vim-markdown-folding' " for git Plug 'tpope/vim-fugitive' " for session Plug 'xolox/vim-session' Plug 'xolox/vim-misc' " for more default snippets "Plug 'honza/vim-snippets' "Plug 'ajh17/VimCompletesMe' " for chinese input "Plug 'vim-scripts/VimIM' " for color theme solarized "Plug 'altercation/vim-colors-solarized' call plug#end() " Advanced Config for VimTeX{{{1 set fillchars=vert:\|,fold:- let g:vimtex_quickfix_ignored_warnings = [] " \ 'Underfull', " \ 'Overfull', " \ 'specifier changed to', " \ 'Package mpgraphics Warning', " \] let g:tex_flavor = 'latex' let g:vimtex_quickfix_mode = 2 let g:vimtex_latexmk_options = '-xelatex -verbose -file-line-error -synctex=1 -shell-escape -interaction=nonstopmode' let g:vimtex_view_general_viewer = 'SumatraPDF' let g:vimtex_view_general_options = '-reuse-instance -inverse-search "\"' . $VIMRUNTIME . '\gvim.exe\" -n --remote-silent +\%l \"\%f\"" -forward-search @tex @line @pdf' let g:vimtex_view_general_options_latexmk = '-reuse-instance' " UltiSnips Config {{{2 let g:UltiSnipsSnippetsDir =$VIM.'/myvim/UltiSnips' " Add Quick Math Input {{{2 "`N for \nabla "let g:vimtex_imaps_disabled = ['N', '~', '^'] call vimtex#imaps#add_map({ \ 'lhs' : 'N', \ 'rhs' : '\nabla', \ 'wrapper' : 'vimtex#imaps#wrap_math' \}) call vimtex#imaps#add_map({ \ 'lhs' : '~', \ 'rhs' : '\tilde', \ 'wrapper' : 'vimtex#imaps#wrap_math' \}) call vimtex#imaps#add_map({ \ 'lhs' : '^', \ 'rhs' : '\wedge', \ 'wrapper' : 'vimtex#imaps#wrap_math' \}) call vimtex#imaps#add_map({ \ 'lhs' : '2', \ 'rhs' : '\sqrt{}', \ 'wrapper' : 'vimtex#imaps#wrap_math' \}) " TeX Live Preview {{{2 function! Texlivepreview() "change dir :lcd %:p:h if filewritable(bufname("%")) silent update % endif endfunction "Since not work for VI if has("gui_running") "au CursorMoved *.tex call Texlivepreview() "au CursorMovedI *.tex call Texlivepreview() au CursorHoldI *.tex call Texlivepreview() endif " Custom Config for VimTeX {{{2 " Open bib (./bib/jobname) {{{3 "map <Leader>lb :silent exec 'tabnew %:h/bib/%:t:r.bib'<cr> map <Leader>lb :silent exec "tabnew %:p:h/bib/*.bib"<tab><cr> " 7z {{{3 map <Leader>lz :silent exec "!cd %:p:h/../ & 7z u -tzip %:t:r usrdefn.tex %:h:t/%:t:r.tex %:h:t/%:t:r.pdf %:h:t/%:t:r.synctex.gz %:h:t/bib/%:t:r.bib >".$USRHOME."/temp/7z.log 2>&1"<cr><cr> map <Leader>lze :silent exec "!cd %:p:h/../ & 7z u -seml -tzip %:t:r usrdefn.tex %:h:t/%:t:r.tex %:h:t/%:t:r.pdf %:h:t/%:t:r.synctex.gz %:h:t/bib/%:t:r.bib >".$USRHOME."/temp/7z.log 2>&1"<cr><cr> " Open Working Directory {{{3 "set nossl "use \ for path instead of / nnoremap <silent> <Leader>ld :if expand("%:p:h") != "" \| exec "!start explorer" expand("%:p:h:S") \| endif<CR> " User Define Maps for VimTex{{{3 " Open bib/*.bib Under Current Dir {{{4 nmap ;b \lb imap ;b <Esc>:w<cr>;b " Compile by Latexmk {{{4 nmap ;c \ll imap ;c <Esc>:w<cr>;c " Compile Selected {{{4 nmap ;C \lL imap ;C <Esc>:w<cr>;C " Open Dir of Current File {{{4 nmap ;d \ld imap ;d <Esc>:w<cr>;d " Open Compile Output {{{4 nmap ;o \lo imap ;o <Esc>:w<cr>;o " Open Error Log {{{4 nmap ;e \le imap ;e <Esc>:w<cr>;e " Show Latexmk Status {{{4 nmap ;g \lg imap ;g <Esc>:w<cr>;g " Show Fullstatus {{{4 nmap ;G \lG imap ;G <Esc>:w<cr>;G " Show Vimtex Infomation {{{4 nmap ;i \li imap ;i <Esc>:w<cr>;i " Show Vimtex Fullinfo {{{4 nmap ;I \lI imap ;I <Esc>:w<cr>;I " Stop Current Latexmk {{{4 nmap ;k \lk imap ;k <Esc>:w<cr>;k " Stop All Latexmk {{{4 nmap ;K \lK imap ;K <Esc>:w<cr>;K " Show Quick Key Reference {{{4 nmap ;m \lm imap ;m <Esc>:w<cr>;m " Set Main {{{4 nmap ;M \ls imap ;M <Esc>:w<cr>;M " Clean Latexmk {{{4 nmap ;n \lc imap ;n <Esc>:w<cr>;n " Full Clean {{{4 nmap ;N \lC imap ;N <Esc>:w<cr>;N " Relaod Vimtex {{{4 nmap ;r \lx imap ;r <Esc>:w<cr>;r " Toc Open {{{4 nmap ;t \lt imap ;t <Esc>:w<cr>;t " Toggle toc open {{{4 nmap ;T \lT imap ;T <Esc>:w<cr>;T " Open Label {{{4 nmap ;y \ly imap ;y <Esc>:w<cr>;y " Toggle Label Open {{{4 nmap ;Y \lY imap ;Y <Esc>:w<cr>;Y " Preview {{{4 nmap ;v \lv imap ;v <Esc>:w<cr>;v " <F5> for Omni Complete {{{4 imap <F5> <c-x><c-o> " Autoinstall missing package {{{1 function! InstallPackages() let winview = winsaveview() call inputsave() let cmd = ['tlmgr install'] %call add(cmd, matchstr(getline('.'), '\\usepackage\(\[.*\]\)\?{\zs.*\ze\}')) echomsg join(cmd) echo system(join(cmd)) call inputrestore() call winrestview(winview) endfunction command! InstallPackages call InstallPackages() " General Custom Config {{{1 " User Defined Maps{{{2 "Esc imap jk <Esc> "imap () ()<left> "imap [] []<left> "imap {} {}<left> "Move right imap <c-e> <right> "Copy to Clipboard vnoremap ;x "*y "Paste from Clopboard nmap ;p "*p "Switch window nnoremap nw <C-w><C-w> "Next/Previous tab gt gT " MetaPost Compile{{{3 function! MetaPostCompile() let s:origdir = getcwd() lcd %:p:h silent exec '!latexmk -C' silent exec '!xelatex -shell-escape %' silent exec 'cd' fnameescape(s:origdir) endfunction imap <silent> <F3> <Esc>:call MetaPostCompile()<cr> map <silent> <F3> :call MetaPostCompile()<cr> " Restore Working Status {{{2 " Only Save buffers, folds, and winsize. Ignore blank, curdir, help, options set sessionoptions=curdir,tabpages,resize,winpos,winsize,options " use xolox/vim-session let g:session_directory = $USRHOME let g:session_default_name = 'Session' let g:session_autosave ='yes' let g:session_autoload ='yes' let g:session_autosave_periodic =10 let g:session_autosave_silent=1 " Go to Last Position when Start {{{2 autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif " Remember the Position and Size of Window {{{2 set sessionoptions+=resize,winpos " Reset the Window Position and Size for TEX {{{2 autocmd BufNewFile,BufReadPost,BufEnter *.tex \ set fdm=syntax | \ if has("gui_running") | \ set lines=12 columns=132 | \ winpos 0 0 | \ endif " Set UTF8 Encoding for TEX {{{2 au FileType tex,markdown,vim set encoding=utf8 " Set EN Language as Default {{{2 " Just rename the `lang` dir under Vim8\vim80 " Remove Menu/Toolbar/Scrollbar {{{2 set go=aegit " Set Default Fonts for GUI {{{2 set guifont=Consolas:h16:cANSI " Set Status Line {{{2 "set statusline=%F%m%r\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L] if has('statusline') set laststatus=2 " Use airline for statusline. " Broken down into easily include-able segments set statusline=%<%f\ " Filename set statusline+=%w%h%m%r " Options set statusline+=%{fugitive#statusline()} " Git Hotness set statusline+=\ [%{&ff}/%Y] " Filetype set statusline+=\ [%{getcwd()}] " Current dir set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info endif " Auto Load _vimrc.custom in the Working Root {{{2 au BufNewFile,BufReadPost,BufEnter *.tex call CustomConfig() function! CustomConfig() let custom_vimrc = expand('%:p:h').'/_vimrc.custom' if filereadable(custom_vimrc) exe 'so' custom_vimrc endif endfunction " Auto Load vimrc When Save {{{2 augroup myvimrc au! au! BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so % \ | if has('gui_running') | so % | endif augroup END |
本作品采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载本站内容必须也遵循署名-非商业用途-保持一致的创作共用协议.
使用该配置需要首先安装vim-plug(参考https://github.com/junegunn/vim-plug#installation), 下载那个plug.vim并将其放到”autoload” 目录. 此外, 还需要安装git(参考https://git-scm.com/download/win), 我用的是绿色protable版. 以及python3(参考https://www.python.org/downloads/). 安装完成后需要添加路径到系统路径(如果是绿色版的话需要手动添加).
一些其他的问题:1. 安装texlive时不要安装文档以及源码占用空间会小很多. 2. texlive最好装最新版的texlive2016, 老版本不支持更新到最新版. 3. 若遇到api-ms-win-crt-runtime-l1-1-0.dll缺失请按照windows更新或者这里(http://stackoverflow.com/questions/33265663/api-ms-win-crt-runtime-l1-1-0-dll-is-missing-when-opening-microsoft-office-file)提供的Visual C++ Redistributable for Visual Studio 2017. 4. UltiSnip需要python2或者3, 一定要注意vim支持的python版本(:version 查看dll版本, 例如我的是python35.dll或者python27.dll), 安装的python版本要匹配. (参考这里:https://www.zhihu.com/question/29025705)
最后注意vim官方支持的是32位版本, 64位需要自己编译. 故python需要下载32位的.