sponsor Vim development Vim logo Vim Book Ad

tagport : Find and yank Python import statement for keyword under cursor.

 script karma  Rating 1/1, Downloaded by 559  Comments, bugs, improvements  Vim wiki

created by
Phui-Hock Chang
 
script type
ftplugin
 
description
A simple script that finds the Python module using the keyword under the cursor and yank the import statement into the unnamed register "" so you can put it anywhere with the command 'p'.


Usage
=====

1. Move cursor to a word you'd like to import.

2. Type ``<Leader>fi``

3. You'll be prompted with a list of import statements to yank into unnamed register ``'"'``.

4. Type a number.

5. Put the import statement anywhere you like with ``p``.  *Tip: quickly jump back to last cursor position with `` (double backticks)*


Options
=======
let g:tagport_aliases = {}
    There are times when importing from a different package is preferred as apposed to the actual Python module the class is defined.
    For example, Django's ``Model`` is declared in ``django.db.models.base``. However, it is a common practice that ``Model``
    is imported from ``django.db.models`` instead.

    To do that, declare the following in ``.vimrc``::

        let g:tagport_aliases = {'django.db.models.base': 'django.db.models'}

    The next time you search for ``Model``, ``from django.db.models import Model`` is listed instead.


let g:tagport_ignore = []
    ``models`` can be found in many places, but not all are useful. You can hide any entry with ``g:tagport_ignore``.
    For example, if you want to hide all ``models`` from ``migrations`` directory, declare the following in ``.vimrc``::
        
        let g:tagport_ignore = ['.*migrations.*']


Links:
  1. README - http://bit.ly/xTL1qn
  2. Screenshot - http://bit.ly/zqOfsv
 
install details
Place this script in $HOME/.vim/ftplugin/python.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
tagport.vim 0.2 2012-02-03 7.0 Phui-Hock Chang - Added aliases and ignore list support.
- Bug fixes
tagport.vim 0.1 2012-02-01 7.0 Phui-Hock Chang Initial upload
ip used for rating: 18.217.182.45

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github