diff --git a/README b/README deleted file mode 100644 index 50fe96d..0000000 --- a/README +++ /dev/null @@ -1,15 +0,0 @@ -This is a mirror of http://www.vim.org/scripts/script.php?script_id=30 - -Written by Mikael Berthe. - -This script can be useful when editing Python scripts. It provides the following menus: -- Select a block of lines with the same indentation -- Select a function -- Select a class -- Go to previous/next class/function -- Go to the beginning/end of a block -- Comment/uncomment the selection -- Jump to the last/next line with the same indent -- Shift a block (left/right) -- Creates list of classes and functions for easy code navigation -Version 1.8+ requires Vim 7, earlier versions require Vim 6 diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..deaad47 --- /dev/null +++ b/README.rst @@ -0,0 +1,52 @@ +Python.vim +========== + +This is a set of menus/shortcuts to work with Python files. This work is kind +continuation of `Mikael Berthe script`_, with some improvements and fixes. + +Installation +------------ + +To install it, any kind of Vim package manager can be used, like NeoBundle_, +Pathogen_, Vundle_ or vim-plug_. + +For manual installation, copy subdirectories from this repository to your +``~/.vim`` directory. + +Usage +----- + +Default shortcuts are as follows: + +- ``]]`` - jump to next class +- ``[[`` - jump to previous class +- ``}}`` - jump to next function or method +- ``{[`` - jump to previous function or method +- ``]t`` - jump to beginning of block +- ``]e`` - jump to end of block +- ``]`` - jump to previous line with the same/lower indentation +- ``]`` - jump to next line with the same/lower indentation +- ``]<`` - shift block to left +- ``]>`` - shift block to right +- ``]#`` - comment selection +- ``]u`` - uncomment selection +- ``vac`` - select (Visual Line Mode) current/previous class +- ``vaf`` - select (Visual Line Mode) current/previous function +- ``vab`` - select (Visual Line Mode) block + +You can set the global variable ``g:py_select_leading_comments`` to 0 +if you don't want to select comments preceding a declaration (these +are usually the description of the function/class). +You can set the global variable ``g:py_select_trailing_comments`` to 0 +if you don't want to select comments at the end of a function/class. +If these variables are not defined, both leading and trailing comments +are selected. + +If you use graphical version of vim (like gvim) you can access those options +through the menu called *Python*. + +.. _Mikael Berthe script: http://www.vim.org/scripts/script.php?script_id=30 +.. _Pathogen: https://github.com/tpope/vim-pathogen +.. _Vundle: https://github.com/gmarik/Vundle.vim +.. _NeoBundle: https://github.com/Shougo/neobundle.vim +.. _vim-plug: https://github.com/junegunn/vim-plug diff --git a/ftplugin/python/python_fn.vim b/ftplugin/python/python_fn.vim index 278edd2..a3182d3 100644 --- a/ftplugin/python/python_fn.vim +++ b/ftplugin/python/python_fn.vim @@ -1,40 +1,15 @@ " -*- vim -*- " FILE: python_fn.vim -" LAST MODIFICATION: 2008-08-28 8:19pm +" LAST MODIFICATION: 2017-05-28 17:47:13 " (C) Copyright 2001-2005 Mikael Berthe " Maintained by Jon Franklin -" Version: 1.13 +" Modifed by Roman Dobosz +" Version: 1.14 " USAGE: -" -" See README for installation. -" You can set the global variable "g:py_select_leading_comments" to 0 -" if you don't want to select comments preceding a declaration (these -" are usually the description of the function/class). -" You can set the global variable "g:py_select_trailing_comments" to 0 -" if you don't want to select comments at the end of a function/class. -" If these variables are not defined, both leading and trailing comments -" are selected. -" Example: (in your .vimrc) "let g:py_select_leading_comments = 0" -" You may want to take a look at the 'shiftwidth' option for the -" shift commands... -" -" REQUIREMENTS: -" vim (>= 7) -" -" Shortcuts: -" ]t -- Jump to beginning of block -" ]e -- Jump to end of block -" ]v -- Select (Visual Line Mode) block -" ]< -- Shift block to left -" ]> -- Shift block to right -" ]# -- Comment selection -" ]u -- Uncomment selection -" ]c -- Select current/previous class -" ]d -- Select current/previous function -" ] -- Jump to previous line with the same/lower indentation -" ] -- Jump to next line with the same/lower indentation +" See README.rst +" Shortcuts: " Only do this when not done yet for this buffer if exists("b:loaded_py_ftplugin") finish @@ -46,7 +21,7 @@ vmap ]t :PBOBm'gv`` map ]e :PEoB vmap ]e :PEoBm'gv`` -map ]v ]tV]e +map vab ]tV]e map ]< ]tV]e< vmap ]< < map ]> ]tV]e> @@ -57,76 +32,56 @@ vmap ]# :call PythonCommentSelection() map ]u :call PythonUncommentSelection() vmap ]u :call PythonUncommentSelection() -map ]c :call PythonSelectObject("class") -map ]d :call PythonSelectObject("function") +map vac :call PythonSelectObject("class") +map vaf :call PythonSelectObject("function") map ] :call PythonNextLine(-1) map ] :call PythonNextLine(1) " You may prefer use and ... :-) " jump to previous class -map ]J :call PythonDec("class", -1) -vmap ]J :call PythonDec("class", -1) +map [[ :call PythonDec("class", -1) +vmap [[ :call PythonDec("class", -1) " jump to next class -map ]j :call PythonDec("class", 1) -vmap ]j :call PythonDec("class", 1) +map ]] :call PythonDec("class", 1) +vmap ]] :call PythonDec("class", 1) " jump to previous function -map ]F :call PythonDec("function", -1) -vmap ]F :call PythonDec("function", -1) +map {{ :call PythonDec("function", -1) +vmap {{ :call PythonDec("function", -1) " jump to next function -map ]f :call PythonDec("function", 1) -vmap ]f :call PythonDec("function", 1) +map }} :call PythonDec("function", 1) +vmap }} :call PythonDec("function", 1) " Menu entries -nmenu &Python.Update\ IM-Python\ Menu - \:call UpdateMenu() +nmenu &Python.Update\ IM-Python\ Menu :call UpdateMenu() nmenu &Python.-Sep1- : -nmenu &Python.Beginning\ of\ Block[t - \]t -nmenu &Python.End\ of\ Block]e - \]e +nmenu &Python.Beginning\ of\ Block[t ]t +nmenu &Python.End\ of\ Block]e ]e nmenu &Python.-Sep2- : -nmenu &Python.Shift\ Block\ Left]< - \]< -vmenu &Python.Shift\ Block\ Left]< - \]< -nmenu &Python.Shift\ Block\ Right]> - \]> -vmenu &Python.Shift\ Block\ Right]> - \]> +nmenu &Python.Shift\ Block\ Left]< ]< +vmenu &Python.Shift\ Block\ Left]< ]< +nmenu &Python.Shift\ Block\ Right]> ]> +vmenu &Python.Shift\ Block\ Right]> ]> nmenu &Python.-Sep3- : -vmenu &Python.Comment\ Selection]# - \]# -nmenu &Python.Comment\ Selection]# - \]# -vmenu &Python.Uncomment\ Selection]u - \]u -nmenu &Python.Uncomment\ Selection]u - \]u +vmenu &Python.Comment\ Selection]# ]# +nmenu &Python.Comment\ Selection]# ]# +vmenu &Python.Uncomment\ Selection]u ]u +nmenu &Python.Uncomment\ Selection]u ]u nmenu &Python.-Sep4- : -nmenu &Python.Previous\ Class]J - \]J -nmenu &Python.Next\ Class]j - \]j -nmenu &Python.Previous\ Function]F - \]F -nmenu &Python.Next\ Function]f - \]f +nmenu &Python.Previous\ Class[[ [[ +nmenu &Python.Next\ Class]] ]] +nmenu &Python.Previous\ Function{{ {{ +nmenu &Python.Next\ Function}} }} nmenu &Python.-Sep5- : -nmenu &Python.Select\ Block]v - \]v -nmenu &Python.Select\ Function]d - \]d -nmenu &Python.Select\ Class]c - \]c +nmenu &Python.Select\ Blockvab vab +nmenu &Python.Select\ Functionvaf vaf +nmenu &Python.Select\ Classvac vac nmenu &Python.-Sep6- : -nmenu &Python.Previous\ Line\ wrt\ indent] - \] -nmenu &Python.Next\ Line\ wrt\ indent] - \] +nmenu &Python.Previous\ Line\ wrt\ indent] ] +nmenu &Python.Next\ Line\ wrt\ indent] ] :com! PBoB execute "normal ".PythonBoB(line('.'), -1, 1)."G" :com! PEoB execute "normal ".PythonBoB(line('.'), 1, 1)."G" @@ -191,7 +146,7 @@ endfunction " commentString is inserted in non-empty lines, and should be aligned with " the block function! PythonCommentSelection() range - let commentString = "#" + let commentString = "# " let cl = a:firstline let ind = 1000 " I hope nobody use so long lines! :) @@ -225,7 +180,7 @@ endfunction function! PythonUncommentSelection() range " commentString could be different than the one from CommentSelection() " For example, this could be "# \\=" - let commentString = "#" + let commentString = "# " let cl = a:firstline while (cl <= a:lastline) let ul = substitute(getline(cl),