How to control and trim line lengths (zz)

What is a long line?

//z 2012-4-26 16:42:21 PM IS2120@CSDN
Well it depends. Notepad++ has two distinct, independent answers to this:

  • When a line cannot display in the view it belongs to, and if word wrap is on, the line wraps to one or more extra lines that all fit inside the view. Word wrap is toggled by the "Wrap" menu item found in the View menu. The Scintilla component does not support real-time wrapping at a fixed length.
  • When a line is longer than a predefined threshhold, the overflowing parts can be shown using some sort of markings. The relevant settings are to be found on theSettings -> Preferences -> Editing -> Vertical edge settings frame.

If a line is too long only because of trailing whitespace, this may be removed using theEdit -> Trim Trailing Space command. Use this instead of the shipped macro with a similar name, as the latter is provided mostly for testing and demonstration purposes.

Word Wrap

Word Wrap is toggled on or off using View -> Wrap. It takes place as you type, creating secondary lines when the current line wouldn't fit in the current window. If line numbers are displayed, a word-wrapped line continuation is designated by a period (".") in the line number column.

Word Wrap has been reported to noticeably slow down display updates when editing 20+ MB files. You may consider disabling it when processing such files.

Using Settings -> Preferences -> Editing -> Word wrap, you can control the appearance of spillover lines. Options are:

  • Default: no indent based on text layout
  • Align: Secondary lines indent like the primary line
  • Indent: Secondary lines indent one level more than primary line

Customizing Word Wrap further

  • The following macro sets the overhang indent of spillover lines that appear when a line wraps:
<Macro name="macro_1" Ctrl="yes" Alt="yes" Shift="no" Key="100">
   <Action type="0" message="2464" wParam=new_indent lParam="0" sParam=""/>
</Macro>
new_indent is given in text columns.
  • The following macro sets the granularity of the line wrapping method:
<Macro name="macro_2" Ctrl="yes" Alt="yes" Shift="no" Key="100">
   <Action type="0" message="2268" wParam=new_mode lParam="0" sParam=""/>
</Macro>
new_mode is either:
  • 0 for no word wrap
  • 1 for wrap at word boundaries only
  • 2 for wrap at cutoff point
  • Other values lead to undefined behaviour and should be avoided.
  • The following macro sets the granularity of the line wrapping method when printing a document:
<Macro name="macro_5" Ctrl="yes" Alt="yes" Shift="no" Key="100">
   <Action type="0" message="2406" wParam=new_mode lParam="0" sParam=""/>
</Macro>
new_mode is either:
  • 0 for no word wrap
  • 1 for wrap at word boundaries only
  • 2 for wrap at cutoff point
  • Other values lead to undefined behaviour and should be avoided.
  • The following macro sets the position of wrap markers:
<Macro name="macro_3" Ctrl="yes" Alt="yes" Shift="no" Key="100">
   <Action type="0" message="2460" wParam=new_mode lParam="0" sParam=""/>
</Macro>
new_mode is either:
  • 0 for no wrap markers
  • 1 for wrap markers at the end of split lines
  • 2 for wrap markers at the beginning of spillover lines
  • 3 for both kinds of markers
  • Other values lead to undefined behaviour and should be avoided.
  • The following macro sets the position of wrap markers when drawn:
<Macro name="macro_4" Ctrl="yes" Alt="yes" Shift="no" Key="100">
   <Action type="0" message="2462" wParam=new_mode lParam="0" sParam=""/>
</Macro>
new_mode is either:
  • 0 for markers drawn close to margin/window edge
  • 1 for wrap markers at the end of split lines drawn closer to text
  • 2 for wrap markers at the beginning of spillover lines drawn closer to text
  • 3 for all wrap markers close to text
  • Other values lead to undefined behaviour and should be avoided.

All the above macros above are bound to Ctrl+Alt+Numpad 4, but this can be changed effortlessly from the Shortcut mapper.

Note that the View -> Show Symbol -> Show wrap symbol toggle can be used to control whether Word Wrap symbols are displayed. This may be enough. Use the macros for finer appearance tuning.

Customising vertical edge display

The Settings -> Preferences -> Editing -> Vertical edge settings frame has:

  • A checkbox to toggle edge display
  • Two radio buttons
    • Background mode, to cause overflowing text to appear with a fixed background
    • Line mode, to draw a vertical line at the desired position
  • A clickable link showing the current threshold. Click on it to change the threshold.

In addition, the edge color is configured from Settings -> Styler Configurator -> Global Styles , Edge color.

Wrapping existing text at a fixed width

//z 2012-4-26 16:42:21 PM IS2120@CSDN
While text won't wrap at a fixed width as you type, you can reformat existing text using the TextFX Edit plugin. To select a width, enter it somewhere and cut it to clipboard. If clipboard is empty, holds something that is not a number, or a number not between 8 and 2048, a value of 72 is assumed. Now select the text and use the Rewrap text to (Clipboard) or 72 command. Removing the wrapping is done using the Unwrap text command from the same TextFX Edit menu.

The Split line command (Ctrl+I) will split the current line, or the selected lines, at the right edge and at word boundaries if possible. While this is not wrapping, the effect is somehow similar. It is possible to devise a macro that splits the current line/block at a fixed position, but the position is measured in pixels, which makes it harder to define correctly.

//z 2012-4-26 16:42:21 PM IS2120@CSDN

你可能感兴趣的:(How to control and trim line lengths (zz))