On Tue, 12 Feb 2013, Eric Smith wrote:
> Eric Smith wrote on Sun-10-Feb 13 1:55PM
>> This works great for me, thanks Benjamin.
>>
>> E.
>>
>> Benjamin R. Haskell wrote on Thu-07-Feb 13 4:39PM
>>> ino <expr> <CR> getline('.') =~ '\w$' ? ".\<CR>" : "\<CR>"
>
> I am trying (and failing) to modify this so that with lines commencing
> with certain words like;
> Dear
> Geachte
> Foobar
> ... must not have a full stop inserted.
>
> Tried using \@<!
>
> How should I do this?
Here's how I'd do that. For starters, I'd modify the 'fun! ... endf'
version, rather than the one-liner.
fun! LazyFullStop()
let line = getline('.')
let firstword = matchstr(line, '\w\+')
if line =~ '\w$' && -1 == index(['Dear','Geachte','Foobar'], firstword)
return ".\<CR>"
end
return "\<CR>"
endf
ino <expr> <CR> LazyFullStop()
That's case-sensitive (which may be what you want).
If you want to allow leading spaces before the "forbidden" words, you
can change:
let firstword = matchstr(line, '\w\+')
To:
let firstword = matchstr(line, '\%(^\s*\)\@<=\w\+')
And if you really want the one-liner:
ino <expr> <CR> getline('.') =~ '\%(^\s*\%(Dear\\|Geachte\\|Foobar\)\>.*\)\@<!\w$' ? ".\<CR>" : "\<CR>"
--
Best,
Ben
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment