I would like to know how to use vim modelines in a Markdown document. Is it possible, or does modelines only recognise certain comment markers?
I have tried using this as the first line of my file:
<!-- vim: set ft=markdown -->
I also tried all these suggestions here with no luck.
Your modeline syntax is off. Add a colon at the end, and it will work:
<!-- vim: set ft=markdown: -->
Modeline doesn't care about comment markers. There are two different modeline formats:
[text]{white}{vi:|vim:|ex:}[white]{options}
This form does not use the keyword set, does not require a final colon, and most importantly, does not allow random text after options (such as -->). This means, any paired comment markers must necessarily use the second form:
[text]{white}{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text]
This form requires the use of set keyword, requires terminating options with a colon (:), and allows the terminating colon to be followed by random text.
I apply some markdown related settings according to the autocmd + filetype.
In my vimrc I have:
if has("autocmd")
autocmd FileType markdown vmap <Leader><Bslash> :EasyAlign*<Bar><Enter>
endif
Not sure that it's the most traditional way.
Related
Vim has a tendency to automagically mess with the indentations in the line I'm currently working on, as well as placing linebreaks. I want it to do an automatic indentation when I manually make a linebreak (i.e. physically hitting the Enter key), but not in any other case, I don't want it to make any linebreaks itself either, and I want these settings to be permanent.
The textwidth option controls the number of characters after which a line break will be inserted, see :h textwidth.
To turn off the insertion of line breaks while editing, the following lines should be added to .vimrc:
set textwidth=0
set wrapmargin=0
set formatexpr=
Information on the options can be obtained by the usual :h command.
Note that these options are set globally but may be overridden e.g. by a filetype plugin. If the problem persists, see :h ftplugin.
Another question is where :set textwidth=132 originates from. This may be due to an earlier misconfiguration or set from any plugin.
In my .vimrc file I have
syntax off
Suppose I want to turn on syntax highlighting on a case-by-case basis via vim's modeline? I've tried many combinations, like:
# vim: syntax on:
but I still can't get it to work. What do I need to do in the modeline?
According to :help syntax, using syntax enable or syntax on loads syntax files at runtime. But there's also apparently syntax manual which turns it on based on the syntax type you specify. Looking at the source vimscript, it says:
It installs the Syntax autocommands, but not the FileType autocommands.
You can therefore use syntax= to set the type, and that works in a modeline to either set a specific type or set none which effectively turns it off.
# vimrc
syntax manual
# In your files
# Turn it on for this yaml file
# vim: syntax=yaml:
# Or this PHP file
# vim: syntax=php:
If you want to be explicit about disabling it in a file:
# In your files
# No syntax highlighting for this file (default if omitted)
# vim: syntax=none:
Vim is a multi-buffer/window/tab editor. Changing global state (syntax, colorscheme, loading plugin etc.) per current file is a wrong habit. Luckily, modeline does not allow this.
What you can do in the modeline is to set :h local-options. Accidentally, there's an option also named :h 'syntax'. And it has the same syntax as any other option.
# vim: syntax=OFF
You don't need to set :syntax manual for this to work, as modeline has preference over filetype detection. However, if FileType event is fired manually (e.g. :setf xyz) while :syntax on then buffer's syntax could be redefined to match new filetype. Not a problem though.
I'm creating a document in latex and I would like all lines to be broken at roughly 80 characters. This is easy to do manually when writing new text, but the editing of old text often leads to lines that are longer or shorter. Fixing it leads to other lines that need to be changed and so on.
Is there an automatic way in vim to break lines after 80 characters and merge them if possible?
To make lines be only 80 characters long you can use textwidth
Assuming your latex file has the extension .tex you can add the following line to your vimrc
autocmd BufReadPost *.tex setlocal textwidth=80
To format the current paragraph you can use gqap
I use the following setup.
set textwidth=80
(either manually or in your ~/.vimrc). Then if I have a block of text in a file that I want to format I first mark it in visual mode (i.e., shift-V to switch to visual line mode and than mark all the lines you want to format) and then use gq. See also :help gq.
Vim can fold Ruby code, but not comments.
After adding this in .vimrc to change foldmethod to comments, i can no longer fold code.
autocmd FileType ruby,eruby
\ set foldmethod=expr |
\ set foldexpr=getline(v:lnum)=~'^\\s*#'
How can i configure Vim to fold both comments and code?
In my recent Vim 7.3.823 snapshot, the $VIMRUNTIME/syntax/ruby.vim (version 2009 Dec 2) has both folding for Ruby constructs and comment blocks.
Just put
:let g:ruby_fold = 1
into ~/.vimrc. (And make sure you don't have a variable named ruby_no_comment_fold.)
You could use foldmethod=marker and add {{{ / }}} markers (or other markers of your choosing) to indicate where folds begin and end.
You could also modify the file which defines ruby syntax highlighting to adjust what it considers as eligible for folding with foldmethod=syntax.
A third option would be to develop a more complex routine for use with foldmethod=expr. For example, I use the vim functions defined here to define how ruby code should be folded. It automatically defines folds for modules, classes and methods along with any comment lines that immediately precede those; and it supports the standard fold markers for folding other sections. It gets used with foldexpr=ruby#MethodFold(v:lnum).
Further information on how fold expressions should behave can be found by doing :help fold-expr. There's also a nice vimcast about that.
Setting foldmethod to indent will fold lines based on indent level,
regardless of whether the line is a comment or code.
:set foldmethod=indent
:help fold-indent
I think you are looking for
set foldignore=#
If you want to fold block comments (like /* .... */ in multiple line), watch my other post in vi.stackechange
I'm using Vim in a terminal on my MacBook Air with OS X Lion, and I can't seem to find a good plugin for Markdown syntax highlighting.
So far I've tried the plasticboy plugin and Tim Pope's plugin. The plasticboy plugin worked OK but was causing white space at the end of lines to be highlighted, and I haven't figured out how to turn that off. (It's really annoying, because every time I hit space when I'm writing it highlights the character.)
Tim's plugin didn't seem to do very much in the way of highlighting, other than maybe headers that use ###. Code blocks and bullets are ignored. I might be missing something there. I do use the .md extension on my Markdown files, so it should be picking up the filetype.
I've also seen a reference to Vim 7.3 having Markdown support built in, but without one of those two plugins I don't get any highlighting at all.
Do either of these require specific color schemes to work?
About the native syntax highlight for markdown I think it only works for files with the extension .markdown by default.
I was having problems with markdown syntax highlight for my .md files.
I tried:
:set syntax=markdown
And it worked.
So i included the following line in my .vimrc:
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
Now my vim have syntax highlight for my .md files.
BufFilePre is needed for :sav
Native syntax highlighting
Native syntax highlighting for Markdown only works by default for the .markdown file extension.
The following line in .vimrc yields the best results for both vim and gvim:
autocmd BufNewFile,BufFilePre,BufRead *.md set filetype=markdown.pandoc
Explanation:
1. Specify your Markdown flavour!
If you work with mainly one flavour of Markdown (e.g. Pandoc), be sure to mention this as well! Doing so, allows for mixing and matching of both Markdown- and Pandoc-specific Vim plug-ins. For example: I have found the vim-pandoc-syntax plug-in particularly suitable for my highlighting needs. Nevertheless, I use the more general vim-markdown-folding for Markdown folding.
By the way, only one flavour is allowed, separated by a dot, e.g.: filetype=markdown.pandoc
2. gvim requires BufFilePre
gvim requires an additional BufFilePre in the autocommand line for Markdown file type recognition with the Save As… :sav command.
This should work to disable the end-of-line space highlighting when using the plasticboy mkd plugin:
:syn clear mkdLineBreak
You could autocmd that for the necessary file extensions so that you needn't do it every time you load a markdown file.
Note that this specific highlight exists because Markdown treats lines ending with 2 or more space characters specially by inserting a <br>, so it is useful.
The plasticboy plugin uses TODO highlighting for this rule, which is a bit too much as it's designed to, by default, be really garish - yellow background - so that it stands out. You can make this less visually striking by changing that highlight rule. One quick way to do this would be something like:
:hi link mkdLineBreak Underlined
Now those end-of-line spaces will show up as underlined. Try linking to other highlight groups for something that may appeal to you more. Instead of using link you can get even more specific about those end-of-line spaces: for instance you could specify that they show up as just slightly lighter/darker than the normal background, using your own highlight command, specifying custom ctermfg, ctermbg, guifg, guibg settings.
As above, you could autocmd this to apply your specific settings.
For more information about link highlight groups, type: :help group-name and you'll see a list of groups that can be linked that themselves should helpfully be displayed using their current highlight rules. Also: :help highlight.
In Tim's plugin the .md extension works only for README.md because filetype.vim specifies so.
" Markdown
au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,README.md setf markdown
If you don't like putting all of your configuration in ~/.vimrc, you can create ~/.vim/ftdetect/markdown.md (or its equivalent on Windows) with the following contents.
au BufNewFile,BufRead *.md setf markdown