Frage

(This may be more superuser question than an SO question, but I think it's very localized to Stata users.)

I made a new install of Vim, but now I've lost smart indenting with Stata. I get syntax highlighting out of the box, but not indenting, even though I have filetype indent on. Is there an additional indent file that I need to add for Stata? I don't see this mentioned in the note on text editors.

I tried set smartindent, but this didn't work either (and it seems that the Vim wiki on source code indenting recommends against smartindent.

Any ideas? I'll paste my _vimrc (I'm on Windows 8.1 with Vim 7.4), but I'm not sure that I have a _vimrc problem (R and LaTeX work great), but a /vimfiles issue.

" ----------------------------------------
"  from sachet http://yoursachet.com/
" ----------------------------------------

set nocompatible

" Pathogen
call pathogen#infect()
call pathogen#helptags()

set background=dark
colorscheme solarized

" ----------------------------------------
"  from my original _vimrc
" ----------------------------------------

set expandtab
set shiftwidth=4
set softtabstop=4
set textwidth=78
set visualbell
set guifont=Source\ Code\ Pro:h11

"  vim-pandoc
" ----------------------------------------
" location of .bib files
let g:pandoc_bibfiles=['C:\Users\richa_000\texmf\bibtex\bib\library.bib']

" vim-R-plugin
" ----------------------------------------
" minimum requirements 
set nocompatible
syntax enable
filetype plugin on
filetype indent on

" Vim LaTeX Suite
" ----------------------------------------
" http://vim-latex.sourceforge.net/documentation/latex-suite.html
" minimum requirements for vimlatexsuite
" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
"filetype plugin on " redundant with vim-R-plugin settings

" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash

" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*

" OPTIONAL: This enables automatic indentation as you type.
"filetype indent on " redundant with vim-R-plugin settings

" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'

" " this is mostly a matter of taste. but LaTeX looks good with just a bit
" " of indentation.
" set sw=2
" TIP: if you write your \label's as \label{fig:something}, then if you
" type in \ref{fig: and press <C-n> you will automatically cycle through
" all the figure labels. Very useful!
set iskeyword+=:

" Fix double brackets problem
" http://tex.stackexchange.com/questions/105758/vim-latex-adds-extra-brackets-when-typing-empty-brackets
set backspace+=start

" For cite completion
let g:Tex_BIBINPUTS='C:/Users/richa_000/texmf/bibtex/bib/library.bib'

" compile pdfs from dvi
let g:Tex_FormatDependency_pdf='dvi,ps,pdf'
let g:Tex_CompileRule_pdf='ps2pdf $*.ps'
let g:Tex_DefaultTargetFormat='pdf'

" pdf viewer
let g:Tex_ViewRule_pdf='C:/Program Files (x86)/SumatraPDF/SumatraPDF' 

" Stata http://fmwww.bc.edu/repec/bocode/t/textEditors.html#vim
" -------------------------------------------------------
" STATA DO-FILE SCRIPTS
fun! RunIt()
    w
    " *** CHANGE PATH AND NAME TO REFLECT YOUR SETUP ***
    !start "C:\ado\personal\rundo.exe" "%:p"
endfun

:map <F8> :<C-U>call RunIt() 
:imap <F8> <Esc>:<C-U>call RunIt() 

fun! RunDoLines()
    let selectedLines = getbufline('%', line("'<"), line("'>"))

    if col("'>") < strlen(getline(line("'>")))
        let selectedLines[-1] = strpart(selectedLines[-1], 0, col("'>"))
    endif
    if col("'<") != 1
        let selectedLines[0] = strpart(selectedLines[0], col("'<")-1)
    endif

    let temp = tempname() . ".do"
    call writefile(selectedLines, temp)

    " *** CHANGE PATH AND NAME TO REFLECT YOUR SETUP. USE \\ INSTEAD OF \ ***
    exec "!start C:\\ado\\personal\\rundo.exe " . temp

    " Delete the temp file after Vim closes
    au VimLeave * exe "!del -y" temp
endfun

:map <F9> :<C-U>call RunDoLines() 
:imap <F9> <Esc>:<C-U>call RunDoLines() 

" Lines added by the Vim-R-plugin command :RpluginConfig (2014-Jan-27 09:42):
syntax on
War es hilfreich?

Lösung

Did you try Googling for "vim indent stata"? I find this blog post on the first page of results: http://tcry.blogspot.com/2010/04/stata-indenting-in-vim.html . It recommends

set cindent
set shiftwidth=5
set cinoptions=>s,e0,n0,f0,{0,}0,^0,:0,=0,l0,b0,g0,h0,p0,t0,i0,+0,c0,C0,/0, (0,u0,U0,w0,W0,m0,j0,)20,*30,#0
set cinwords=

You could add those lines to your vimrc file. That will set global values of these options, and if nothing else changes the global values, then you should get these values when editing Stata files. Or you could add an indent file with those lines: change all the set commands to setl so that they do not affect the global values. To follow standards, add these lines at the top (from the same blog post):

" Only load this indent file when no other was loaded yet.
if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

In the comments, you ask,

... isn't file type indentation preferred to 'cindent' or 'smartindent'?

"File type indentation" just means :sourceing a file at indent/<filetype>.vim (in this case, indent/stata.vim) under ~/.vim/ (or some other directory specified by 'runtimepath'). That file can set whatever options seem appropriate: 'indentexpr' is the most flexible, but if 'cindent' and related options are good enough, you may as well use them.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top