Quindi, non ho mai fatto nessuno script Vim, ma basato su this question about doing something similar in C e this tip for checking if you're currently in a comment, ho violato una soluzione.
Per impostazione predefinita, utilizza le larghezze PEP8-suggerito di 79 caratteri per linee normali e 72 caratteri per i commenti, ma li si può ignorare da let
ting g:python_normal_text_width
o g:python_comment_text_width
variabili, rispettivamente. (Personalmente, mi avvolgo linee normali a 78 caratteri.)
Goccia questo bambino nel vostro Vimrc e si dovrebbe essere a posto. Potrei impacchettare questo come un plugin più tardi.
function! GetPythonTextWidth()
if !exists('g:python_normal_text_width')
let normal_text_width = 79
else
let normal_text_width = g:python_normal_text_width
endif
if !exists('g:python_comment_text_width')
let comment_text_width = 72
else
let comment_text_width = g:python_comment_text_width
endif
let cur_syntax = synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name")
if cur_syntax == "Comment"
return comment_text_width
elseif cur_syntax == "String"
" Check to see if we're in a docstring
let lnum = line(".")
while lnum >= 1 && (synIDattr(synIDtrans(synID(lnum, col([lnum, "$"]) - 1, 0)), "name") == "String" || match(getline(lnum), '\v^\s*$') > -1)
if match(getline(lnum), "\\('''\\|\"\"\"\\)") > -1
" Assume that any longstring is a docstring
return comment_text_width
endif
let lnum -= 1
endwhile
endif
return normal_text_width
endfunction
augroup pep8
au!
autocmd CursorMoved,CursorMovedI * :if &ft == 'python' | :exe 'setlocal textwidth='.GetPythonTextWidth() | :endif
augroup END
fonte
2010-10-26 22:04:01
Domanda molto simile: http://stackoverflow.com/questions/3475072/vim-different-textwidth-for-multiline-c-comments – adw