javascript - Vim : Moving Through Code - Stack Overflow
I want to be able to navigate the cursor across functions using Vim. Mainly, I want a mand to allow me to go to the next function, like }
allows me to go to the next paragraph. I found this:
Go to the end of the C++ function in Vim
Unfortunately, it doesn't seem to work fine in JavaScript. Also, I believe it would also not work for Python, as Python don't depend much on { and }.
Any help?
I want to be able to navigate the cursor across functions using Vim. Mainly, I want a mand to allow me to go to the next function, like }
allows me to go to the next paragraph. I found this:
Go to the end of the C++ function in Vim
Unfortunately, it doesn't seem to work fine in JavaScript. Also, I believe it would also not work for Python, as Python don't depend much on { and }.
Any help?
Share Improve this question edited May 23, 2017 at 12:26 CommunityBot 11 silver badge asked Jan 24, 2011 at 9:31 RafidRafid 20.4k24 gold badges79 silver badges111 bronze badges 2-
2
/^def
will take you to the next top level function – John La Rooy Commented Jan 24, 2011 at 9:38 - This is only useful in Python, I am also looking for JavaScript and languages with similar syntax. Besides that, it is easier to press few keys, then to have to make a search every time, but it is good, thanks. – Rafid Commented Jan 24, 2011 at 9:55
2 Answers
Reset to default 8In a Python file I find:
}
will take me to the end of a block,]]
will take me to the start of the next function.[[
takes me to the start of the current function, or the one above if I keep pressing.
]}
didn't seem to work though.
I believe the standard vim motions will work for you in javascript. I think the $VIMRUNTIME/ftplugin/javascript.vim file defines function/Class/etc boundaries.
See :h ]m
:
*]m*
]m Go to [count] next start of a method (for Java or
similar structured language). When not before the
start of a method, jump to the start or end of the
class. When no '{' is found after the cursor, this is
an error. |exclusive| motion.
*]M*
]M Go to [count] next end of a method (for Java or
similar structured language). When not before the end
of a method, jump to the start or end of the class.
When no '}' is found after the cursor, this is an
error. |exclusive| motion.
*[m*
[m Go to [count] previous start of a method (for Java or
similar structured language). When not after the
start of a method, jump to the start or end of the
class. When no '{' is found before the cursor this is
an error. |exclusive| motion.
*[M*
[M Go to [count] previous end of a method (for Java or
similar structured language). When not after the
end of a method, jump to the start or end of the
class. When no '}' is found before the cursor this is
an error. |exclusive| motion.
More precise JS movements from this: https://github./okpute/vim-javascript-motions
For python, see $VIMRUNTIME/ftplugin/python.vim:
execute "nnoremap <silent> <buffer> ]] :call <SID>Python_jump('n', '". b:next_toplevel."', 'W', v:count1)<cr>"
execute "nnoremap <silent> <buffer> [[ :call <SID>Python_jump('n', '". b:prev_toplevel."', 'Wb', v:count1)<cr>"
execute "nnoremap <silent> <buffer> ][ :call <SID>Python_jump('n', '". b:next_endtoplevel."', 'W', v:count1, 0)<cr>"
execute "nnoremap <silent> <buffer> [] :call <SID>Python_jump('n', '". b:prev_endtoplevel."', 'Wb', v:count1, 0)<cr>"
execute "nnoremap <silent> <buffer> ]m :call <SID>Python_jump('n', '". b:next."', 'W', v:count1)<cr>"
execute "nnoremap <silent> <buffer> [m :call <SID>Python_jump('n', '". b:prev."', 'Wb', v:count1)<cr>"
execute "nnoremap <silent> <buffer> ]M :call <SID>Python_jump('n', '". b:next_end."', 'W', v:count1, 0)<cr>"
execute "nnoremap <silent> <buffer> [M :call <SID>Python_jump('n', '". b:prev_end."', 'Wb', v:count1, 0)<cr>"
- 谷歌正在复制苹果模式?(图)
- 苹果兜售没用软件脸不红心不跳
- 英特尔移动之战
- 后PC时代是五足鼎立还是苹果独领风骚?
- python - How to solve this TensorflowTensorboard compatibility problem? - Stack Overflow
- uart - MH-z19b stop working after 999999 millis (NodeMCU v3 ESP8266 12F) - Stack Overflow
- python - DocTR wrong number detection - Stack Overflow
- C equivalent of C++ inline - Stack Overflow
- python - How to display only the tags translated into the corresponding language on a multilingual site? - Stack Overflow
- postgresql - Postgres Postgis ST_DWithin query is not accurate - Stack Overflow
- javascript - Use HTML5 canvas 2d API with WebGL - Stack Overflow
- React Native Build Error on Windows: "EMFILE: too many open files" During `assembleRelease` - Stack Overflow
- kubernetes - Tekton CD Pruner Job Pod Hanging with Istio Sidecar - Stack Overflow
- class - Python: trying to use exec(), pathlib and __file__ in combination fails - Stack Overflow
- java - jOOQ transaction does not work as expected - Stack Overflow
- sockets - PICO WMicropython websocket client can't send to PHP websocket properly - Stack Overflow
- Spring Boot Application in Docker Container Shuts Down Immediately After Startup - Stack Overflow