Package: vimtk
DescriptionThe tools in this package focus on, but are not exclusive to Python development
with gVim.  This is both a Vim plugin and a pip installable Python module.UsageWe suggest using vim-plug to manage plugins. Install vim plug like this:# 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.vimWe suggest the following vimrc as a template:" DEMO_VIMRC:callplug#begin('~/.vim/bundle')Plug'Erotemic/vimtk'callplug#end()" requiredfiletypeplugin indentonsyntaxon"""" The above code should be among the first things in your vimrc" Map your leader key to comma (much easier to hit)letmapleader=","letmaplocalleader=","noremap\," Make default vimtk remaps:callVimTK_default_remap()" Register files you use all the time with quickopen" (use <leader>i<char> as a shortcut to specific filescallvimtk#quickopen(',','~/.vimrc')callvimtk#quickopen('5','~/.bashrc')This module defines many helper functions, but does not bind them to keys by
default unlessVimTK_default_remapis called. The default bindings are as
follows:noremap<leader>H :callvimtk#helloworld()<Esc>noremap<leader>a:callvimtk#execute_text_in_terminal(mode())<CR>vnoremap<leader>a:callvimtk#execute_text_in_terminal(visualmode())<CR>noremap<leader>m:callvimtk#execute_text_in_terminal('word')<CR>noremap<leader>C :callvimtk#copy_current_fpath()<Esc>noremap<leader>M :callvimtk#ipython_import_all()<CR>command!AutoImportcallvimtk#insert_auto_import()noremap<leader>pv :callvimtk#insert_print_var_at_cursor()<CR>noremap<c-M-B>:callvimtk#insert_timerit(mode())<CR><Esc>vnoremap<c-M-B>:callvimtk#insert_timerit(visualmode())<CR><Esc>noremap<leader>es :callvimtk#smart_search_word_at_cursor()<CR>noremap<leader>go:callvimtk#open_path_at_cursor("e")<CR>noremap<leader>gf :callvimtk#open_path_at_cursor("e")<CR>noremap<leader>gi :callvimtk#open_path_at_cursor("split")<CR>noremap<leader>gv :callvimtk#open_path_at_cursor("vsplit")<CR>noremap<leader>gv :callvimtk#open_path_at_cursor("vsplit")<CR>noremap<leader>gt :callvimtk#open_path_at_cursor("tabe")<CR>noremapgi :callvimtk#open_path_at_cursor("split")<CR>" Doctest editingvnoremapgd:callvimtk#py_format_doctest()<CR>vnoremapgu :callvimtk#py_unformat_doctest()<CR>Obviously you can modify the exact key bindings however you would like.Here is what some of these functions do:vimtk#execute_text_in_terminal- copies the current word, line, or visual
selection and executes it in your most recently used terminal (perhaps
running IPython or bash) without needing to alt-tab or copy paste.
Default binding is<leader>afor the current line or visual selection and<leader>mfor a word.vimtk#ipython_import_all- if you are in a python module, this funciton
creates a few lines of code that will import everything in this module into
the current namespace. Note, it detects if you need to modify your pythonpath
and does that.  It also completely disregards__all__. These lines are
then executed in your terminal (which should probably be an IPython session).
Default binding is<leader>M.vimtk#copy_current_fpath- Copies the path to the current file into the
clipboard. On non-windows the home drive is replaced with~. Default
binding is<leader>C.vimtk#auto_import- Automatically inserts missing Python imports.vimtk#insert_print_var_at_cursor- Insert a print statement around the
current variable your cursor is on (supports python, bash, cmake, and C++)
Default binding is<leader>pvfor a repr representation and<leader>psfor a ubelt repr2 representation.vimtk#insert_timerit- Make a stub timerit and insert it at the current
positionvimtk#open_path_at_cursor- Open a file path or web url at your cursor.vimtk#quickopen(char, fpath)- Use<leader>[tvio]`to open predefined
files / directoriesvimtk#py_format_doctest- Default binding to <visual-select>gd.
Inserts the doctest>>>prefix before the visually selected code.vimtk#py_unformat_doctest- Default binding to <visual-select>gu.
Removes the doctest>>>prefix before the visually selected code.Alternate VIMRCNote to get all the features, you need the following packages:# The <leader>a ability requires xdotool and wmctrl on linux systemssudoaptinstallxdotoolwmctrlctags# vimtk requires ubelt in whichever environment it is runningpipinstallubelt--user# There are also third party python packages needed for some functionspipinstallpyperclippyflakesxinspectpsutil--user# On windows you should also install pywinautopipinstallpywinauto--userNote: there have been some issues regarding which Python environment these
pacakges are installed to and which Python environment is used by Vim. We are
working to resolve these issues. Bug reports and patches are welcome!" VimTK Recommended VimRC:" References: https://github.com/Erotemic/vimtk"""""""""""""""" # Automatically install vim-plug into your autoload directory" " See: https://github.com/junegunn/vim-plug"""""""""""""""ifempty(glob('~/.vim/autoload/plug.vim'))" Automatic installation if vim plug does not existsilent!curl-fLo~/.vim/autoload/plug.vim--create-dirs\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vimautocmdVimEnter* PlugInstall--sync|source $MYVIMRCendif" Enable normal windows hotkeys like: ctrl+c, ctrl+v, ctrl+a, etc...source $VIMRUNTIME/mswin.vimbehave mswinsetnocompatiblefiletypeoff"source $VIMRUNTIME/mswin.vim"behave mswinsetencoding=utf8callplug#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'callplug#end()" requiredfiletypeplugin indentonsyntaxon"""" The above code should be among the first things in your vimrcscriptencodingutf-8setencoding=utf-8" References: https://vi.stackexchange.com/questions/13034/automatic-whitespace-in-python" ---- Minimal configuration:setsmartindent" Do smart autoindenting when starting a new linesetshiftwidth=4" Set number of spaces per auto indentationsetexpandtab" When using <Tab>, put spaces instead of a <tab> character" ---- Good to have for consistencysettabstop=4" Number of spaces that a <Tab> in the file counts forsetsmarttab" At <Tab> at beginning line inserts spaces set in shiftwidth" Highlight search regexessetincsearchsethlsearch" Disable swap files, which prevents annoying messages when you open the" same file twicesetnoswapfile" Use a colorscheme (murphy is builtin, but I like badwolf)colorschemebadwolf"colorscheme murphy" Map your leader key to comma (much easier to hit)letmapleader=","letmaplocalleader=","noremap\," Search and replace under cursornoremap<leader>ss:%s/\<<C-r><C-w>\>/"Surround word with quotesnoremap<leader>qw ciw'<C-r>"'<Esc>noremap<leader>qc ciw`<C-r>"`<Esc>" Reload your vimrcnoremap<leader>R :source~/.vimrc<CR>" Window navication" Alt + jklhmap<silent><A-j><c-w>jmap<silent><A-k><c-w>kmap<silent><A-l><c-w>lmap<silent><A-h><c-w>h" Control + jklhmap<c-j><c-w>jmap<c-k><c-w>kmap<c-l><c-w>l" Move in split windows" Press leader twice to move between windowsnoremap<leader>,<C-w>wmap<c-h><c-w>h" Fast nerd tree accessnoremap<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 fileautocmdBufEnter*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 pluginsource $HOME/.vim/bundle/vimtk/plugin/vimtk.vim" Make default vimtk remaps.:callVimTK_default_remap()" Swap colon and semicolon:callvimtk#swap_keys(':',';')" Register files you use all the time with quickopen" (use <leader>i<char> as a shortcut to specific files:callvimtk#quickopen(',','~/.vimrc'):callvimtk#quickopen('5','~/.bashrc')