1

特定のケースを除いて、vim のすべてをタブでインデントしたいと思います。たとえば、私はこのc ++コードを持っています(<tab>はタブ文字シリーズで<s>、スペース文字シリーズです):

<tab>if(true &&
<tab><s>true)
<tab>{
<tab><tab>//code here
<tab>}

「&&」を書いた後、「o」を押して次の行にジャンプして書き込みを開始し、前の行から「(」までのタブとスペースの数をvimに入れさせたいと思います。

このコーディング スタイルを vim で定義することは可能ですか?

ありがとう!

4

2 に答える 2

5

あなたが探しているのはの(Nオプションだと思いますcinoptions。試してみてくださいset cinoptions+=(0。ドキュメントによると、これはあなたが求めている配置のように見えます。

詳細については、help コマンドを使用する:help cinoptions-valuesか、オンライン バージョンのcinoptions-values のヘルプを参照してください

タブに関する限り、 で無効expandtabにし:set noexpandtab、それに応じてタブストップ、ソフトタブストップ、およびシフト幅がすべて設定されていることを確認する必要があります。例として、Linux ソース コードは上記のようなスタイルを使用しており、私の vimrc には次のようなものがあります。

setlocal ts=8 sts=8 sw=8 tw=80

" Don't expand tabs to spaces.
setlocal noexpandtab

" Enable automatic C program indenting.
setlocal cindent

" Don't outdent function return types.
setlocal cinoptions+=t0

" No extra indentation for case labels.
setlocal cinoptions+=:0

" No extra indentation for "public", "protected", "private" labels.
setlocal cinoptions+=g0

" Line up function args.
setlocal cinoptions+=(0

" Setup formatoptions:
"   c - auto-wrap comments to textwidth.
"   r - automatically insert comment leader when pressing <Enter>.
"   o - automatically insert comment leader after 'o' or 'O'.
"   q - allow formatting of comments with 'gq'.
"   l - long lines are not broken in insert mode.
"   n - recognize numbered lists.
"   t - autowrap using textwidth,
setlocal formatoptions=croqlnt
于 2013-03-31T12:35:00.283 に答える
0

.vimrc に以下を追加

set tabstop=2
set expandtab
set shiftwidth=2
set smarttab
set linebreak
set smartindent
set cindent
set autoindent

vim で awesomeness を展開するために必要なのはこれだけです。:)

于 2013-03-31T11:50:09.997 に答える