How can we do this with vim?
set hlsearch " Highlight search matches set incsearch " Highlight search matches as you type set visualbell " Use visual bell instead of beeping set shortmess+=I " Disable vim intro message set lazyredraw █...............x<-- Put the cursor here
- Should work without changing normal Tab functionality
- Solution doesn't necessarily have to use the Tab key
I've got a pretty well working 'supertab' key based on Maxim Kim's posted solution.
A modified tabbing behavior that jumps to align with the next word on the previous line can be achieved by including this in your vimrc:
" Tab that will advance to align with next word on the previous line fun! SuperTab() abort let spaces = matchstr(getline(line('.')-1)[col('.')-1:], '^\s*') return len(spaces) ? spaces : "\<tab>" endfun inoremap <expr> <C-t> SuperTab()
For a more succinct solution if backwards compatibility is not a concern (since support for a regular expression anchor
\%.c that represents the current cursor position has been introduced into vim in version 8.2.3110):
" Tab that will advance to align with next word on the previous line (needs vim >= 8.2.3110) fun! SuperTab() abort let spaces = matchstr(getline(line('.')-1), '\%.c\s*') return len(spaces) ? spaces : "\<tab>" endfun inoremap <expr> <C-t> SuperTab()
Although binding this to something like CtrlTab could feel intuitive, that happens to be one of the key combinations that doesn't have universal support across terminal emulators. For this reason, I've currently got it bound to CtrlT in normal mode.