Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How do I define function for toggling textwidth (and echoing along)?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Santosh Kumar  
View profile   Translate to Translated (View Original)
 More options Aug 25 2012, 5:07 am
From: Santosh Kumar <sntshkm...@gmail.com>
Date: Sat, 25 Aug 2012 14:37:43 +0530
Local: Sat, Aug 25 2012 5:07 am
Subject: How do I define function for toggling textwidth (and echoing along)?
By default I have textwidth set to 78:
set textwidth=78

By this setting if I type more than 78 characters in a line, those
will be moved to next line.
I want a mapping that will toogle that textwidth to 0 (or say disable
textwidth), so that I can type long sentences in a single line.

Currently I have this mapping:
nnoremap <silent> <leader>tw :exe "set textwidth=" . (&tw ? 0 : 78)<cr>

This does the work but I don't get notified if the work has been done.
All I want is along with toggling the setting I should be notified
(i.e. if textwidth is zero then show textwidth=0 at statusline).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Isambert  
View profile  
 More options Aug 25 2012, 8:50 am
From: Paul Isambert <zappathus...@free.fr>
Date: Sat, 25 Aug 2012 14:50:20 +0200
Local: Sat, Aug 25 2012 8:50 am
Subject: Re: How do I define function for toggling textwidth (and echoing along)?
Santosh Kumar <sntshkm...@gmail.com> a écrit:

> By default I have textwidth set to 78:
> set textwidth=78

> By this setting if I type more than 78 characters in a line, those
> will be moved to next line.
> I want a mapping that will toogle that textwidth to 0 (or say disable
> textwidth), so that I can type long sentences in a single line.

> Currently I have this mapping:
> nnoremap <silent> <leader>tw :exe "set textwidth=" . (&tw ? 0 : 78)<cr>

> This does the work but I don't get notified if the work has been done.
> All I want is along with toggling the setting I should be notified
> (i.e. if textwidth is zero then show textwidth=0 at statusline).

Try this:

  :nnoremap <silent> tw :exe "set textwidth=" . (&tw ? 0 : 78)<CR> <Bar> :echo "textwidth=" . &tw<CR>

Best,
Paul


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Santosh Kumar  
View profile   Translate to Translated (View Original)
 More options Aug 25 2012, 9:21 am
From: Santosh Kumar <sntshkm...@gmail.com>
Date: Sat, 25 Aug 2012 18:51:03 +0530
Local: Sat, Aug 25 2012 9:21 am
Subject: Re: How do I define function for toggling textwidth (and echoing along)?
Still nothing is shown on the status bar.

Can't we create a function named Toogletw() and call it on this mapping?

On 8/25/12, Paul Isambert <zappathus...@free.fr> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ruderich  
View profile   Translate to Translated (View Original)
 More options Aug 25 2012, 9:50 am
From: Simon Ruderich <si...@ruderich.org>
Date: Sat, 25 Aug 2012 15:50:09 +0200
Local: Sat, Aug 25 2012 9:50 am
Subject: Re: How do I define function for toggling textwidth (and echoing along)?

On Sat, Aug 25, 2012 at 02:37:43PM +0530, Santosh Kumar wrote:
> [snip]

> Currently I have this mapping:
> nnoremap <silent> <leader>tw :exe "set textwidth=" . (&tw ? 0 : 78)<cr>

> This does the work but I don't get notified if the work has been done.
> All I want is along with toggling the setting I should be notified
> (i.e. if textwidth is zero then show textwidth=0 at statusline).

:help let-option comes useful in these cases. For example:

    :nnoremap tw :let &textwidth = (&textwidth ? 0 : 78)<CR>:set textwidth?<CR>

It's a bit shorter and IMHO easier to read.

'formatoption' l (:help fo-table) might also be useful:

    l   Long lines are not broken in insert mode: When a line was
        longer than 'textwidth' when the insert command started,
        Vim does not automatically format it.

Regards,
Simon
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

  application_pgp-signature_part
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Isambert  
View profile  
 More options Aug 25 2012, 11:48 am
From: Paul Isambert <zappathus...@free.fr>
Date: Sat, 25 Aug 2012 17:48:04 +0200
Local: Sat, Aug 25 2012 11:48 am
Subject: Re: How do I define function for toggling textwidth (and echoing along)?
Santosh Kumar <sntshkm...@gmail.com> a écrit:

> Still nothing is shown on the status bar.

> Can't we create a function named Toogletw() and call it on this mapping?

I hadn't read "status-line"; my code prints the width in the command-line.
If you want the value of "textwidth" to be mentioned in the status line, then
change the "statusline" option, and let your mapping simply change that value;
the change will be automatically reflected in the status line. The simpler
solution is (see ":help statusline"):

  setlocal statusline=%!&tw

Of course the problem then is what happens if you don't have a status-line?

Best,
Paul


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gary Johnson  
View profile  
 More options Aug 25 2012, 12:21 pm
From: Gary Johnson <garyj...@spocom.com>
Date: Sat, 25 Aug 2012 09:21:54 -0700
Local: Sat, Aug 25 2012 12:21 pm
Subject: Re: How do I define function for toggling textwidth (and echoing along)?
On 2012-08-25, Paul Isambert wrote:

> Santosh Kumar a crit:

> > Still nothing is shown on the status bar.

> > Can't we create a function named Toogletw() and call it on this mapping?

> I hadn't read "status-line"; my code prints the width in the command-line.
> If you want the value of "textwidth" to be mentioned in the status line, then
> change the "statusline" option, and let your mapping simply change that value;
> the change will be automatically reflected in the status line. The simpler
> solution is (see ":help statusline"):

>   setlocal statusline=%!&tw

> Of course the problem then is what happens if you don't have a status-line?

You could put a textwidth indication in the ruler, which doesn't
take as much screen space as the statusline, but 'rulerformat'
doesn't give you as much space for customization.

Regards,
Gary


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bee  
View profile  
 More options Aug 25 2012, 11:56 pm
From: Bee <fo...@calcentral.com>
Date: Sat, 25 Aug 2012 20:56:25 -0700 (PDT)
Local: Sat, Aug 25 2012 11:56 pm
Subject: Re: How do I define function for toggling textwidth (and echoing along)?

On Aug 25, 2:07 am, Santosh Kumar <sntshkm...@gmail.com> wrote:

> By default I have textwidth set to 78:
> set textwidth=78

> By this setting if I type more than 78 characters in a line, those
> will be moved to next line.
> I want a mapping that will toogle that textwidth to 0 (or say disable
> textwidth), so that I can type long sentences in a single line.

> Currently I have this mapping:
> nnoremap <silent> <leader>tw :exe "set textwidth=" . (&tw ? 0 : 78)<cr>

> This does the work but I don't get notified if the work has been done.
> All I want is along with toggling the setting I should be notified
> (i.e. if textwidth is zero then show textwidth=0 at statusline).

:help colorcolumn

Add this to your .vimrc:

set colorcolumn=+1
hi ColorColumn NONE ctermbg=Cyan

When textwidth=0 there is no colorcolumn,
otherwise it is drawn just after the textwidth.

Bill


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bee  
View profile  
 More options Aug 25 2012, 11:39 pm
From: Bee <beeyaw...@gmail.com>
Date: Sat, 25 Aug 2012 20:39:24 -0700
Local: Sat, Aug 25 2012 11:39 pm
Subject: Re: How do I define function for toggling textwidth (and echoing along)?
On Aug 25, 2012, at 8:00 PM, vim_use@googlegroups.com wrote:

:help colorcolumn

Add this to your .vimrc:

set colorcolumn=+1
hi ColorColumn NONE ctermbg=Cyan

When textwidth=0 there is no colorcolumn,
otherwise it is drawn just after the textwidth.

Bill


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andy Wokula  
View profile  
 More options Aug 30 2012, 2:03 pm
From: Andy Wokula <anw...@yahoo.de>
Date: Thu, 30 Aug 2012 20:02:37 +0200
Local: Thurs, Aug 30 2012 2:02 pm
Subject: Re: How do I define function for toggling textwidth (and echoing along)?
Am 25.08.2012 11:07, schrieb Santosh Kumar:

> By default I have textwidth set to 78:
> set textwidth=78

> By this setting if I type more than 78 characters in a line, those
> will be moved to next line.
> I want a mapping that will toogle that textwidth to 0 (or say disable
> textwidth), so that I can type long sentences in a single line.

> Currently I have this mapping:
> nnoremap <silent> <leader>tw :exe "set textwidth=" . (&tw ? 0 : 78)<cr>

This one is more verbose, without visual clutter:

    :nn <expr> <Leader>tw  printf(":setl tw=%d<CR>", &tw==0 ? 78 : 0)

> This does the work but I don't get notified if the work has been done.
> All I want is along with toggling the setting I should be notified
> (i.e. if textwidth is zero then show textwidth=0 at statusline).

An example how to play with the statusline:
     :h 'stl

" standard statusline
" set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P

set statusline=%<%f\ %h%m%r%{TwLeft()}%=%-14.(%l,%c%V%)\ %P

" remaining textwidth
func! TwLeft()
     let ioff = mode()==#"i" ? 1 : 0
     if &tw == 0 || virtcol(".") > &tw + ioff
         return ""
     else
         let left = &tw + ioff - virtcol(".")
         return printf('[%d %s left]', left, left==1 ? "char" : "chars")
     endif
endfunc

--
Andy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »