1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vim × Makefile で C 言語の環境を快適にする

1
Last updated at Posted at 2026-05-24

はじめに

Cを書いていると「保存 → ターミナル切り替え → make → エラー確認 → vim に戻る」という流れが普通だと思っていませんか?
このムダな往復をゼロにするのが vim の :make コマンドMakefile の組み合わせです。


前提

  • vim(NeoVim でも同様)
  • make(GNU make)
  • gcc または clang

Step 1 ― Makefile を用意する

プロジェクトルートに以下の Makefile を置く。

CC      = gcc
CFLAGS  = -Wall -Wextra -g
TARGET  = main
SRCS    = main.c
OBJS    = $(SRCS:.c=.o)

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	rm -f $(OBJS) $(TARGET)

ポイント: -Wall -Wextra で警告を最大化しておくと、コンパイル時に潰せるバグが増える。


Step 2 ― vim から :make を叩く

vim を開いたまま、コマンドモードで

:make

と打つだけ。カレントディレクトリの Makefile が自動で実行される。
エラーがあれば QuickFix リスト に展開され、そのままエラー行に飛べる。

コマンド 意味
Ctrl + w , [jkhl] ウィンドウを切り替える
:make make 実行
:copen QuickFix ウィンドウを開く
:cnext / :cprev 次/前のエラーへジャンプ
:cc 現在のエラー行へ
:cclose QuickFix を閉じる

まとめ

やること 設定
Makefile にビルドルールを書く CC, CFLAGS, SRCS を整理
vim から :make を実行 QuickFix でエラー即ジャンプ
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?