Disable syntax hightlighting in vim only for specific buffer - vim

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.

Related

Setting fdm=marker in the first line of .vimrc

This is the first line of my .vimrc file:
" vim:fdm=marker " Treat comments as folds
Every time I edit .vimrc I get this error (and no other errors):
"~/.vimrc" 409L, 12674C
Error detected while processing modelines:
line 1:
E518: Unknown option: "
Since I have taken this line from some other .vimrc, it should work in my setup as well. Why doesn't it? How can I fix this?
The modeline syntax is wrong. I doubt it worked in the vimrc you copied it from. If you read :h modeline you will find that the modeline is trying to interpret the second quote as an option. Since there is no option called quote it fails.
You should use the second modeline syntax if you want to put a comment after the modeline and get something like the following
" vim: set fdm=marker: " Treat comments as folds
:h modeline copied below.
modeline vim: vi: ex: E520
There are two forms of modelines. The first form:
[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)
Examples:
vi:noai:sw=3 ts=6
vim: tw=77
The second form (this is compatible with some versions of Vi):
[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

how to get the digraph key or unicode from a special character

I am configuring tmux & powerline. I would like to change the default separators in tmux status line. I managed to figure out where to do it, however I could not get the special character that I want.
I want to type, in Vim, a left/right pointing triangle that spans the whole line-height, but the only thing I could find is a small triangle (unicode : 25B6,25BA,25C0,25C4...)
There is a big right pointing triangle already in a powerline configuration file, which I could copy and paste, but I want to know its unicode and want a left one. Is there a way to get the unicode from the symbol in Vim or anywhere else?
You can get the codepoint value of a character in Vim by positioning the cursor on the character in question and typing either ga or :ascii.
You can either use ga in command mode or :ascii on the command line (even though it says ascii, it shows information for general encodings)
You may add a permanent preview of current character in your status line (see :h statusline), eg.:
:let &statusline = &statusline . "\ [%03b\ 0x%B]"

#vim: set only sort of working

I have .zsh-theme files (from oh-my-zsh), but they are not syntax highlighted. I was able to get this done pretty easily with
autocmd BufEnter *.zsh-theme set filetype=sh
However, before I did that I tried adding a vim meta comment for a specific file
#vim: set filetype=sh
The addition of the # apparently makes vim detect the file as a conf file, but it seems that this command is ignored (i.e. it is not detected as a sh file in spite of the comment). Is there any reason this may be happening?
Get rid of the word set (and add a space after the comment symbol)
# vim: filetype=sh
This fits with the first form of modelines
There are two forms of modelines. The first form:
[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)
The syntax for this type of modeline is:
[text]{white}{vi:|vim:|ex:}[white]se[t] {options}:[text]
That is, try adding a space before vim:, and a trailing colon:
# vim: set filetype=sh:
You can find everything about modelines in
:h modeline
:h 'modeline'

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!

Is there a vim equivalent to emacs's x-symbol?

I am working on writing a vim plugin and I would like to have some way of displaying some tokens in the buffer using an alternative glyph to improve readability. Is there an existing approach to this problem? Is it even possible within vim?
What I have in mind is something like the emacs package x-symbol -- http://x-symbol.sourceforge.net/.
You'd get the very basics with
:se list
and the listchars option.
That is not very extensible though. For more involved work you can create concealing syntax rules:
Concealing
See
:he syn-conceal
:he 'cole'
:he hl-Conceal
Excerpts:
Syntax Rules
conceal *conceal* *:syn-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.
concealends *:syn-concealends*
When the "concealends" argument is given, the start and end matches of
the region, but not the contents of the region, are marked as concealable.
Whether or not they are actually concealed depends on the setting on the
'conceallevel' option. The ends of a region can only be concealed separately
in this way when they have their own highlighting via "matchgroup"
cchar *:syn-cchar*
The "cchar" argument defines the character shown in place of the item
when it is concealed (setting "cchar" only makes sense when the conceal
argument is given.) If "cchar" is not set then the default conceal
character defined in the 'listchars' option is used. Example: >
:syntax match Entity "&" conceal cchar=&
See |hl-Conceal| for highlighting.
Conceal Level
'conceallevel' 'cole' *'conceallevel'* *'cole'*
number (default 0)
local to window
{not in Vi}
{not available when compiled without the |+conceal|
feature}
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.
Note: in the cursor line concealed text is not hidden, so that you can
edit and copy the text. This can be changed with the 'concealcursor'
option.

Resources