Per le lingue con {}
per indicare i blocchi, vim ha l'onnipotente chiave %
. Qual è l'equivalente movimento per il codice Python? O almeno per passare alla riga successiva/precedente con lo stesso trattino.Equivalente di% movement per file Python
risposta
Il vim wiki suggeriscono attacchi come ad esempio:
nnoremap <M-,> k:call search('^'. matchstr(getline(line('.')+1), '\(\s*\)') .'\S', 'b')<CR>^
nnoremap <M-.> :call search('^'. matchstr(getline(line('.')), '\(\s*\)') .'\S')<CR>^
Oltre ad offrire una soluzione più completa:
" Jump to the next or previous line that has the same level or a lower
" level of indentation than the current line.
"
" exclusive (bool): true: Motion is exclusive
" false: Motion is inclusive
" fwd (bool): true: Go to next line
" false: Go to previous line
" lowerlevel (bool): true: Go to line with lower indentation level
" false: Go to line with the same indentation level
" skipblanks (bool): true: Skip blank lines
" false: Don't skip blank lines
function! NextIndent(exclusive, fwd, lowerlevel, skipblanks)
let line = line('.')
let column = col('.')
let lastline = line('$')
let indent = indent(line)
let stepvalue = a:fwd ? 1 : -1
while (line > 0 && line <= lastline)
let line = line + stepvalue
if (! a:lowerlevel && indent(line) == indent ||
\ a:lowerlevel && indent(line) < indent)
if (! a:skipblanks || strlen(getline(line)) > 0)
if (a:exclusive)
let line = line - stepvalue
endif
exe line
exe "normal " column . "|"
return
endif
endif
endwhile
endfunction
" Moving back and forth between lines of same or lower indentation.
nnoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
nnoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
nnoremap <silent> [L :call NextIndent(0, 0, 1, 1)<CR>
nnoremap <silent> ]L :call NextIndent(0, 1, 1, 1)<CR>
vnoremap <silent> [l <Esc>:call NextIndent(0, 0, 0, 1)<CR>m'gv''
vnoremap <silent> ]l <Esc>:call NextIndent(0, 1, 0, 1)<CR>m'gv''
vnoremap <silent> [L <Esc>:call NextIndent(0, 0, 1, 1)<CR>m'gv''
vnoremap <silent> ]L <Esc>:call NextIndent(0, 1, 1, 1)<CR>m'gv''
onoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
onoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
onoremap <silent> [L :call NextIndent(1, 0, 1, 1)<CR>
onoremap <silent> ]L :call NextIndent(1, 1, 1, 1)<CR>
che utilizza:
[l
e]l
salto al precedente o la riga successiva con lo stesso livello di indentazione della corrente linea.[L
e]L
passare alla riga precedente o successiva con un livello di indentazione inferiore rispetto alla riga corrente.
È sempre possibile utilizzare i commenti per inserire {} (non farebbe questo se altri condividono):
class Game(object): # {
def __init__(self, num, end): # {
pass
# }
# }
Vim ha le {
e }
movimenti per spostarsi tra "punti" e il corrispondente p
di testo -object (vip
, dap
).
Il ftplugin predefinito Python anche (ri) definisce [[
e ]]
per passare alla classe successiva e precedente e ]m
e [m
per passare al metodo successivo e precedente.
Il indent-object è molto utile pure per Python.
perdonami, ma che cos'è un oggetto-indent? Link per favore? – Ayman
Mi dispiace, ho avuto l'URL nella mia appunti ma ho dimenticato di metterlo nella risposta. È molto facile da trovare, però. – romainl
Piuttosto interessante ma l'oggetto indent non funziona in modalità normale. C'è un modo per costringerlo a lavorare in modalità normale? –
- 1. VisualVM equivalente per Python
- 2. Passport.js equivalente per Python?
- 3. Equivalente Java per il file str.strip di Python()
- 4. Equivalente Python di find2perl
- 5. Equivalente rubino per Python per/
- 6. Equivalente per LinkedHashMap in Python
- 7. Python equivalente per #ifdef DEBUG
- 8. Equivalente per inject() in Python?
- 9. di Python equivalente
- 10. Equivalente Python per IFNULL di MySQL
- 11. Equivalente thread-safe per time.strptime() di python?
- 12. Equivalente Python di Sinatra
- 13. Equivalente Python di Jstack?
- 14. Esiste un equivalente Cake per Python?
- 15. appSettings file di attributi equivalente per ApplicationSettings
- 16. Esiste un equivalente python dell'utilità "file" di unix?
- 17. Equivalente Scala di Python help()
- 18. Python equivalente di Perl/Rubino || =
- 19. Equivalente Python di C++ getline()
- 20. Ruby equivalente all'aiuto di Python()?
- 21. Nim equivalente di lista Python
- 22. equivalente JavaScript di Python __setitem__
- 23. Equivalente rubino di python setattr()
- 24. Equivalente Java di Python repr()?
- 25. equivalente PHP per un decoratore python?
- 26. Equivalente Python di Perl's while (<>) {...}?
- 27. selenium.wait_for_condition equivalente in binding Python per WebDriver
- 28. python - equivalente a strtotime?
- 29. Python #define equivalente
- 30. Python equivalente a "php -s"
Perché non scaricare un plug-in Python? – jamylak
* O almeno per passare alla riga successiva/precedente con lo stesso trattino * - potresti elaborare ciò che intendi con questo? – timss