How to set display the indentation symbol when wrapping a new line in Vim,when input it will disappear - vim

Does anyone knows how to set this? Vim will display the indentation symbol when wrapping a new line, When input it will disappear.

These options will make sure trailing spaces are displayed as dots (or whichever other character you set instead). As you say, the dots disappear once another character is entered, as the spaces are then not trailing any more. Look through other listchars options as well, if you want to see e.g. tabs or other cool stuff.
set listchars=trail:·
set list
(See :help 'listchars', :help 'list')

Related

How to create dashed lines in terminal for indentation

I'm using vim in Mac terminal. I want to have dashed lines in front of each line to indicate the tabs and indentations. Is there a way to configure this in .vimrc? The editor shown in the picture is sharelatex.
Many thanks!
Set listchars to that symbol (you might want one of these: ¦⁞⋮┆┊┋┇︙⸽) and a space:
set listchars=tab:¦\
That is "tab", followed by a colon, your desired character, a backslash and a space.
In addition, to see the effect, you have to set the list option:
set list
listchars can be used to set more characters to show in special places, e.g. eol to show a character at the end of a line, or trail to see trailing spaces. To set multiple ones, seperate them by commas:
set listchars=tab:¦\ ,trail:·

Disable syntax hightlighting in vim only for specific buffer

I want to disable syntax highlighting but only for a specific buffer. I tried using modeline at the end of the buffer:
#vim:syntax off:
and
#vim:set syntax=off:
But it is not working.
You need a space (minimally) between the comment symbols and vim for mode lines to be parsed. The first one is also missing an equals sign.
# vim:syntax=off:
Or
# vim:set syntax=off:
If you look at :h modeline you will see that there can be any leading text before vim: but there needs to be whitespace after that text.
The two forms fix the patterns
[text]{white}{vi:|vim:|ex:}[white]{options}
[text] any text or empty
{white} at least one blank character (<Space> or <Tab>)
{vi:|vim:|ex:} the string "vi:", "vim:" or "ex:"
[white] optional white space
{options} a list of option settings, separated with white space
or ':', where each part between ':' is the argument
for a ":set" command (can be empty)
Or
[text]{white}{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text]
[text] any text or empty
{white} at least one blank character (<Space> or <Tab>)
{vi:|vim:|Vim:|ex:} the string "vi:", "vim:", "Vim:" or "ex:"
[white] optional white space
se[t] the string "set " or "se " (note the space); When
"Vim" is used it must be "set".
{options} a list of options, separated with white space, which
is the argument for a ":set" command
: a colon
[text] any text or empty
tl;dr Switch to the manual mode (:sy manual), enable syntax highlighting with :se syn=ON.
What :sy on (:syntax on) does under the hood is sets the 'syn' ('syntax') option for all the active buffers, and makes vim set the 'syn' option for any new files you open. :sy manual disables the latter automatic behavior. So to enable syntax highlighting for a buffer in the manual mode you've got to: :se syn=ON. To make it clear :sy manual doesn't affect the open buffers. They remain highlighted. But when you later do :se syn=ON, syntax highlighting is enabled for all the active buffers.
In other words if you're going to open a big file, you might want to do :sy manual before that. Then the file will open unhighlighted. If you open another file (you didn't open before in this vim instance, i.e. the inactive buffer doesn't exist) it will also open unhighlighted. To enable syntax for this (supposedly not big) buffer you'd do: se syn=ON. When you no longer need to work with the big file, you do: :sy on.

Prettier tab symbols in vim

I’m trying to make vim look more similar to what I’m used to in Coda 2.
In my .vimrc I have this line:
set listchars=tab:➝.,extends:#,nbsp:.
That makes my whitespace look like this:
However, I’d rather those dots weren’t visible, so it’d look more like this:
I've tried using a space character, but I end up with this warning:
E474: Invalid argument: listchars=tab:➝
What character can I use that won’t be visible on the screen, and also won’t throw a warning?
You can escape the space character like this:
set listchars=tab:➝\ ,extends:#,nbsp:.
In listchars tab: takes to characters. Directly from the help file:
tab:xy Two characters to be used to show a tab. The first
char is used once. The second char is repeated to
fill the space that the tab normally occupies.
"tab:>-" will show a tab that takes four spaces as
">---". When omitted, a tab is show as ^I.
So you can just use a space instead of the dot that you are using for the second character, it does have to be escaped though: set listchars=tab:➝\ ,extends:#,nbsp:. to get the result you want.

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!

VIM: How to change the Showbreak Highlight color without using the NonText Color-element

I noted that the 'showbreak' symbol is highlighted with the highlight "NonText" color-element. NonText is also used for the EOL Characters.
I would like to keep the highlight-color for the EOL characters but want to change it for the showbreak symbol is that possible?
Another problem is that my showbreak symbol is not displayed.
I would like to use this symbol "↳" and put it in the linenumbers column (using set cpoptions+=n). I can't find out how to display the symbol and how to put a space after the showbreak symbol (between the text and the symbol).
Can anyone help me?
I don't think you're going to get highlighting to be different than the EOL character, at least I am not aware of a way to do that.
For the second part I can help with. I was able to get "↳ " to show up in my line number column with the following settings:
let &showbreak = '↳ '
set wrap
set cpo=n
Note that there is a space after the ↳. This lines up nice until you have > 9 lines in the file. If you wanted it to line up with the last character of the number column regardless of the number of lines I'm not sure what you're going to have to do.
Edit: I've recently written a proof-of-concept function for someone on IRC that highlights the first character on a line that has been wrapped with a different highlight group. It hasn't been tested much but it seems to work. Not exactly what you're looking for but maybe it's worth a look.
:help hl-NonText makes it pretty clear that you cannot have different colors for the 'showbreak' string and other non-text strings, of which eol is a member (see :help 'listchars'):
NonText
'~' and '#' at the end of the window, characters from 'showbreak' and
other characters that do not really exist in the text (e.g., ">"
displayed when a double-wide character doesn't fit at the end of the
line).
If you're willing to accept this limitation (#elliottcable) hi! link NonText LineNr will match the 'showbreak' string to the line number colors.
If you really wanted to get clever, as a compromise you could create a mapping or command to toggle between ':set list' and ':set nolist' that would also adjust the NonText highlight setting simultaneously.
If you use :set relativenumber (added in vim 7.3), :set showbreak=↳\ \ \ will reliably keep your 'showbreak' neatly lined up since the number width will not change as you navigate through the file. (This in addition to the :set cpo+=n and :set wrap #Randy Morris mentioned in his answer.)
You'll definitely need UTF-8 for the ↳ character, since it does not appear in other encodings. I'd strongly recommend you carefully document your encoding problems, with details about how to reproduce them along with your OS, its version, and the :version output of vim, and post them as separate questions. UTF-8 should be helping you wrangle multiple languages rather than being an impediment.

Resources