[prev in list] [next in list] [prev in thread] [next in thread]
List: vim
Subject: Re: Smart tab key
From: Didier Bretin <dbr () informactis ! com>
Date: 2003-03-24 13:47:47
[Download RAW message or body]
Hi Shaun,
On Sat, 22 Mar 2003 15:10:47 -0800
Shaun Jackman <sjackman@shaw.ca> wrote:
SJ> In insert mode, I would like the tab key to function as follows:
SJ>
SJ> If cursor is at the beginning of a line,
SJ> ie only white space characters to the left
SJ> tab inserts a tab character.
SJ> If in the middle of a line,
SJ> ie any non-white space character on the left
SJ> tab acts as <c-p>
SJ>
SJ> I'm sure this is a simple insert-mode macro, but my vim hacking
SJ> skills are weak. <frown> Can anybody suggest a couple quick lines to
SJ> accomplish this?
Me I use this on my .vimrc file and it works very well:
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
Regards.
--
.------------------------------------------------.
.^. | Didier Bretin, France | dbr@informactis.com |
/V\ |-----------------------| www.informactis.com |
// \\ | `------------------------|
/( )\ | Visit: http://www.vim.org/ |
^^-^^ `------------------------------------------------'
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic