How to auto-break a long word when auto-wrapping text - sublimetext3

I know we can use "word_wrap": "auto" in the User settings to make Sublime Text 3 auto wrap text, but how can I make it break a long word when wrapping?
In a sentence like:
a long word aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
I want it to
a long word aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaa
but not:
a long word
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
First, I saw advice to add "auto_wrap_break_long_word" : false, to the setting file, but it made no sense to me.
And then, I get advice from comments by using Sublime Wrap Plus
However, it is not what I want.
The Readme of Sublime Wrap Plus says:
Enhanced “wrap lines” command for Sublime Text 2 or 3. This is for the manual hard line wrap command. It does not affect the automatic soft line wrapping.
But what I want is not “HARD line wrap” because it will add real some line breaks and change the text file. And what I want is to break long word in “SOFT line wrap”(which will not change texts but only change how it looks)
In fact , I've tried to install the Sublime Wrap Plus package and set "WrapPlus.break_long_words":true in Preferences >> Settings — User.
But nothing changed about my SOFT line wrap.
THANKS for all advice anyway!

Related

Sublime Text 3 AutoWrap breaks double quotes

I installed a package called Sublime Wrap Plus to insert line break after wrapping text at 80 characters.
However, this breaks for example, the "long long long quotes" into
"long long long...
long quotes"
Which is a syntax error. Anyone knows how to fix this?
The README is clear about this plugin detecting where to wrap paragraph text, not source code. Based on their epilogue, you should open up an Issue for additional features.
Code wise, if you do want to add additional logic to the mix, its written in Python and uses if statements like this one to parse the selected area as you see fit.

Sublime Text Tab Indentation Indenting Entire Paragraph?

I've recently discovered Sublime Text and since I'm new to using text editors like this, I had a question about indentation. When I'm not using Sublime for code, I type up my writing with it before taking it to a word processor for further processing. I've been having a little bit of trouble with the indentation regarding paragraphs. When I tab a paragraph, it seems to tab the entire paragraph rather than just the first line. It looks like the first paragraph in this picture.
I've tried using the wrap paragraph function which seems to allow me to tab just the first line but when I paste it in Microsoft Word, it retains its wrap setting. Is there anyway that I can just indent just the first line without having to wrap it? Or am I approaching it all wrong?
For a global effect you can add this to Preferences > Settings-User:
"indent_subsequent_lines": false
Because I code too, I add it to Preferences > Settings-More > Syntax Specific-User.
To do this properly, open a .txt file (or your preferred file type) and it will open/create a settings file for the specific file type. Then paste in this and save:
{
"indent_subsequent_lines": false,
"tab_size": 4,
"translate_tabs_to_spaces": false
}
Sublime is a code editor, not a word processor. Although you may use it to type any kind of (plain) text, it's focused on editing code.
Sublime indents lines in a way that makes sense for a programming language. If you're looking for a tool to write anything like a report or a novel, maybe you should consider another tool.

In Vim, how to keep characters concealed even when cursor enters that line

I may have a unique situation here. I want gVim (gui version, in Linux) to keep concealed characters concealed no matter what, even when the cursor is on that line or that character gets selected. (It should be as close to if the characters never existed as possible.) Currently the concealed characters show themselves when the cursor enters that line, which causes text to jump around when scrolling and when selecting text.
We are using gView (read-only gVim) to view logs, so as to take advantage of its robust syntax highlighting. Problem is, these logs contain lots of escape characters and TTY color codes, that make reading difficult. (^[33mSomeText^[0m)
I'm using this line to hide them:
syntax match Ignore /\%o33\[[0-9]\{0,5}m/ conceal
Since the files are viewed by non-vim-experts, it looks glitchy and broken when the text un-conceals itself. (And also looks glitchy and broken if the color codes are present, and also looks glitchy and broken if the color codes are blacked-out to become invisible, but still show when selected and appear after copy/paste.)
This should be fine because these files are opened read-only in gview, with an extra set nomodifiable making it even more difficult to save the file. While it's possible to edit and attempt to save the logs, doing so is considered both an invalid thing to do, and a harmless thing to do, and requires enough Vim skills that if someone manages to edit a file they know what they're doing. The problem with being able to edit a line with concealed text does not apply.
If 'conceal' can't be configured to keep hidden text hidden no matter what, an acceptable alternative would be to replace the TTY color codes with whitespace when the file gets opened. But, this has to be done in read-only mode, and we can't have gview throwing up a save dialog on closing the window because the file has been modified by its .vimrc.
Note: I am in full control of the .vim script file sourced when these are read, but cannot control the existence of the TTY color codes or the code that opens the log files in gview. (i.e. I can't pass it through sed or anything like that.) The ideal solution is anything that can transparently nuke the color codes from within a .vimrc, but I'll hear any suggestions. The 'conceal' feature is just my most promising lead.
So, any ideas how to permanently get rid of these on file view without dialogs popping up on close?
:help conceal
When the "conceal" argument is given, the item is marked as concealable.
Whether or not it is actually concealed depends on the value of the
'conceallevel' option. The 'concealcursor' option is used to decide whether
concealable items in the current line are displayed unconcealed to be able to
edit the line.
:help concealcursor
Sets the modes in which text in the cursor line can also be concealed.
When the current mode is listed then concealing happens just like in
other lines.
n Normal mode
v Visual mode
i Insert mode
c Command line editing, for 'incsearch'
'v' applies to all lines in the Visual area, not only the cursor.
A useful value is "nc". This is used in help files. So long as you
are moving around text is concealed, but when starting to insert text
or selecting a Visual area the concealed text is displayed, so that
you can see what you are doing.
Keep in mind that the cursor position is not always where it's
displayed. E.g., when moving vertically it may change column.
Also, :help conceallevel
Determine how text with the "conceal" syntax attribute |:syn-conceal|
is shown:
Value Effect ~
0 Text is shown normally
1 Each block of concealed text is replaced with one
character. If the syntax item does not have a custom
replacement character defined (see |:syn-cchar|) the
character defined in 'listchars' is used (default is a
space).
It is highlighted with the "Conceal" highlight group.
2 Concealed text is completely hidden unless it has a
custom replacement character defined (see
|:syn-cchar|).
3 Concealed text is completely hidden.
Only one command is needed: set concealcursor=n
I might have a better idea—you can pass it through sed (using %!sed) or really do a bunch of other :substitute commands—whatever edits you need to get rid of the color codes.
When you’re done, make sure to set nomodified—this forces vim to think there haven’t been any changes!

Nicely formatting long //comments in vim

When I am typing a long code comment in VIM, I manually judge when each comment line reaches 80 characters, then manually typically press < enter >< tab >//< space > and continue on. Likewise it is awkward editing comments, adding or removing text.
// The comments I have to use
// look like this
Ideally, I'd like some kind of comment mode, where you type text, and the 80 line character limit and the // symbols are sorted out automatically. Does anything like this exist?
You can turn on formatting options with set formatoptions=tcq (with tcq each representing an option, there are others as well). Use h formatoptions to see what the various flags are.
In this case you probably want to use set fo+=a.
Personally though, I prefer to just type my comments normally, then when I'm done run gqip. gq is the formatting command, ip for in paragraph. Make sure the comment block is not next to code though or it will suck that up when reformatting your comment.
I use :set textwidth=80 to set the formatting width (actually, 80 is the default).
Then I move the cursor to the first line of the comment and in command mode press gq} to format the comment. It also works for other comment types from other programming languages such as # and /* ... */
A variant on #Alex's suggestion is to select the lines in visual mode and then press gq. This allows you to avoid the problem of gqip reformatting code as well.
Pressing capital V selects an entire line, then you can just move up or down to highlight all the comments and press gq.

How do you enable word wrap in vim when printing

I wanted to print a simple text document and make sure words wrap on word boundaries. I tried both
set linebreak
and
set wrap
but when printing, it just breaks on the right column in the middle of words. Is this possible for printing?
You are creating a text file without any built-in linebreaks so each paragraph is a single "line", even though with linebreak and wrap set, it looks like they are multiple lines). This is why printing breaks at fixed places. (According to http://www.vim.org/htmldoc/various.html#printing it does not seem like you can have vim respect linebreak/wrap during print.)
To avoid this, if you want text to wrap while you are editing, do
set textwidth=70
to wrap at the 70th column. If you want your file to have long lines (e.g., so it formats fine when loaded into MS Word or something), then you will have to pre-process the text version before printing it. So, for example, you can try:
fmt file.txt | lpr
or if you have enscript installed, you should be able to try:
enscript --word-wrap file.txt
to print. An existing file can be wrapped by running in vim:
gggqG
that is, 'gg' to go to start of file and 'gqG' to reformat 'gq' from the current position (i.e. the first line) to the last line (by going to 'G'). 'gq' will respect your current textwidth setting.

Resources