Function to put full stop at the end of my sentences

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Function to put full stop at the end of my sentences

ericmsmith
Hi

Do you have a suggestion for an (efficient) function to put a dot
after every combination of an alphanumeric char and a newline?

I just got tired of doing it manually the last days.

Thanks

Eric Smith

--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Function to put full stop at the end of my sentences

Chris Schneider
%s/\v(\w)$/\1./   - find any line ending in an alphanumeric, and replace it with that same alpha and a period.


On Tue, Feb 5, 2013 at 3:29 PM, Eric Smith <[hidden email]> wrote:
Hi

Do you have a suggestion for an (efficient) function to put a dot
after every combination of an alphanumeric char and a newline?

I just got tired of doing it manually the last days.

Thanks

Eric Smith

--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.



--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Function to put full stop at the end of my sentences

ericmsmith
Thanks for the suggestion Chris.

I was considering a command triggered
by iabbr <enter>

This command will look to see if the character
immediately to the left of the cursor belongs
to a certain character class (like \w)
and then inserts a `.' and a newline.

Then it is easy for me to check if this was what I want or not
and delete the period (full atop) if necessary and then press
arrow-down to avoid triggering the iabbr again.

How could this be implemented as efficiently as possible?


PS. at a next stage, I guess one could implement more fine
grained checks in order to make better guesses on whether a full
stop is wanted or not. At a cost of course.

Thanks for an suggestions.

--
Eric Smith

Chris Schneider wrote on Wed-06-Feb 13 12:01AM
> %s/\v(\w)$/\1./   - find any line ending in an alphanumeric, and replace it
> with that same alpha and a period.
>
>
> On Tue, Feb 5, 2013 at 3:29 PM, Eric Smith <[hidden email]> wrote:
>     Do you have a suggestion for an (efficient) function to put a dot
>     after every combination of an alphanumeric char and a newline?

--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Function to put full stop at the end of my sentences

Paul-4
On Thursday, 07 February, 2013 at 08:35:43 GMT, Eric Smith wrote:

>This command will look to see if the character
>immediately to the left of the cursor belongs
>to a certain character class (like \w)
>and then inserts a `.' and a newline.
>
>Then it is easy for me to check if this was what I want or not
>and delete the period (full atop) if necessary and then press
>arrow-down to avoid triggering the iabbr again.
>
>How could this be implemented as efficiently as possible?

You can put “c” after a search-and-replace, and Vim will ask for confirmation for each match, eg.:

%s/(\w)$/\1./c

--

.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Function to put full stop at the end of my sentences

Benjamin R. Haskell-8
In reply to this post by ericmsmith
On Tue, 5 Feb 2013, Eric Smith wrote:

> Hi
>
> Do you have a suggestion for an (efficient) function to put a dot
> after every combination of an alphanumeric char and a newline?
>
> I just got tired of doing it manually the last days.

(Initial suggestion: don't do it... but, that's because I suspect it
would annoy me after a while.)


What you requested:

fun! LazyFullStop()
   if getline('.') =~ '\w$'
     return ".\<CR>"
   end
   return "\<CR>"
endf
ino <expr> <CR> LazyFullStop()

Or, more compact:

ino <expr> <CR> getline('.') =~ '\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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Function to put full stop at the end of my sentences -> refining

ericmsmith
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?

Eric

--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Function to put full stop at the end of my sentences -> refining

Benjamin R. Haskell-8
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.