vim 的签名配置.

vim 的签名配置.

今天想到每次都写一些东西挺麻烦的,就查了一下,果然有这个。

比如可以在~/.vimrc里面写入

autocmd BufNewFile *.py,*.sh exec ":call SetPy()"

func SetPy()
    call setline(1, "# ===========================================")
    call append(line("."), "# --coding:UTF-8 --")
    call append(line(".")+1, "# file: ".expand("%:t"))
    call append(line(".")+2, "# author: ZhengPengkun")
    call append(line(".")+3, "# date: ".strftime("%Y-%m-%d"))
    call append(line(".")+4, "# email: pkzhengmath@pku.edu.cn")
    call append(line(".")+5, "# description: ")
    call append(line(".")+6, "# ===========================================")
    call append(line(".")+7, "")
    call append(line(".")+8, "")
    call append(line(".")+9, "")
    call append(line(".")+10, "def main():")
    call append(line(".")+11, "")
    call append(line(".")+12, "")
    call append(line(".")+13, "")
    call append(line(".")+14, "")
    call append(line(".")+15, "")
    call append(line(".")+16, "")
    call append(line(".")+17, "if __name__ == '__main__':")
    call append(line(".")+18, "    main()")

endfunc

然后再新建.py或者.sh文件的时候就可以出现像下面这种的。

# ===========================================
# --coding:UTF-8 --
# file: h.py
# author: pzk
# date: 2019-01-08
# email: beyondpzk@outlook.com
# description: 
# ===========================================



def main():






if __name__ == '__main__':
    main()

当然也可以对于其他的也可以,类似的按照上面的语法来写就可以了。

像IDE一样的文件树结构

可以使用NerdTree插件,可以详细参考 https://segmentfault.com/a/1190000015143474 确实挺方便的, 还有这一个 https://www.cnblogs.com/kavlez/p/vimrc-tips.html这里面的辅助NerdTree的插件也非常地赞. 关于这个插件常用的命令:

  • o

像IDE一样不用按一个key就能运行该文件

” 运行文件 map :w:r!python3 %

另外一个自动补全

filetype plugin on let g:pydiction_location = ‘~/.vim/tools/pydiction/complete-dict’

这个和YCM那个不一样,这个是在当前的代码里面去找的,

这个写的也很好 https://www.cnblogs.com/qkqBeer/articles/9565858.html

https://www.cnblogs.com/thinheader/p/9467065.html 这个里面有一键配置

跳转推荐使用

在vimrc 里加入 map :YcmCompleter GoTo

使用方法是 把光标定位到变量或者函数的地方,按F6, 参考的这一个blog https://www.cnblogs.com/demo-lv/p/12672296.html, 这里面介绍的还有一个debug的功能,NB。

其它

运行 :r!command , command命令的结果插入光标下一行 :nr! command, command命令的结果插入n行后。

这里还有 几个很值得用的 https://zhuanlan.zhihu.com/p/145793963

关于autopep8 , https://vimjc.com/vim-autopep8-plugin.html

我目前使用的

syntax on
set cursorline
set encoding=utf8
set ts=4
set sts=4
set expandtab
set shiftwidth=4
set nu
set hlsearch
set showmatch
set bg=dark

filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Lokaltog/vim-powerline'
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'majutsushi/tagbar'
Plugin 'vim-scripts/ctags.vim'
Plugin 'tell-k/vim-autopep8'
"补全括号
Plugin 'jiangmiao/auto-pairs'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
" 方便注释的
Plugin 'preservim/nerdcommenter'
"python 自动补全
Plugin 'davidhalter/jedi-vim'
call vundle#end()
filetype plugin indent on
filetype plugin on
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

"另外一个自动补全
filetype plugin on
let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'

"打开
map <F3> :NERDTreeMirror<CR>
"关闭
map <F3> :NERDTreeToggle<CR>
"自动开启Nerdtree
"autocmd vimenter * NERDTree
let NERDTreeShowBookmarks=1
let g:NERDTreeWinSize = 25
"设定 NERDTree 视窗大小
"开启/关闭nerdtree快捷键
"map <C-f> :NERDTreeToggle<CR>
" 开启Nerdtree时自动显示Bookmarks
"打开vim时如果没有文件自动打开NERDTree
autocmd vimenter * if !argc()|NERDTree|endif
"当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"设置树的显示图标
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
"过滤所有.pyc文件不显示
let NERDTreeIgnore = ['\.pyc$', '__pycache__', '\.swp']
" 是否显示行号
"let g:NERDTreeShowLineNumbers = 1
"不显示隐藏文件
let g:NERDTreeHidden=0
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
"下面是tagbar的配置
let g:tagbar_width = 30
map <F4> :TagbarToggle<CR>
let g:tagbar_autopreview = 1
let g:tagbar_sort = 0

" 运行文件
map <F5> :w<cr>:r!python3 %<cr>
" 跳转
map <F6> :YcmCompleter GoTo<CR>
"airline的配置
set laststatus=2  "永远显示状态栏
let g:airline_powerline_fonts = 1  " 支持 powerline 字体
let g:airline#extensions#tabline#enabled = 1 " 显示窗口tab和buffer
let g:airline_theme='murmur'  " murmur配色不错
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_left_sep = '▶'
let g:airline_left_alt_sep = '❯'
let g:airline_right_sep = '◀'
let g:airline_right_alt_sep = '❮'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'

" auto-pairs's settings
au Filetype FILETYPE let b:AutoPairs = {"(": ")"}
au FileType php      let b:AutoPairs = AutoPairsDefine({'<?' : '?>', '<?php': '?>'})

"autopep8设置"
let g:autopep8_disable_show_diff=1

"NERDCommenter的注释
map <F1> <leader>ci <CR>
"Auto8
autocmd FileType python noremap <buffer> <F8> :call Autopep8()<CR>


打赏,谢谢~~

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,多谢支持~

打开微信扫一扫,即可进行扫码打赏哦