美文网首页
.vimrc.vim

.vimrc.vim

作者: swynner | 来源:发表于2018-06-22 10:05 被阅读0次

    .vimrc配置

    
    " Startup {{{
    filetype indent plugin on
    
    
    " vim 文件折叠方式为 marker
    augroup ft_vim
        au!
    
        au FileType vim setlocal foldmethod=marker
    augroup END
    " }}}
    
    " General {{{
    set nocompatible
    set nobackup
    set noswapfile
    set history=1024
    set autochdir
    set whichwrap=b,s,<,>,[,]
    set nobomb
    set backspace=indent,eol,start whichwrap+=<,>,[,]
    " Vim 的默认寄存器和系统剪贴板共享
    set clipboard+=unnamed
    " 设置 alt 键不映射到菜单栏
    set winaltkeys=no
    " }}}
    
    
    " Lang & Encoding {{{
    set fileencodings=utf-8,gbk2312,gbk,gb18030,cp936
    set encoding=utf-8
    set langmenu=zh_CN
    let $LANG = 'en_US.UTF-8'
    "language messages zh_CN.UTF-8
    " }}}
    
    " GUI {{{
    " colorscheme Tomorrow-Night
    
    source $VIMRUNTIME/delmenu.vim
    source $VIMRUNTIME/menu.vim
    set cursorline
    set hlsearch
    set number
    " 窗口大小
    set lines=35 columns=140
    " 分割出来的窗口位于当前窗口下边/右边
    set splitbelow
    set splitright
    "不显示工具/菜单栏
    set guioptions-=T
    set guioptions-=m
    set guioptions-=L
    set guioptions-=r
    set guioptions-=b
    " 使用内置 tab 样式而不是 gui
    set guioptions-=e
    set nolist
    " set listchars=tab:▶\ ,eol:¬,trail:·,extends:>,precedes:<
    set guifont=Inconsolata:h12:cANSI
    " }}}
    
    
    " Format {{{
    set autoindent
    set smartindent
    set tabstop=4
    set expandtab
    set softtabstop=4
    set foldmethod=indent
    syntax on
    " }}}
    
    
    " Keymap {{{
    let mapleader=","
    
    nmap <leader>s :source ~/.vimrc<cr>
    nmap <leader>e :e ~/.vimrc<cr>
    
    map <leader>tn :tabnew<cr>
    map <leader>tc :tabclose<cr>
    map <leader>th :tabp<cr>
    map <leader>tl :tabn<cr>
    
    " 移动分割窗口
    nmap <C-j> <C-W>j
    nmap <C-k> <C-W>k
    nmap <C-h> <C-W>h
    nmap <C-l> <C-W>l
    
    " 正常模式下 alt+j,k,h,l 调整分割窗口大小
    nnoremap <M-j> :resize +5<cr>
    nnoremap <M-k> :resize -5<cr>
    nnoremap <M-h> :vertical resize -5<cr>
    nnoremap <M-l> :vertical resize +5<cr>
    
    " 插入模式移动光标 alt + 方向键
    inoremap <M-j> <Down>
    inoremap <M-k> <Up>
    inoremap <M-h> <left>
    inoremap <M-l> <Right>
    
    " IDE like delete
    inoremap <C-BS> <Esc>bdei
    
    nnoremap vv ^vg_
    " 转换当前行为大写
    inoremap <C-u> <esc>mzgUiw`za
    " 命令模式下的行首尾
    cnoremap <C-a> <home>
    cnoremap <C-e> <end>
    
    nnoremap <F2> :setlocal number!<cr>
    nnoremap <leader>w :set wrap!<cr>
    
    imap <C-v> "+gP
    vmap <C-c> "+y
    vnoremap <BS> d
    vnoremap <C-C> "+y
    vnoremap <C-Insert> "+y
    imap <C-V>        "+gP
    map <S-Insert>        "+gP
    cmap <C-V>        <C-R>+
    cmap <S-Insert>        <C-R>+
    
    exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
    exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
    
    " 打开当前目录 windows
    map <leader>ex :!start explorer %:p:h<CR>
    
    " 打开当前目录CMD
    map <leader>cmd :!start<cr>
    " 打印当前时间
    map <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
    
    " 复制当前文件/路径到剪贴板
    nmap ,fn :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
    nmap ,fp :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>
    
    " 设置切换Buffer快捷键"
    nnoremap <C-left> :bn<CR>
    nnoremap <C-right> :bp<CR>
    
    " }}}
    
    
    " Function {{{
    " Remove trailing whitespace when writing a buffer, but not for diff files.
    " From: Vigil
    " @see http://blog.bs2.to/post/EdwardLee/17961
    function! RemoveTrailingWhitespace()
        if &ft != "diff"
            let b:curcol = col(".")
            let b:curline = line(".")
            silent! %s/\s\+$//
            silent! %s/\(\s*\n\)\+\%$//
            call cursor(b:curline, b:curcol)
        endif
    endfunction
    autocmd BufWritePre * call RemoveTrailingWhitespace()
    " }}}
    
    
    "常用命令备忘{{{
    
    "去除查找后高亮
    ":nohl
    
    
    "去除重复行,查找相同的两行,先将内容排序,然后查找前一行等于后一行者
    ":sort
    ":/^\(.\+\)$\n\1t
    
    "查找相同的两行,先将内容排序,然后用g/d删除,g命令查找到匹配的两行,然后定位到第二行,使用/d命令删除当前行
    ":sort
    ":g/^\(.\+\)$\n\1/d
    
    "查找第一个单词相同的两行,然后把第二行删除,比如规整字典文件,需要把重复的单词解释删除
    ":sort
    ":g/^\(.*\)\( \+\)\(.*\)$\n\1\2/d
    ":g/^\(\S\+\)\( \+\)\(\S\+\)\(.*\)$\n\1\2/d
    
    "去除行尾空格、tab之类的
    ":%s/\s\+$//
    
    "命令行窗口。
    "在正常模式下,输入'q:',就打开了命令行窗口。可以正常编辑
    
    "常用命令:
    "yy复制一行,dd删除一行,p黏贴
    "键功能
    "i 在光标左侧输入文本
    "I 在当前行的行首输入文本
    "a 在光标右侧输入文本
    "A 在当前行的行尾输入文本
    "o 在当前行的下一行添加一个空行,光标放在新行的行首
    "O 在当前行的上一行添加一个空行,光标放在新行的行首
    "
    
    ":vimgrep <pattern> <files>在文件中搜索模式<pattern>
    ":比如在当前目录所有.cpp文件中搜索abc:
    ":vimgrep abc *.cpp
    "如果想搜索子目录,是这样
    ":vimgrep abc **/*.cpp
    "搜索当前文件
    ":vimgrep /abc/%
    "出来的结果在quickfix窗口,用命令:cw呼出
    
    
    "}}}
    
    
    "for python {{{
    
    "缩进指示线
    let g:indentLine_char="|"
    let g:indentLine_enabled = 1
    " Vim
    let g:indentLine_color_term = 239
    "GVim
    let g:indentLine_color_gui = '#A4E57E'
    
    "autopep8设置
    "let g:autopep8_disable_show_diff=1
    
    
    "Python解释器设置:绑定Python解释器,一键F6编译、F5运行。
    
    "make直接使用python运行即可,F6运行是可以分析python.exe输出信息
    "autocmd BufRead *.py set makeprg=python\ %
    "autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
    "autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
    "autocmd BufRead *.py nmap <F5> :w!<CR>:!python %<CR>
    "autocmd BufRead *.py nmap <F6> :w!<CR>:make<CR>
    
    "如果是py文件,则同时打开编译信息窗口
    "autocmd BufRead *.py copen
    
    "按F5运行python
    map <F5> :w<CR> :call RunPython()<CR>
    function! RunPython()
      let mp = &makeprg
      let ef = &errorformat
      let exeFile = expand("%:t")
      setlocal makeprg=python\ -u
      set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
      silent make %
      copen
      let &makeprg = mp
      let &errorformat = ef
    endfunction
    
    "}}}
    
    
    "for markdown {{{
    
    "设置markdown折叠
    let g:vim_markdown_folding_level = 6
    let g:vim_markdown_folding_disabled = 1
    
    "Markdown文件格式化
    "使用如下命令进行空行转换,markdown文件中使用两个以上空行作为分行
    "\/n\/r/r\g
    "函数实现如下
    function! MD_Format()
        ":%s/\n/\r\r/g
        :set ic
        :%s/\(^chapter\)/##\1/g
        :w
    endfunction
    
    "在md文件行首增加文件名作为标题
    function! MD_Addtitle()
        call append(0,"#<center>".expand("%:r")."<\/center>")
        call append(1,"")
        call append(2,"")
        "call append(line("."),"*   Copyright (C) ".strftime("%Y")." All rights reserved.")
    endfunction
    
    "查询可能的章节标题行
    function! MD_searchTags()
        ":vimgrep /^#*\(chapter\|\d\+\|prologue\|copyright\|dedication\)/%
        :vimgrep /^#*\*\*Contents/%
        :vimgrepadd /^#*chapter/%
        :vimgrepadd /^#*prologue/%
        :vimgrepadd /^#*part/%
        :vimgrepadd /^#*copyright/%
        :vimgrepadd /^#*dedication/%
        :vimgrepadd /^#*\d\+/%
        :cw
    endfunction
    
    "保证标题居中,可以前后添加<center>#title text</center>
    
    "转换markdwon文件为pdf,调用calibre中的ebook-convert.exe把当前的文件转换为pdf,命令如下
    "!"c:\Program Files (x86)\Calibre2\ebook-convert.exe" "%:p" "%:p:h\temppp.pdf" --remove-paragraph-spacing --margin-top=30 --margin-left=30  --margin-right=30  --margin-bottom=30"
    
    "函数实现
    function! MD_ToPdf()
        ""c:\Program Files (x86)\Calibre2\ebook-convert.exe" "d:\temp\thegravebook - Wei Zhi.md" "d:\temp\aa.pdf"
        let p1="\"c:\\Program Files (x86)\\Calibre2\\ebook-convert.exe\""
    
        let from_file="\"".expand('%:p')."\""
        echo from_file
    
    
    
        let to_file="\"".expand('%:p:h')."\\".expand('%:t:r').".pdf"."\""
        echo to_file
    
        let option_file="--remove-paragraph-spacing --margin-top=30 --margin-left=30  --margin-right=30  --margin-bottom=30"
    
        let command_line= p1." ".from_file." ".to_file." ".option_file
        echo command_line
        execute "!" . command_line
    endfunction
    nmap <F2> GoDate: <Esc>
    " }}}
    
    

    相关文章

      网友评论

          本文标题:.vimrc.vim

          本文链接:https://www.haomeiwen.com/subject/cjfcyftx.html