Setting fdm=marker in the first line of .vimrc - vim

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

Related

Redefine word movement stop characters for editing Clojure code in Vim/GVim

When editing Clojure code in Vim/GVim, I frequently use the w word-motion command (and its cousin b for backwards word-motion). However, in the default Clojure configuration Vim/GVim ignores common word separator chars such as hyphen, slash, and period. The following Clojure symbol shows all three:
clojure.core/select-keys
In this case, we want the w and b word-motion commands to stop at any of the non-alphabetic characters.
How can I modify the default Vim configuration to recognize these word boundaries in Clojure?
The answer is to use the Vim feature autocmd to modify the iskeyword setting for Clojure files. Specifically, add these lines to your ~/.vimrc file:
" Remove the period `.`, hyphen, `-`, and slash `/` as keyword chars so "word" movement will stop
" on these chars (i.e. in a namespace like `proj.some.long.ns.name` or a symbol like `my-clojure-sym`)
" Must do one at a time for 'string lists'
autocmd BufWinEnter,BufNewFile,BufRead *.clj* set iskeyword-=.
autocmd BufWinEnter,BufNewFile,BufRead *.clj* set iskeyword-=-
autocmd BufWinEnter,BufNewFile,BufRead *.clj* set iskeyword-=/
When loading a file with the suffix .clj*, we remove the three characters period, hypthen, and slash from the iskeyword string list, so they are no longer recognized as part of a "keyword". That is, they become word-separator characters. Then, the w and b word-motion commands will stop there, as we were seeking.
I add an answer for ideavim users since, this is the first google result.
Add this line to your .ideavimrc file:
set iskeyword=#,48-57,_,192-255,?,-,*,!,+,/,=,<,>,.,:,$

vim-airline: what is "! trailing[1]"

At the right of my vim-airline display, I have ! trailing[1].
I'm assuming this means trailing whitespace of some sort, but how do I read what vim-airline is telling me and what am I supposed to do?
That means you have a trailing whitespace on the first line ([1]).
You can add to your .vimrc the following:
set list " Display unprintable characters f12 - switches
set listchars=tab:•\ ,trail:•,extends:»,precedes:« " Unprintable chars mapping
That'll display whitespace chars. You can toggle it with :set invlist.
Airline is telling you that on line 1 you have trailing whitespace, which is usually something you want to get rid of.
So go to the line and delete it (1G$gelD).
It’s a good feature, but you can turn it on/off with:
:AirlineToggleWhitespace
More info on trailing whitespace here.
To turn off the trailing whitespace check at startup, add to your vimrc:
let g:airline#extensions#whitespace#enabled = 0

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.

#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'

Change wrap width in a text file using Vim

I want to format srt subtitle text files to avoid wrapping problems on my media player.
I need to set a line wrap width to a number of characters e.g. 43
I can do this with Editplus, its a built in function and works well. The reason I want to do it in Vim, firstly Editplus is only available on the PC and the secondly Vim is badass.
I have found the following solution on the net..
:set tw=43
gggqG
It does work, but not exactly how I want it.
E.g.
I have this text:
557
00:47:39,487 --> 00:47:42,453
I will have to complete some procedures,
and I asked you to check out what they are for me
after I format it, I get:
557 00:47:39,487 --> 00:47:42,453 I will
have to complete some procedures, and I
asked you to check out what they are for
me
It seems to ignore line breaks/CRs. As you can see the "I will" has been added to the first line.
How do I get it to not ignore line breaks?
EDIT: apoligies about the formatting, first time using stackoverflow!
You could use the whitespace option of formatoptions and make the lines you want to wrap end in whitespace.
:set tw=43
:set fo+=w
:g/^\a/s/$/ /
gggqG
The third line adds a space on the end of any line starting with a letter and fo+=w stops gq from joining lines that don't end in spaces.
See:
:help fo-table
:help 'formatoptions'
:help gq
:help :g
Edit in response to comments
:g/^\a/s/$/ /
This translates to:
:g/ " Search the file
^\a " For lines starting (^) with an alphabetic character (\a - equivalent to [A-Za-z])
/ " Then on each line that the regexp matches (i.e. each line starting with an alphabetic character)
s/ " Substitute...
$ " The end of line (zero-width match at the end of the line)
/ / " With a space (slashes are delimiters)
The global (:g) command will only operate on the current file, but the textwidth and formatoptions lines will last for the whole session. If you want those options to only be used on the current buffer, use :setlocal instead:
:setlocal tw=43
:setlocal fo+=w
:help :setlocal
If the only lines you want to wrap are the ones that start with text (ignore the ones that start with numbers) you can use the following.
:g/^[a-zA-Z]/normal gqq
This will run p00ya's command on each text line in the file.
With the following text (i.e. only 3 lines):
557
00:47:39,487 --> 00:47:42,453
I will have to complete some procedures, and I asked you to check out what they are for me
Use gqq (format current line) on the 3rd line after setting tw. Formatting by paragraph will not work since vim will treat all 3 lines as part of the same paragraph (paragraphs only end with a blank line).
While not exactly robust (or elegant), if you can assume that the subtitle lines do not begin with numbers, you can configure Vim to treat them as comments.
:set comments=:0,:1,:2,:3,:4,:5,:6,:7,:8,:9
gggqG
Lines starting with 0-9 will be treated as comments and won't be merged together with the text.
I can't see exactly what the issue is due to the formatting of your post, but you might want to checkout the 'formatoptions' setting in vim's help, specifically :he fo-table which contains a bunch of customization flags.
This link might be useful.

Resources