Tip #315: "Smart <home>"
tip karma |
Rating 23/19, Viewed by 1455
|
created: |
|
August 14, 2002 16:46 |
|
complexity: |
|
advanced |
author: |
|
Alex A. Naanou |
|
as of Vim: |
|
5.7 |
to make it faster to navigate through indented code here is a common way to "go home"...
---cut---
fun! s:SmartHome()
if col('.') != match(getline('.'), '\S')+1
norm ^
else
:call cursor(line('.'),2)
norm h
endif
endfun
inoremap <silent><home> <C-O>:call <SID>SmartHome()<CR>
nnoremap <silent><home> :call <SID>SmartHome()<CR>
vnoremap <silent><home> :call <SID>SmartHome()<CR>
---uncut---
what this snippet does is make the <home> key behave as it does in such IDEs as PythonWin or MSVisualStudio, and that is first go to the first non whitespace, and then to the first char on the line.
<<Insert and back... |
Using /pattern/ search in a script >>
Additional Notes
|