Vim highlighting weird parts of FORTRAN - vim

I am using VIM theme molokai, if that makes any difference.
I have been learning FORTRAN lately and when I write a FORTRAN program using VIM, I have weird coloring depending on my whitespace.
For instance, if I tab things over as is (no indenting) I have this purple highlight on only a portion of the word (sometimes it isn't there, notice the PRINTs and READs).
If I tab it over it looks normal:
I am new to VIM (not to mention FORTRAN) so I am not sure what's happening, I don't mind tabbing over all the time but I think it looks a little ridiculous if the whole program is wasting that column of white space.

If you search :help fortran, you'll get a list of options that you can set.
These are the fortran options I set in my own .vimrc file. (I don't work with fixed-format code though) I know there are one or two fortran specific scripts that are available online, but I don't use them.
let fortran_free_source=1
let fortran_have_tabs=1
let fortran_more_precise=1
let fortran_do_enddo=1

Vim was using fixed-format/punchcard when I created a new .f90 file. In order to differentiate it, I found this.
I copied it to my ~/.vim/syntax/ directory and added the following lines to my .vimrc (also specified at following link)
nmap <S-F> :set syntax=fortran<CR>:let b:fortran_fixed_source=!b:fortran_fixed_source<CR>:set syntax=text<CR>:set syntax=fortran<CR>
nmap <C-F> :filetype detect<CR>
Allowing me to bind Shift-F to switch formats, and Ctrl-F to auto detect.

You can install the Fortran F90/95 indentation rules script in ~/.vim/after/indent, and it should fix the index errors.

Related

How do you set up formatting in vim?

Earlier, when I used open .py files in vim on ubuntu, they would be well formatted, with separate colours for separate segments of the program. Now, when I am using VIM on ubuntu, all the text in the .py file appears black. How can I correct this?
Formating in Vim means text formatting; e.g. indenting lists and breaking long lines. You're concerned about syntax highlighting, which is purely about the visual appearance of code.
First, it needs to be turned on.
:syntax on
does that.
Second, you probably want Vim to automatically detect the used language (e.g. Python) and choose the correct syntax plugin for you.
:filetype on
does that, though you usually enable more via :filetype plugin indent on.
To make these settings persistent, put them into your ~/.vimrc configuration.
Check man vim. In a nutshell, find a copy of a vimrc file, one might be under /usr/share/vim/ subtree. It may be named vimrc_example.vim. Copy to your home directory and rename it as .vimrc.

Vim Code Folding for Scilab

I've just recently started to use the folding functionality of vim and it's very helpful for the languages that it works really well for.
My issue lies in the way vim comments out the fold markers in scilab code. It defaults to
/*{{{*/ and /*}}}*/
which works great in languages like C, but is not actually a comment in scilab. I get a multiplication error when i try to run the code.
I've tried adding
autocmd FileType scilab set fmr=//{{{,//}}}
to my .vimrc file which doesn't quite do what I'd like. It results in
/*//{{{*/ and /*//}}}*/
which are still not comments. The code "folds" fine but becomes unusable. I could set up a macro to replace every instance of "/*" with "//", but that could have unintended consequences when applied globally to a file.
So the question is: how can i setup vim fold markers comments for scilab files such that it will not render the file unusable?
You do not add the comments to 'foldmarker' itself, there's the 'commentstring' option that influences how Vim surrounds the fold markers (when creating folds with zf). Try setting
:setlocal commentstring=//%s
for your scilab filetype. (Put the command in ~/.vim/after/ftplugin/scilab.vim to make it permanent.)
It sounds to me like vim doesn't understand how SciLab comments work. I'm not sure if vim comes with SciLab syntax logic these days, is syntax highlighted correctly in your SciLab files? If not, you can get the syntax file from here.
Is there a particular reason you want to use marks? They aren't actually needed. If you don't want vim to auto-fold by syntax or indentation level, you can still manually define folds with
:set foldmethod=manual
That lets you select a chunk of text in visual mode and make it into a fold with 'zf'. No marks required.
More info on various vim folding techniques here.

Text highlighting and cross-reference warning in Vim LaTeX with harvard.sty on MikTex 2.9

I used Vim LaTeX for six months with natbib and had no problems. But to use a new bib style file (i.e., rfs.bst) I started using harvard.sty, which gives me two minor problems:
(1) syntax highlighting is not complete; specifically for \citeasnoun, Vim only highlights the \cite portion. With another Vim plugin (Vim-plugin-R) I can update the syntax highlighting, but I can't figure out how to do this in Vim. I refreshed the databases in MikTex, but that didn't work.
(2) Vim LaTeX is automatically rerunning as necessary to get references correct -- the status window in Vim shows it going through several runs and the results are as desired -- but I still get this warning:
|| LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
How can I fix these? Thanks!
As for the syntax highlighting issue, you could try the following.
In your personal vim settings folder -- typically $HOME/.vim/ on Unix-based systems, or C:\Users\<yourname>\vimfiles (?) on Windows (probably the first entry shown in :set rtp?), create a directory (if there isn't one already) called after, and create a subdirectory of it called syntax, and in it create a file called tex.vim. So the file will be $HOME/.vim/after/syntax/tex.vim for Unix or C:\Users\<yourname>\vimfiles\after\syntax\tex.vim on Windows. (I hope a Windows user will confirm this, since I'm on Linux.)
In that file, put the following line:
syn match texRefZone '\\citeasnoun\%([tp]\*\=\)\=' nextgroup=texRefOption,texCite
Then when you open a LaTeX file, \citeasnoun should be treated just like \cite as for Syntax Highlighting (...that's assuming you're using the default Syntax Highlighting rules for LaTeX files that came with vim 7.3 anyway....)
I think your other question is answered in the comments.

Latex and Vim usage

How can I use Latex effectively in VIM?
Is there a way to configure compile errors by highlighting the line in vim?
I have syntax highlight. What are other recommended add-ons? Is a makefile the recommended way to compile a latex file to pdf?
TexWorks lets you open and replace the opened pdf everytime it's recompiled. Is there a plugin to do something similar in vim?
I've just begun playing around with LaTeX-Box. It seems like a good plugin. I, also used VIM-LaTeX for a while, but I didn't really like the key mappings, and it seemed a bit to heavyweight as Jeet described.
I like LaTeX-Box so far because it used latexmk to compile, which is what I was using anyway. Latexmk will sit in the background and watch your .tex file for changes, and then automatically compile for you. And if you use a pdf viewer which refreshed changes (such as evince on Linux) you can see updates every time you change. Adding
let g:LatexBox_latexmk_options = "-pvc -pdfps"
to my .vimrc got latexmk working properly. You also need the latexmk script somewhere on you PATH. The key mapping to start latexmk is the same as Vim-Latex's compile: '\ll' (that's lowercase LL).
I also use SuperTab plugin for completions, which is great. And I took the dictionary files from Vim-LaTeX so I have a ton of auto completion words to use. This dictionary file is: ftplugin/latex-suite/dictionaries/dictionary in the vim-latex files. What I did was copy this file into ~/.vim/dictionaries/ and renamed it 'tex' then I added these lines to my .vimrc file:
set filetype on
au FileType * exec("setlocal dictionary+=".$HOME."/.vim/dictionaries/".expand('<amatch>'))
set complete+=k
Then if I type the beginning of a latex command and hit 'tab' I will get a list of completions. Pretty handy. BTW that 'au' command in the vimrc will also load dictionaries for any other filetypes if you want. A useful trick.
check out vim latex
If you use vim latex put the following in your .vimrc:
let g:Tex_DefaultTargetFormat='pdf'
and it should compile to pdf by default. (I think the default compilation key
is \ll).
You can also check AutomaticLatexPlugin, it has many nice features (see the features list).
Its main point is to compile the document in the background using autocommands, so that you are free from compilation cycle. This works nicely on Linux and MacOs. It contains (extended version of) Latex-Box.
vim-latex is great. But I found it too heavyweight for my tastes. I prefer more of a "Vim with LaTeX compile & view" approach, rather than "A LaTeX IDE with Vim key-bindings". So I rolled my own: 'TeX-PDF: Lightweight "stay-out-of-your-way" TeX-to-PDF development support'.
Also check out: "LaTeX Help : Help for LaTeX in vim.help format" for calling up help of LaTeX from within Vim.
I personally can get by on:
autocmd BufNewFile,BufRead *.tex set makeprg=pdflatex\ %\ &&\ open\ %:r.pdf
where open is Mac OS X specific. Linux users will want a different command to view their compiled file after running make. This works best if you have mapped a key to write and then run make (and you should - once you have single key save and compile, you'll never go back).

Is vim able to detect the natural language of a file, then load the correct dictionary?

I am using several languages, and currently I am obliged to indicate to vim with which of these the spell check must be done. Is there a way to set up vim so that it automatically detects the correct one? I vaguely remember that in a previous version of vim, when the spell check was not integrated, the vimspell script made this possible.
It would be even better if this could apply not only to a file but also to a portion of a file, since I frequently mix several languages in a single file. Of course, I would like to avoid to load several dictionaries simultaneously.
I don't know if there is a way to autodetect it, but if you put vim:spell:spelllang=foo,bar,baz at the bottom of the file, vim will set the spellchecking languages to foo, bar, and baz when the file is opened. Note that you must put at least one space before that text, or vim will think it's part of the file.
Since vim is missing this feature, I found it useful to define shortcuts like these in .vimrc:
command! Nb :set spelllang=nb
command! En :set spelllang=en

Resources