neovim配置

latex的動圖展示

  1. 新建一個latex文件,編譯出pdf
    latex01
  2. 插入圖片
    latex02
    主要配置了markdown,LaTeX,python的一些編譯環境和快捷鍵。

常見的插入表格,圖片,代碼塊,公式等等都有配置。

我的neovim配置文件

" =============================================== 插件配置 ===============================================
call plug#begin('~/.config/nvim/plugged')
Plug 'iamcco/mathjax-support-for-mkdp'
Plug 'iamcco/markdown-preview.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'xuhdev/vim-latex-live-preview', {'for':'tex'}
Plug 'xuhdev/SingleCompile'
Plug 'vim-latex/vim-latex', {'for':'tex'}
call plug#end()

let g:coc_global_extensions = ['coc-python']
let g:tex_flavor='latex'
let g:Tex_DefaultTargetFormat = 'pdf'
let g:Tex_SmartKeyBS=0
let g:Tex_ViewRule_pdf = 'zathura'

call SingleCompile#SetCompilerTemplate('tex', '/usr/local/texlive/2019/bin/x86_64-linux/xelatex', 'XeLatex',
            \ '/usr/local/texlive/2019/bin/x86_64-linux/xelatex', '',
            \ SingleCompile#GetDefaultOpenCommand() .
            \ ' "$(FILE_TITLE)$.pdf"')
call SingleCompile#ChooseCompiler('tex', '/usr/local/texlive/2019/bin/x86_64-linux/xelatex')
nmap <F6> :SCCompile<CR>
imap <F6> :SCCompile<CR>
let g:livepreview_previewer='zathura'
autocmd Filetype tex,plaintex setl updatetime=1
let g:livepreview_engine='/usr/local/texlive/2019/bin/x86_64-linux/xelatex'
let g:livepreview_cursorhold_recompile=0
set conceallevel=1
let g:tex_conceal='abdmg'
let g:Tex_FoldedSections=''
" =============================================== 插件配置 ===============================================

" colorscheme molokai
" set background=dark
colorscheme mycolor
set t_Co=256                                                    " 開啓256色支持
syntax on
filetype plugin indent on
filetype on
let mapleader=" "                                               " 設置leader鍵爲空格鍵
set nocompatible                                                " 不以兼容模式運行
set encoding=utf-8                                              " utf-8編碼
set helplang=cn                                                 " 中文幫助文檔
set number                                                      " 顯示行號
set wrap                                                        " 自動換行
set showcmd                                                     " 顯示輸入信息
set cursorline                                                  " 顯示光標所在行
set wildmenu                                                    " 顯示補全提示
set hlsearch                                                    " 高亮搜索結果
" set foldenable                                                " 允許摺疊
" set foldmethod=manual                                         " 手動摺疊

" 打開vim運行nohlsearch,取消高亮
exec "nohlsearch"
set ts=4                                                        " 設置tab鍵長度爲四個空格
set expandtab                                                   " 設置tab鍵替換爲四個空格鍵

" 將文件中的tab鍵替換成空格
map <LEADER>    :retab!<CR>
set incsearch                                                   " 一邊輸入一邊高亮
set ignorecase                                                  " 忽略大小寫
set smartcase                                                   " 智能大小寫
set laststatus=2                                                " 設置狀態欄在倒數第2行

" ======================================== 設置狀態欄格式 ========================================
set statusline=%1*\%<%.50F\                                     "顯示文件名和文件路徑
set statusline+=%=%2*\%y%m%r%h%w\ %*                            "顯示文件類型及文件狀態
set statusline+=%3*\%{&ff}\[%{&fenc}]\ %*                       "顯示文件編碼類型
set statusline+=%4*\ row:%l/%L,col:%c\ %*                       "顯示光標所在行和列
set statusline+=%5*\%3p%%\%*                                    "顯示光標前文本所佔總文本的比例
hi User1 cterm=none ctermfg=25 ctermbg=0
hi User2 cterm=none ctermfg=208 ctermbg=0
hi User3 cterm=none ctermfg=169 ctermbg=0
hi User4 cterm=none ctermfg=100 ctermbg=0
hi User5 cterm=none ctermfg=green ctermbg=0
" ======================================== 設置狀態欄格式 ========================================

set mouse=a                                                     " 啓用鼠標
set backspace=indent,eol,start                                  " 退格鍵可以退到上一行
set scrolloff=5                                                 " 光標行上下移動範圍各縮小5行
"set ruler
"set transparency=11

" 設置背景透明
hi Normal ctermfg=252 ctermbg=none
" 尋找下一搜索結果,並將其置於屏幕中心
noremap = nzz
" 尋找上一搜索結果,並將其置於屏幕中心
noremap - Nzz
" 取消高亮
noremap <LEADER><CR> :nohlsearch<CR>
map s <nop>
" 保存
map S :w<CR>
" 退出
map Q :q<CR>
" 右分屏,聚焦右窗口
map sl :set splitright<CR>:vsplit<CR>:e 
" 左分屏,聚焦左窗口
map sh :set nosplitright<CR>:vsplit<CR>:e 
" 上分屏,聚焦上窗口
map sk :set nosplitbelow<CR>:split<CR>:e 
" 下分屏,聚焦下窗口
map sj :set splitbelow<CR>:split<CR>:e 
" 光標移至右窗口
map <LEADER>l <C-w>l
" 光標移至上窗口
map <LEADER>k <C-w>k
" 光標移至下窗口
map <LEADER>j <C-w>j
" 光標移至左窗口
map <LEADER>h <C-w>h
" 窗口上移
map <up> :res +5<CR>
" 窗口下移
map <down> :res -5<CR>
" 窗口左移
map <left> :vertical resize-5<CR>
" 窗口右移
map <right> :vertical resize+5<CR>
" 新建標籤頁
map <C-n> :tabe<CR>
" 前一標籤頁
map t- :-tabnext<CR>
" 後一標籤頁
map t= :+tabnext<CR>
" 重新加載vim配置文件
map rc :source $MYVIMRC<CR>
" 尋找兩個相等的單詞
map <LEADER>fd /\(\<\w\+\>\)\_s*\1
" 替換佔空符<++>
map <LEADER><LEADER> <ESC>/<++><CR>:nohlsearch<CR>c4l
" 全選
map <C-a> ggVG
" 打開我的vimrc
map <LEADER>rc :e ~/.config/nvim/init.vim<CR>
" 複製到系統剪切板
map +y "+y
" 從系統剪切板粘貼
map +p "+p
" 插入模式下jj映射爲<Esc>
inoremap jj <Esc>

set list
set listchars=tab:▸\ ,trail:▫

" ======================================== 自動匹配括號 ========================================
autocmd filetype c,python,vim,conf inoremap <buffer> ( ()<++><ESC>4hi
autocmd filetype c,python,vim,conf inoremap <buffer> ) <c-r>=ClosePair(')')<CR>
autocmd filetype c,python,vim,conf inoremap <buffer> { {}<++><ESC>4hi
autocmd filetype c,python,vim,conf inoremap <buffer> } <c-r>=ClosePair('}')<CR>
autocmd filetype c,python,vim,conf inoremap <buffer> [ []<++><ESC>4hi
autocmd filetype c,python,vim,conf inoremap <buffer> ] <c-r>=ClosePair(']')<CR>
autocmd filetype c,conf inoremap <buffer> " ""<++><ESC>4hi
autocmd filetype c,vim,conf inoremap <buffer> ' ''<++><ESC>4hi
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endfunction
" ======================================== 自動匹配括號 ========================================

let &t_SI = "\<Esc>]50;CursorShape=1\x7" 
let &t_SR = "\<Esc>]50;CursorShape=2\x7" 
let &t_EI = "\<Esc>]50;CursorShape=0\x7" 

" 打開文件,光標回到上次編輯的位置
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" =============================================== 創建文件頭 ===============================================
autocmd BufNewFile *.py,*.tex exec ":call SetTitle()"
func! SetTitle()
    if &filetype == 'python'
        call setline(1,"#!/usr/bin/env python3")
        call append(line("."),"# -*- coding:UTF-8 -*-")
        call append(line(".")+1,"##########################################################################")
        call append(line(".")+2, "# File Name: ".expand("%"))
        call append(line(".")+3, "# Author: stubborn vegeta")
        call append(line(".")+4, "# Created Time: ".strftime("%c"))
        call append(line(".")+5, "##########################################################################")
        call append(line(".")+6, "<++>")
    endif
    if &filetype == 'plaintex'
        call setline(1,"% -*- coding:UTF-8 -*-")
        call append(line("."),"% #########################################################################")
        call append(line(".")+1, "% File Name: ".expand("%"))
        call append(line(".")+2, "% Author: stubborn vegeta")
        call append(line(".")+3, "% Created Time: ".strftime("%c"))
        call append(line(".")+4, "% #########################################################################")
        call append(line(".")+5, "\\documentclass[UTF8]{<++>}")
        call append(line(".")+6, "\\usepackage{graphicx}")
        call append(line(".")+7, "\\usepackage{booktabs}")
        call append(line(".")+8, "\\usepackage{geometry}")
        call append(line(".")+9, "\\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}")
        call append(line(".")+10, "\\pagestyle{plain}")
        call append(line(".")+11, "\\begin{document}")
        call append(line(".")+12, "<++>")
        call append(line(".")+13, "\\end{document}")
    endif
    if &filetype == 'tex'
        call setline(1,"% -*- coding:UTF-8 -*-")
        call append(line("."),"% #########################################################################")
        call append(line(".")+1, "% File Name: ".expand("%"))
        call append(line(".")+2, "% Author: stubborn vegeta")
        call append(line(".")+3, "% Created Time: ".strftime("%c"))
        call append(line(".")+4, "% #########################################################################")
        call append(line(".")+5, "\\documentclass[UTF8]{<++>}")
        call append(line(".")+6, "\\usepackage{graphicx}")
        call append(line(".")+7, "\\usepackage{booktabs}")
        call append(line(".")+8, "\\usepackage{geometry}")
        call append(line(".")+9, "\\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}")
        call append(line(".")+10, "\\pagestyle{plain}")
        call append(line(".")+11, "\\begin{document}")
        call append(line(".")+12, "<++>")
        call append(line(".")+13, "\\end{document}")
    endif
"     normal G 
endfunc
" =============================================== 創建文件頭 ===============================================

" 設置註釋快捷鍵
map <LEADER>' :call Note()<CR>
func! Note()
    if &filetype == 'python'
        normal 0i# 
    endif
    if &filetype == 'vim'
        normal 0i" 
    endif
    if &filetype == 'plaintex'
        normal 0i% 
    endif
    if &filetype == 'tex'
        normal 0i% 
    endif
    if &filetype == 'c'
        normal 0i// 
    endif
endfunc
" 設置取消註釋
map <LEADER>" 0df j

" ========
" ======== coc
" ========
function! s:check_back_space() abort
        let col = col('.') - 1
        return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<Tab>" :
      \ coc#refresh()
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

nmap <silent> gd <Plug>(coc-definition) 
nmap <silent> gy <Plug>(coc-type-definition) 
nmap <silent> gi <Plug>(coc-implementation) 
nmap <LEADER>rn <Plug>(coc-rename)

" ========
" ======== markdown
" ========
" markdown加粗命令
autocmd filetype markdown inoremap <buffer> ,b **** <++><ESC>F*hi
" markdown斜體
autocmd filetype markdown inoremap <buffer> ,i ** <++><ESC>F*i
" markdown插入圖片
autocmd filetype markdown inoremap <buffer> ,f [外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-sYXhYUHv-1569758460414)(<++>)]<ESC>F[a
" markdown插入鏈接
autocmd filetype markdown inoremap <buffer> ,l [](<++>)<Esc>F[a
" markdown插入數學公式
autocmd filetype markdown inoremap <buffer> ,m $$<CR><CR>$$ <++><Esc>ki
" markdown插入代碼塊
autocmd filetype markdown inoremap <buffer> ,c ```<CR>```<++><Esc>k$a
" markdown插入圖片(html)
autocmd filetype markdown inoremap <buffer> ,h <Esc>:call Imagehtml()<CR>2jf"a
function! Imagehtml()
        if &filetype == 'markdown'
                call append(line("."), "<center>")
                call append(line(".")+1, "<img src=\"\" alt=\"<++>\" height=\"50%\" width=\"50%\" />")
                call append(line(".")+2, "</center>")
        endif
endfunction
autocmd filetype markdown map <buffer> ; :call InsertString()<CR>
function! InsertString()
        if getline(".")[col(".")-2] == '|'
                normal i <++> | 
        else
                normal i| <++> | 
        endif
endfunction

autocmd filetype markdown inoremap <buffer> ,t <ESC>:call InsertTable()<CR>
function! InsertTable()
        call append(line("."), "| <++> | <++> | ")
        call append(line(".")+1, "| :--: | :--: | ")
        call append(line(".")+2, "| <++> | <++> | ")
endfunction

autocmd filetype markdown map <buffer> 3t :call InsertTable3()<CR>
function! InsertTable3()
        call append(line("."), "| <++> | <++> | <++> | ")
        call append(line(".")+1, "| :--: | :--: | :--: | ")
        call append(line(".")+2, "| <++> | <++> | <++> | ")
endfunction

" =======
" ======= LaTeX
" =======
autocmd filetype tex,plaintex inoremap <buffer> ,1 \section{}<CR><++><Esc>kf{a
autocmd filetype tex,plaintex inoremap <buffer> ,2 \subsection{}<CR><++><Esc>kf{a
autocmd filetype tex,plaintex inoremap <buffer> ,3 \subsubsection{}<CR><++><Esc>kf{a
autocmd filetype tex,plaintex inoremap <buffer> ,b \textbf{}<++><Esc>4hi
autocmd filetype tex,plaintex inoremap <buffer> ,i \textit{}<++><Esc>4hi
autocmd filetype tex,plaintex inoremap <buffer> ,f \begin{figure}[<++>]<CR>\centering<CR>\includegraphics[scale=<++>]{<++>}<CR>\caption{<++>}<CR>\end{figure}<CR><++><Esc>5k
autocmd filetype tex,plaintex inoremap <buffer> ,t \begin{table}<CR>\centering<CR>\caption{<++>}<CR>\begin{tabular}{<++>}<CR><++><CR>\end{tabular}<CR>\end{table}<CR><++><Esc>7k
autocmd filetype tex,plaintex inoremap <buffer> ,m \[<CR><CR>\]<CR><CR><++><Esc>3ki
autocmd filetype tex,plaintex inoremap <buffer> ,e \begin{equation}<CR><CR>\end{equation}<Esc>0kk
autocmd filetype tex,plaintex inoremap <buffer> <F1> \begin{<++>}<CR><CR>\end{<++>}<Esc>0kk
autocmd filetype tex,plaintex nmap <buffer> <F10> :LLPStartPreview<CR>
" autocmd filetype tex,plaintex nmap <buffer> <F10> :call Tex_ViewLaTeX()<CR>

" =======
" ======= python
" =======
autocmd filetype python inoremap <buffer> ,' """<CR><CR>"""<CR><++><Esc>2ki

" =======
" ======= runcode
" =======
map <F5> :call RunCode()<CR>
func! RunCode()
    exec "w"
    if &filetype == 'python'
            if search("@profile")
                    exec "AsyncRun kernprof -l -v %"
                    exec "copen"
                    exec "wincmd p"
             elseif search("set_trace()")
                     exec "!python3 %"
             else
                    exec "AsyncRun -raw python3 %"
                    exec "copen"
                    exec "wincmd p"
            endif
    endif

    if &filetype == 'dot'
    exec "!dot % -T png -o %.png"
    exec "!feh %.png"
    endif

    if &filetype == 'markdown'
        exec "MarkdownPreview"
    endif
endfunc

我的github:demonlord1997/nvim-config

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章