“谷歌”python风格脚本无法正常工作

时间:2011-04-17 22:19:40

标签: python vim indentation

我正在尝试使用Google python indentation script,但这对我不起作用。我希望它缩进如下:

very_long_function_name(
    first_param,

我将其文字粘贴到this vim script:的末尾并将其放入~/.vim/indent/python.vim。不知道为什么它不起作用。


编辑:修复。

我修改了缩进文件,如下所示:

function GetGooglePythonIndent(lnum)
  " Indent inside parens.
  " Align with the open paren unless it is at the end of the line.
  " E.g.
  "   open_paren_not_at_EOL(100,
  "                         (200,
  "                          300),
  "                         400)
  "   open_paren_at_EOL(
  "       100, 200, 300, 400)
  call cursor(a:lnum, 1)
  let [par_line, par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW',
        \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
        \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
        \ . " =~ '\\(Comment\\|String\\)$'")
  echo par_line par_col
  if par_line > 0
    call cursor(par_line, 1)
    if par_col != col("$") - 1
      return par_col
    else
      return indent(par_line) + &sw " FIXED HERE. FIXED BY ADDING THIS LINE
    endif
  endif

  " Delegate the rest to the original function.
  return GetPythonIndent(a:lnum)
endfunction

3 个答案:

答案 0 :(得分:2)

您可能缺少.vimrc中的filetype indent on

答案 1 :(得分:0)

通过修改脚本并添加缺失行来修复。

答案 2 :(得分:0)

就我而言,我必须将脚本复制到~/.vim/after/indent/python.vim,因为内置的python缩进脚本会覆盖我添加到~/.vim/indent/python.vim的脚本。

我可以通过:scriptnames命令查看加载的订单。

相关问题