VIM + Python - gd command not working properly

I am starting to use VIM for Python programming. I ran into some problems, hope someone can help me with this.

The gd command should take you first when the variable is defined / used in the current function. From what I understand, this is the same as "[[", to go to the beginning of the function and then search for the variable name.

The problem is that when I try to use this in Python functions, vim finds the first occurrence of the variable in the entire file.

Any thoughts on why this is happening / how can I fix this?

+5
source share
2 answers

, , Vim . [[:

                            *[[*
[[          [count] sections backward or to the previous '{' in
            the first column.  |exclusive|
            Note that |exclusive-linewise| often applies.

- python - ( , , nroff), , , python.

Vim, , . :

nmap gd :let varname = '\<<C-R><C-W>\>'<CR>?\<def\><CR>/<C-R>=varname<CR><CR>

, , . gd , "varname", , , def :

    :let varname =             " Variable setting
    '\<                        " String start and word boundary
    <C-R><C-W>                 " Ctrl-R, Ctrl-W: pull in the word under the cursor
    \>'                        " Word boundary and string end
    <CR>                       " Enter - finish this command
    ?                          " Search backwards for...
    \<def\>                    " def but not undefined etc (using word boundaries)
    <CR>                       " Enter - Perform search
    /                          " Now search forward
    <C-R>=                     " Pull in something from an expression
    varname<CR>                " The expression is 'varname', so pull in the contents of varname
    <CR>                       " Enter - perform search
+3

varname Vim, , vim, python. , ?

​​ Vx 7.x, Python? , :python print "hello, world" VIM. , E319: Sorry, the command is not available in this version , .

+2

All Articles