vimtk插件的Python后端
项目描述
描述
本软件包中的工具专注于,但不仅限于使用gVim进行Python开发。这是一个Vim插件,也是一个可pip安装的Python模块。
使用方法
我们建议使用vim-plug来管理插件。安装vim plug的方式如下
# Install vim-plug into your autoload directory
" See: https://github.com/junegunn/vim-plug
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
我们建议以下vimrc作为模板
" DEMO_VIMRC:
call plug#begin('~/.vim/bundle')
Plug 'Erotemic/vimtk'
call plug#end() " required
filetype plugin indent on
syntax on
"""" The above code should be among the first things in your vimrc
" Map your leader key to comma (much easier to hit)
let mapleader = ","
let maplocalleader = ","
noremap \ ,
" Make default vimtk remaps
:call VimTK_default_remap()
" Register files you use all the time with quickopen
" (use <leader>i<char> as a shortcut to specific files
call vimtk#quickopen(',', '~/.vimrc')
call vimtk#quickopen('5', '~/.bashrc')
此模块定义了许多辅助函数,但默认情况下不会将它们绑定到键上,除非调用VimTK_default_remap。默认绑定如下
noremap <leader>H :call vimtk#helloworld()<Esc>
noremap <leader>a :call vimtk#execute_text_in_terminal(mode())<CR>
vnoremap <leader>a :call vimtk#execute_text_in_terminal(visualmode())<CR>
noremap <leader>m :call vimtk#execute_text_in_terminal('word')<CR>
noremap <leader>C :call vimtk#copy_current_fpath()<Esc>
noremap <leader>M :call vimtk#ipython_import_all()<CR>
command! AutoImport call vimtk#insert_auto_import()
noremap <leader>pv :call vimtk#insert_print_var_at_cursor()<CR>
noremap <c-M-B> :call vimtk#insert_timerit(mode())<CR><Esc>
vnoremap <c-M-B> :call vimtk#insert_timerit(visualmode())<CR><Esc>
noremap <leader>es :call vimtk#smart_search_word_at_cursor()<CR>
noremap <leader>go :call vimtk#open_path_at_cursor("e")<CR>
noremap <leader>gf :call vimtk#open_path_at_cursor("e")<CR>
noremap <leader>gi :call vimtk#open_path_at_cursor("split")<CR>
noremap <leader>gv :call vimtk#open_path_at_cursor("vsplit")<CR>
noremap <leader>gv :call vimtk#open_path_at_cursor("vsplit")<CR>
noremap <leader>gt :call vimtk#open_path_at_cursor("tabe")<CR>
noremap gi :call vimtk#open_path_at_cursor("split")<CR>
" Doctest editing
vnoremap gd :call vimtk#py_format_doctest()<CR>
vnoremap gu :call vimtk#py_unformat_doctest()<CR>
显然,您可以按需修改确切的键绑定。
以下是一些这些函数的作用
vimtk#execute_text_in_terminal - 复制当前单词、行或可视选择,并在您最近使用的终端(可能是运行IPython或bash)中执行它,无需切换标签或复制粘贴。默认绑定是<leader>a用于当前行或可视选择,<leader>m用于单词。
vimtk#ipython_import_all - 如果你在Python模块中,此函数将创建几行代码,将这些模块中的所有内容导入当前命名空间。请注意,它检测你是否需要修改pythonpath,并执行该操作。它完全忽略__all__。这些行将在你的终端中执行(可能是一个IPython会话)。默认绑定是<leader>M。
vimtk#copy_current_fpath - 将当前文件的路径复制到剪贴板。在非Windows上,家用驱动器将被替换为~。默认绑定是<leader>C。
vimtk#auto_import - 自动插入缺少的Python导入。
vimtk#insert_print_var_at_cursor - 在当前光标所在的变量周围插入打印语句(支持python、bash、cmake和C++)。默认绑定是<leader>pv用于repr表示,<leader>ps用于ubelt repr2表示。
vimtk#insert_timerit - 创建一个stub timerit并在当前位置插入。
vimtk#open_path_at_cursor - 在光标处打开文件路径或网页URL。
vimtk#quickopen(char, fpath) - 使用<leader>[tvio]`打开预定义的文件/目录。
vimtk#py_format_doctest - 默认绑定到<visual-select> gd。在视觉选定的代码之前插入doctest >>>前缀。
vimtk#py_unformat_doctest - 默认绑定到<visual-select> gu。从视觉选定的代码之前删除doctest >>>前缀。
备选VIMRC
注意:要获取所有功能,你需要以下包
# The <leader>a ability requires xdotool and wmctrl on linux systems
sudo apt install xdotool wmctrl ctags
# vimtk requires ubelt in whichever environment it is running
pip install ubelt --user
# There are also third party python packages needed for some functions
pip install pyperclip pyflakes xinspect psutil --user
# On windows you should also install pywinauto
pip install pywinauto --user
注意:关于这些包安装到哪个Python环境和Vim使用哪个Python环境有一些问题。我们正在努力解决这些问题。欢迎提交错误报告和补丁!
" VimTK Recommended VimRC:
" References: https://github.com/Erotemic/vimtk
"""""""""""""""
" # Automatically install vim-plug into your autoload directory
" " See: https://github.com/junegunn/vim-plug
"""""""""""""""
if empty(glob('~/.vim/autoload/plug.vim'))
" Automatic installation if vim plug does not exist
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Enable normal windows hotkeys like: ctrl+c, ctrl+v, ctrl+a, etc...
source $VIMRUNTIME/mswin.vim
behave mswin
set nocompatible
filetype off
"source $VIMRUNTIME/mswin.vim
"behave mswin
set encoding=utf8
call plug#begin('~/.vim/bundle')
Plug 'sjl/badwolf'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'vim-syntastic/syntastic'
Plug 'majutsushi/tagbar'
Plug 'ervandew/supertab'
Plug 'Erotemic/vimtk'
call plug#end() " required
filetype plugin indent on
syntax on
"""" The above code should be among the first things in your vimrc
scriptencoding utf-8
set encoding=utf-8
" References: https://vi.stackexchange.com/questions/13034/automatic-whitespace-in-python
" ---- Minimal configuration:
set smartindent " Do smart autoindenting when starting a new line
set shiftwidth=4 " Set number of spaces per auto indentation
set expandtab " When using <Tab>, put spaces instead of a <tab> character
" ---- Good to have for consistency
set tabstop=4 " Number of spaces that a <Tab> in the file counts for
set smarttab " At <Tab> at beginning line inserts spaces set in shiftwidth
" Highlight search regexes
set incsearch
set hlsearch
" Disable swap files, which prevents annoying messages when you open the
" same file twice
set noswapfile
" Use a colorscheme (murphy is builtin, but I like badwolf)
colorscheme badwolf
"colorscheme murphy
" Map your leader key to comma (much easier to hit)
let mapleader = ","
let maplocalleader = ","
noremap \ ,
" Search and replace under cursor
noremap <leader>ss :%s/\<<C-r><C-w>\>/
"Surround word with quotes
noremap <leader>qw ciw'<C-r>"'<Esc>
noremap <leader>qc ciw`<C-r>"`<Esc>
" Reload your vimrc
noremap <leader>R :source ~/.vimrc<CR>
" Window navication
" Alt + jklh
map <silent><A-j> <c-w>j
map <silent><A-k> <c-w>k
map <silent><A-l> <c-w>l
map <silent><A-h> <c-w>h
" Control + jklh
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
" Move in split windows
" Press leader twice to move between windows
noremap <leader>, <C-w>w
map <c-h> <c-w>h
" Fast nerd tree access
noremap <C-T> :NERDTree<CR>
noremap <leader>. :NERDTree<CR>
noremap <leader>h :NERDTreeToggle<CR>
"noremap <leader>h :Tlist<CR>
noremap <leader>j :Tagbar<CR>
"set autochdir
" better version of autochdir that changes cwd to be at the current file
autocmd BufEnter * silent! lcd %:p:h
" Note: to use vimtk I think we need to have ubelt installed
" or get some sort of install-hook pip install command to happen
" We can hack around this by explicitly sourcing the vimtk plugin
source $HOME/.vim/bundle/vimtk/plugin/vimtk.vim
" Make default vimtk remaps.
:call VimTK_default_remap()
" Swap colon and semicolon
:call vimtk#swap_keys(':', ';')
" Register files you use all the time with quickopen
" (use <leader>i<char> as a shortcut to specific files
:call vimtk#quickopen(',', '~/.vimrc')
:call vimtk#quickopen('5', '~/.bashrc')
项目详情
下载文件
为你的平台下载文件。如果你不确定要选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
vimtk-0.3.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 48b730fe1d0832da10e8775d461acad02bb78fbc6f7dd7f0db628e212cc58a21 |
|
MD5 | 20ad3d5725f35f9595006f11e5599184 |
|
BLAKE2b-256 | af0a4e74ac69f287f5f542322268a881464cc510c9a34697c243b89a2a267df3 |