Skip to content

Instantly share code, notes, and snippets.

@Shusei-E
Forked from m-note/.vimrc
Last active November 2, 2016 17:18
Show Gist options
  • Save Shusei-E/db4ed25ce011a5b31993 to your computer and use it in GitHub Desktop.
Save Shusei-E/db4ed25ce011a5b31993 to your computer and use it in GitHub Desktop.
Vimの設定ファイル
" 起動時のウィンドウサイズの変更
set lines=56
set columns=105
" Change working directory (これを使うとパスが変わってtexのquickrunが動かない)
" cd /Users/Shu/Dropbox/
" セッションの保存(終了時にVimのセッション情報を自動で保存)と復元(Control-sで復元)
au Vimleave * mks! ~/.vim_session
nnoremap <C-s> :source ~/.vim_session <cr> :nohl <cr>
" Cmd-1を押して行頭に、Cmd-0を押して行末に
noremap <D-1> 0
noremap <D-0> $
"Chrome的なタブの切り替え
nnoremap <D-A-Left> gT
nnoremap <D-A-Right> gt
" Oのときの動作
set nocompatible
nnoremap O :<C-u>call append(expand('.'), '')<Cr>j
"行番号を表示する
set number
" ヤンクでクリップボードにコピー
set clipboard=unnamed
"タブ幅の設定、Tabではなくスペース2つにする
set tabstop=2
set shiftwidth=2
set noexpandtab
set softtabstop=0
autocmd Filetype tex setlocal expandtab
"新しい行のインデントを現在行と同じにする
set autoindent
autocmd BufNewFile,BufRead *.c set cindent
autocmd BufNewFile,BufRead *.cpp set cindent
"バックアップをとらない
set nobackup
"ビープ音を出さない
set visualbell t_vb=
"括弧ハイライトの調整 cf. http://goo.gl/acS2xh http://goo.gl/4caCgN
autocmd ColorScheme * highlight MatchParen gui=bold,underline guibg=white guifg=orange
"勝手に括弧のハイライトでカーソルを動かさない
set noshowmatch
"括弧の補完
inoremap { {}<Left>
inoremap [ []<Left>
inoremap ( ()<Left>
inoremap " ""<Left>
inoremap {<Enter> {}<Left><CR><ESC><S-o>
inoremap [<Enter> []<Left><CR><ESC><S-o>
inoremap (<Enter> ()<Left><CR><ESC><S-o>
"ビジュアルモードでは勝手にヤンクしないようにする cf. http://goo.gl/7jq1Th
vnoremap d "_d
noremap D "_D
"noremap p "0p
"Undoの情報はセッションを超えて保存しない
:set noundofile
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"NeoBundel用
" Note: Skip initialization for vim-tiny or vim-small.
if 0 | endif
filetype off
if has('vim_starting')
if &compatible
set nocompatible " Be iMproved
endif
set runtimepath+=~/.vim/bundle/neobundle.vim
endif
call neobundle#begin(expand('~/.vim/bundle/'))
" 以下にあるものが追加されるみたい
NeoBundle 'Shougo/neobundle.vim'
NeoBundle 'Shougo/vimproc', {
\ 'build' : {
\ 'windows' : 'make -f make_mingw32.mak',
\ 'cygwin' : 'make -f make_cygwin.mak',
\ 'mac' : 'make -f make_mac.mak',
\ 'unix' : 'make -f make_unix.mak',
\ },
\ }
"NeoBundle 'VimClojure'
"NeoBundle 'Shougo/vimshell'
NeoBundle 'Shougo/unite.vim'
" 詳細な設定は下の方にある
"NeoBundle 'Shougo/neocomplcache'
"NeoBundle 'jpalardy/vim-slime'
"NeoBundle 'scrooloose/syntastic'
NeoBundle 'Shougo/vimfiler.vim'
nnoremap <Leader>v :VimFilerBufferDir -split -simple -winwidth=35 -force-quit<CR>
let g:vimfiler_as_default_explorer = 1
let g:vimfiler_edit_action = 'tabopen'
"詳細な設定は下の方に続く
"NeoBundle 'itchyny/lightline.vim'
"NeoBundle 't9md/vim-textmanip'
"NeoBundle 'ujihisa/unite-colorscheme'
"NeoBundle 'tomasr/molokai'
""NeoBundle 'https://bitbucket.org/kovisoft/slimv'
"以下はLaTexの変換用
" for LaTeX
NeoBundle 'lervag/vimtex'
let g:vimtex_fold_envs = 0
let g:tex_indent_brace=0
" vim-quickrun
let g:quickrun_config = {
\ "_" : {
\ "runner" : "vimproc",
\ "runner/vimproc/updatetime" : 60
\ },
\}
NeoBundle 'thinca/vim-quickrun'
"QuickRunでコンパイル中、<C-c> で実行を強制終了させる
"quickrun.vim が実行していない場合には <C-c> を呼び出す
nnoremap <expr><silent> <C-c> quickrun#is_running() ? quickrun#sweep_sessions() : "\<C-c>"
" disable the conceal function
let g:tex_conceal=''
" AutoSave
NeoBundle 'vim-scripts/vim-auto-save'
nnoremap <Leader>as :AutoSaveSetting<CR>
command! AutoSaveSetting call s:AutoSaveSetting()
function! s:AutoSaveSetting()
if g:auto_save==0
let g:auto_save = 1
let g:auto_save_silent = 1 " do not display the auto-save notification
let g:auto_save_in_insert_mode = 0 " do not save while in insert mode
:echomsg "AutoSave is on"
else
let g:auto_save = 0
:echomsg "AutoSave is off"
endif
endfunction
" Evervim用設定
NeoBundle 'kakkyz81/evervim'
let g:evervim_devtoken= 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
nnoremap <Leader>el :EvervimNotebookList<CR>
nnoremap <Leader>es :EvervimSearchByQuery<Space>
nnoremap <Leader>ec :EvervimCreateNote<CR>
nnoremap <Leader>et :EvervimListTags<CR>
" Geeknote
NeoBundle 'neilagabriel/vim-geeknote'
nnoremap <Leader>gl :Geeknote<cr>
nnoremap <Leader>gs :GeeknoteSearch<Space>
nnoremap <Leader>gc :GeeknoteCreateNote<Space>
let g:GeeknoteMaxExplorerWidth=60
let g:GeeknoteFormat="markdown"
" color scheme / colorscheme NAMEコマンドで変更可能
NeoBundle 'ujihisa/unite-colorscheme'
" bawolf
NeoBundle 'sjl/badwolf'
" solarized
NeoBundle 'altercation/vim-colors-solarized'
" molokai
NeoBundle 'tomasr/molokai'
call neobundle#end() "NeoBundle関連が全て終わった場所に置いている
filetype plugin indent on " required!
filetype indent on
syntax on
NeoBundleCheck
"""""""""""""""""""""""""""""""""""""""""
"プログラムのコンパイル
"F5でCのコンパイル cf. http://goo.gl/MBWvoM
"実行コマンド
command! Run1 call s:Run1()
nmap <F5> :Run1<CR>
function! s:Run1()
let e = expand("%:e")
if e == "c"
:Gcc1
endif
if e == "py"
:Python31
endif
if e == "cpp"
:CPP1
endif
if e == "tex"
:lcd %:p:h
:QuickRun
endif
endfunction
command! Gcc1 call s:Gcc1()
function! s:Gcc1()
if has("win32") || has("win64")
:!gcc % -o %:r.exe
:!%:r.exe
else
:!sudo gcc % -o %:r.out
":!%:p:h/%:r.out
:!./%:r.out
endif
endfunction
command! Python31 call s:Python1()
function! s:Python1()
:!python3 %
endfunction
command! CPP1 call s:CPP1()
function! s:CPP1()
:cd %:p:h
:!sudo clang++ -std=c++11 -stdlib=libc++ % -o %:r.out
":!%:p:h/%:r.out
:!./%:r.out
endfunction
"QuickRunで実行
command! Run call s:Run()
nmap <F6> :Run<CR>
function! s:Run()
let e = expand("%:e")
if e == "c"
:Gcc
endif
if e == "py"
:Python3
endif
if e == "cpp"
:CPP
endif
endfunction
command! Gcc call s:Gcc()
function! s:Gcc()
if has("win32") || has("win64")
:!gcc % -o %:r.exe
:!%:r.exe
else
:QuickRun c -hook/time/enable 1
endif
endfunction
command! Python3 call s:Python()
function! s:Python()
:QuickRun python3
endfunction
command! CPP call s:CPP()
function! s:CPP()
:QuickRun cpp
endfunction
"""""""""""""""""""""""""""""""""""""""""
"Spell Checkのときに日本語を除外
set spelllang=en,cjk
"""""""""""""""""""""""""""""""""""""""""
"Ctr+kでコメントアウト
NeoBundle 'tomtom/tcomment_vim'
" F3でwordcount (Latexなら純粋に単語数だけ)
map <F3> :w !detex \| wc -w<CR>
"テキストでは勝手に改行しない
autocmd FileType text setlocal textwidth=0
"autocmd FileType txt set formatoptions=q
" R関係 tmuxをhomebrewしておく必要がありそう
" http://www.vim.org/scripts/script.php?script_id=2628 のファイルを開いて :so % でOK
filetype plugin indent on
if has("gui_running")
inoremap <C-Space> <C-x><C-o>
else
inoremap <Nul> <C-x><C-o>
endif
vmap <C-r> <Plug>RDSendSelection
nmap <C-r> <Plug>RDSendLine
nmap <C-q> :let rstatus = RRunEnd(rstatus)<CR>
let rstatus ="Roff"
function RRunEnd(rstatus)
if a:rstatus == "Roff"
echo "Open R"
execute "normal \<Plug>RStart"
return "Ron"
else
echo "Close R"
execute "normal \<Plug>RClose"
return "Roff"
endif
endfunction
" 今開いているファイルをMarked 2で表示
nnoremap <Leader>m :Marked2Run<CR>
command! Marked2Run call s:Marked2Run()
function! s:Marked2Run()
let e = expand("%:e")
if e == "md"
:!open -a /Applications/Marked\ 2.app %
echo "Open Marked 2"
else
echo "File is not Markdown"
endif
endfunction
" 今開いているtexのPDFををSkimで表示
nnoremap <Leader>s :SkimRun<CR>
command! SkimRun call s:SkimRun()
function! s:SkimRun()
let e = expand("%:e")
if e == "tex"
:!open -a /Applications/Skim.app %:r.pdf
echo "Open in Skim"
else
echo "File is not tex"
endif
endfunction
" Pandoc
nnoremap <Leader>p :PandocRun<CR>
command! PandocRun call s:PandocRun()
function! s:PandocRun()
let e = expand("%:e")
if e == "md"
":!pandoc %:r.md -f markdown -t latex -s -o %:r.tex
:!pandoc %:r.md -o %:r.tex --template="~/.vim/pandoc_latex_template.tex"
echo "Converted to tex file"
else
echo "File is not MarkDown"
endif
endfunction
"uniteを開いている間のキーマッピング
augroup vimrc
autocmd FileType unite call s:unite_my_settings()
augroup END
function! s:unite_my_settings()
"ESCでuniteを終了
nmap <buffer> <ESC><ESC> <Plug>(unite_exit)
"入力モードのときjjでノーマルモードに移動
imap <buffer> jj <Plug>(unite_insert_leave)
"入力モードのときctrl+wでバックスラッシュも削除
imap <buffer> <C-w> <Plug>(unite_delete_backward_path)
"<C-s>でsplit
nnoremap <silent><buffer><expr> <C-s> unite#smart_map('<C-s>', unite#do_action('split'))
inoremap <silent><buffer><expr> <C-s> unite#smart_map('<C-s>', unite#do_action('split'))
"<C-v>でvsplit
nnoremap <silent><buffer><expr> <C-v> unite#smart_map('<C-v>', unite#do_action('vsplit'))
inoremap <silent><buffer><expr> <C-v>f unite#smart_map('<C-v>', unite#do_action('vsplit'))
"vでvimfiler
nnoremap <silent><buffer><expr> v unite#smart_map('v', unite#do_action('vimfiler'))
inoremap <silent><buffer><expr> v unite#smart_map('v', unite#do_action('vimfiler'))
endfunction
" Vimfilerのキーマッピング
augroup vimfiler
autocmd!
autocmd FileType vimfiler call s:vimfiler_settings()
augroup END
function! s:vimfiler_settings()
" tree での制御は,<Space>
map <silent><buffer> <Space> <NOP>
nmap <silent><buffer> <Space> <Plug>(vimfiler_expand_tree)
nmap <silent><buffer> <S-Space> <Plug>(vimfiler_expand_tree_recursive)
" マークは,<C-Space>(control-space)
nmap <silent><buffer> <C-Space> <Plug>(vimfiler_toggle_mark_current_line)
vmap <silent><buffer> <C-Space> <Plug>(vimfiler_toggle_mark_selected_lines)
" ウィンドウを分割して開く
nnoremap <silent><buffer><expr> <C-h> vimfiler#do_switch_action('split')
nnoremap <silent><buffer><expr> <C-v> vimfiler#do_switch_action('vsplit')
" 移動,<Tab> だけでなく <C-l> も
nmap <buffer> <C-l> <plug>(vimfiler_switch_to_other_window)
" 閉じる,<Esc> 2 回叩き
nmap <buffer> <Esc><Esc> <Plug>(vimfiler_exit)
endfunction
\documentclass[a4paper,10.5pt]{jsarticle} %jsarticleでも良いかも
%--脚注の設定
\usepackage{natbib}
\bibpunct[, ]{(}{)}{;}{and}{}{,} %本文での引用の体裁はここで整えられるみたい
\bibliographystyle{apsr2006} %このagsmは編集済みなので注意。ジャーナルが太字にならないようにしてる。ブログ参照。
\usepackage{amsmath}
%--余白の設定 http://pcwide-jp.blogspot.co.uk/2009/07/latex.html より
\setlength{\topmargin}{15mm}
\addtolength{\topmargin}{-1in}
\setlength{\oddsidemargin}{17mm}
\addtolength{\oddsidemargin}{-1in}
\setlength{\evensidemargin}{15mm}
\addtolength{\evensidemargin}{-1in}
\setlength{\textwidth}{170mm}
\setlength{\textheight}{254mm}
\setlength{\headsep}{0mm}
\setlength{\headheight}{0mm}
\setlength{\topskip}{0mm}
%--図の設定
\usepackage[dvipdfmx]{graphicx} % PDFの利用もOKに
%\usepackage[dvips]{graphicx}
%--行間の設定
\usepackage{setspace}
\setstretch{1.13} % ページ全体の行間を設定
%コードの設定
\usepackage{listings}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backgroundcolour}{rgb}{0.95,0.95,0.92}
\lstset{ %
language= Python, %ここを含めなければ、変に太字になったりしない
aboveskip=2.5mm,
belowskip=4.5mm,
showstringspaces=false,
columns=flexible,
keepspaces=true,
numbers=left,
numbersep=5pt,
basicstyle={\small\ttfamily},
commentstyle={\small\ttfamily},
breaklines=true,
breakatwhitespace=true
tabsize=3
backgroundcolor=\color{backgroundcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
xleftmargin = 1.1cm,
framexleftmargin = 1em
}
\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{green!8}
%リンクの埋め込みを可能にする \href{ **URL** }{表示テキスト}
\usepackage[dvipdfmx]{hyperref}
\usepackage{courier}
\usepackage{here}
%日本語環境用の設定を追加
\renewcommand{\refname}{参考文献}
\renewcommand{\abstractname}{要約}
\usepackage{multirow}
\usepackage{placeins}
%数学用のフォント
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
%Pandoc用
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
%Too deeply nested対策
\usepackage{enumitem}
\setlistdepth{20}
\renewlist{itemize}{itemize}{20}
\setlist[itemize]{label=\textbullet}
\setlist[itemize,2]{label=\(\circ\)}
\setlist[itemize,3]{label=\(\diamond\)}
\setlist[itemize,4]{label=\(\triangledown\)}
\setlist[itemize,5]{label=\(\triangleright\)}
\setlist[itemize,6]{label=\(\vartriangle\)}
\setlist[itemize,8]{label=\(\circ\)}
\setlist[itemize,9]{label=\(\diamond\)}
\setlist[itemize,10]{label=\(\triangledown\)}
\setlist[itemize,11]{label=\(\triangleright\)}
\setlist[itemize,12]{label=\(\vartriangle\)}
\setlist[itemize,14]{label=\(\circ\)}
\setlist[itemize,15]{label=\(\diamond\)}
\setlist[itemize,16]{label=\(\triangledown\)}
\setlist[itemize,17]{label=\(\triangleright\)}
\setlist[itemize,18]{label=\(\vartriangle\)}
\setlist[itemize,20]{label=\(\circ\)}
%-----------------
$if(title)$
\title{$title$$if(thanks)$\thanks{$thanks$}$endif$}
$endif$
$if(subtitle)$
\providecommand{\subtitle}[1]{}
\subtitle{$subtitle$}
$endif$
$if(author)$
\author{$for(author)$$author$$sep$ \and $endfor$}
$endif$
$if(institute)$
\institute{$for(institute)$$institute$$sep$ \and $endfor$}
$endif$
\begin{document}
\title{}
\author{}
\date{$date$}
\maketitle
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
{
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$black$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$
$if(lot)$
\listoftables
$endif$
$if(lof)$
\listoffigures
$endif$
$body$
$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
$for(include-after)$
$include-after$
$endfor$
\end{document}
" ~/.vim/ftplugin/tex_quickrun.vim に保存。なければフォルダを自分で作る。 / Texのコンパイルに必要
" 指定した範囲でF5をすると、tmptex.pdfというファイルができ、そこにプレビューされる。
" どこも指定せずにF5をすると、そのファイル全体がコンパイルされる。
"http://qiita.com/ssh0/items/4aea2d3849667717b36dを参考にした。自分の保存用。
" Change to current directory
:cd %:p:h
" LaTeX Quickrun
let g:quickrun_config['tex'] = {
\ 'command' : 'latexmk',
\ 'outputter' : 'error',
\ 'outputter/error/success' : 'null',
\ 'outputter/error/error' : 'quickfix',
\ 'srcfile' : expand("%"),
\ 'cmdopt': '-pdfdvi',
\ 'hook/sweep/files' : [
\ '%S:p:r.aux',
\ '%S:p:r.bbl',
\ '%S:p:r.blg',
\ '%S:p:r.dvi',
\ '%S:p:r.fdb_latexmk',
\ '%S:p:r.fls',
\ '%S:p:r.log',
\ '%S:p:r.out'
\ ],
\ 'exec': '%c %o %a %s',
\}
" 部分的に選択してコンパイル
" http://auewe.hatenablog.com/entry/2013/12/25/033416 を参考に
let g:quickrun_config.tmptex = {
\ 'exec': [
\ 'mv %s %a/tmptex.latex',
\ 'latexmk -pdfdvi -pv -output-directory=%a %a/tmptex.latex',
\ ],
\ 'args' : expand("%:p:h:gs?\\\\?/?"),
\ 'outputter' : 'error',
\ 'outputter/error/error' : 'quickfix',
\
\ 'hook/eval/enable' : 1,
\ 'hook/eval/cd' : "%s:r",
\
\ 'hook/eval/template' : '\documentclass{jsarticle}'
\ .'\usepackage[dvipdfmx]{graphicx, hyperref}'
\ .'\usepackage{float}'
\ .'\usepackage{amsmath,amssymb,amsthm,ascmac,mathrsfs}'
\ .'\allowdisplaybreaks[1]'
\ .'\theoremstyle{definition}'
\ .'\newtheorem{theorem}{定理}'
\ .'\newtheorem*{theorem*}{定理}'
\ .'\newtheorem{definition}[theorem]{定義}'
\ .'\newtheorem*{definition*}{定義}'
\ .'\renewcommand\vector[1]{\mbox{\boldmath{\$#1\$}}}'
\ .'\begin{document}'
\ .'%s'
\ .'\end{document}',
\
\ 'hook/sweep/files' : [
\ '%a/tmptex.latex',
\ '%a/tmptex.out',
\ '%a/tmptex.fdb_latexmk',
\ '%a/tmptex.log',
\ '%a/tmptex.aux',
\ '%a/tmptex.dvi'
\ ],
\}
"vnoremap <silent><buffer> <F4> :QuickRun -mode v -type tmptex<CR>
vnoremap <silent><buffer> <F5> :QuickRun -mode v -type tmptex<CR>
" QuickRun and view compile result quickly (but don't preview pdf file)
"nnoremap <silent><F4> :QuickRun<CR>
nnoremap <silent><F5> :QuickRun<CR>
" 自動で生成したい場合
"autocmd BufWritePost,FileWritePost *.tex QuickRun tex
@Shusei-E
Copy link
Author

2016/03/20
ターミナルで動かした時に、call neobundle#end()の位置がおかしいと表示されたので、NeoBundle関連が全て終わった場所に変更した

@Shusei-E
Copy link
Author

Texの編集中に、インデントがおかしくなる問題について:
~/.vim/indent/tex.vimというファイルを作って、let b:did_indent = 1と記述

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment