SlideShare a Scribd company logo
1 of 31
Vim勉強会(第1回) 
Vim初心者のための基本講座
自己紹介 
• 藤田慎二郎 
• 広島大学分散システム学研究室所属(2014年現在) 
• Vim歴2年(まだまだ未熟です) 
• 神崎師匠の弟子 
2
Vim勉強会(第1回)の主旨 
• キーボードのホームポジションから離れること 
なくテキスト編集する方法を習得 
- マウス操作の排除 
- 矢印キーの排除 
• 基本的でかつ実用的な操作に絞って紹介 
3
1. Vimの基礎知識 
本旨へ入る前に 
4
Vimの基本操作 
• カーソル移動 
- h(←) 
- j(↓) 
- k(↑) 
- l(→) 
• 1文字削除(x) 
• Undo(u) 
• Redo(Ctrl + r) 
5
Vimのモード 
6 
挿入モード 
ノーマルモード 
v, V, Ctrl+v :, /, ?, ! 
ヴィジュアル 
モード 
コマンドモード 
a, i, s, c 
etc… 
Esc, Ctrl+[ 
Esc, Ctrl+[
Vimのモード 
• ノーマルモード 
- カーソル移動、文字の削除 
• 挿入モード 
- 文章の書き込み 
• ヴィジュアルモード 
- 文字の選択(マウスのドラッグと同じ) 
• コマンドモード 
- 保存、検索、置換など 
7
Vimのモード 
• ノーマルモード 
- カーソル移動、文字の削除 
• 挿入モード 
- 文章の書き込み 
• ヴィジュアルモード 
- 文字の選択(マウスのドラッグと同じ) 
• コマンドモード 
- 保存、検索、置換など 
8 
今後掲載する操作は全て 
ノーマルモードが起点
ヴィジュアルモード 
• v(文字単位で選択) 
• V(行単位で選択) 
• Ctrl+v(矩形選択) 
9 
よく使うので要記憶
2. カーソルの移動 
長い文章でも一瞬で行きたい場所へ 
10
カーソルの移動(細かい移動) 
• 単語単位での移動 
- w(単語単位で後ろに移動) 
- b(単語単位で前に移動) 
• 指定した文字まで移動 
- f <character>(同じ行内で前方検索して移動) 
;(セミコロン)と,(カンマ)で前後に移動 
- F <character>(同じ行内で後方検索して移動) 
;(セミコロン)と,(カンマ)で(略) 
11
カーソルの移動(大きい移動) 
• gg(ファイルの頭に移動) 
• G(ファイルの末尾に移動) 
• <number>G(指定行へ移動) 
• Ctrl+f, Ctrl+b(1ページ単位で移動) 
• Ctrl+d, Ctrl+u(半ページ単位で移動) 
12
カーソルの移動(大きい移動) 
• *(カーソル下の単語間を移動) 
- ”n”で前方検索、”N”で後方検索 
• /<some words>(指定した文字を前方検索) 
- “n”もしくは”N”でさらに前後の文字を検索 
- 正規表現を使用可能 
13
3. 文字の消去とコピー 
消去は一瞬で、コピーはマウスなしで 
14
文字や文章の消去 
• dd(1行まるごと削除) 
• D(カーソル位置より後を削除) 
• viewで選択して”d”(選択範囲を削除) 
- 選択の際に「カーソルの移動」でやった操作を活用 
• dt<character>(指定した文字までを削除) 
- “d”を”c”にすれば削除した後「挿入モード」へ移行 
15
Text Objectを使った消去(重要) 
• テキストオブジェクトとは 
- あるルールに基いたテキストのまとまり 
- 「”」で囲まれた文章 
- 「htmlタグ」で囲まれた文章など… 
16 
String str = “Hello World!”; 
<b>Hello World!</b>
Text Objectを使った消去(重要) 
• dw, cw(単語単位で削除) 
• di”, ci”(”で囲まれた文字を削除) 
- 「”」の他に「(」「<」「[」も指定可能 
• da”, ca”(”で囲まれた文字を”を含めて削除) 
- 「”」の他に(略) 
17
Text Objectを使った消去(重要) 
• dw, cw(単語単位で削除) 
• di”, ci”(”で囲まれた文字を削除) 
- 「”」の他に「(」「<」「[」も指定可能 
• da”, ca”(”で囲まれた文字を”を含めて削除) 
- 「”」の他に(略) 
18 
超便利なので 
これだけでも憶えよう
文字のコピー 
• Vimでのコピーは”Copy”ではなく”Yank” 
• yy, Y(カーソルのある行をコピー) 
• Viewで選択してy(選択した範囲をコピー) 
• yi”, ya” etc…(Text Objectを使ったコピー) 
- 動作は「消去」のときと同じ 
- ywなども使用可 
• 貼り付けはp(”Paste”) 
19
文字のコピー(切り取り) 
• Vimでは「切り取り=消去」 
• つまり「文字の消去」が「切り取り」に相当 
• 消去した後にp(Paste)すれば貼り付け可能 
• そのため「切り取り」の操作は「文字の消去」 
を参照 
20
4. ファイルを開く 
ファイル間の行き来も全てVimで 
21
新規ファイルを開く 
• 主にコマンドモードでの操作 
• :n <file name>(指定したファイル名で開く) 
- すでにファイルがある場合はそれを開く 
- 頭に「:(コロン)」があるので注意 
• :bp, :bn(開いたファイル間を行き来する) 
- :bpは前のファイル(previous) 
- :bnは後のファイル(next) 
22
新規ファイルを開く 
• :ls(開いたファイルの一覧を表示) 
• :b<number>(指定した番号のファイルを開く) 
- 番号は:lsで確認 
• Ctrl+ws(画面を水平分割) 
- 画面内に2つのファイルを表示して編集 
• Ctrl+wv(画面を垂直分割) 
- 画面内に(略) 
23
5. その他小技集 
必須ではないが知ってるとやばい小技集 
24
その他小技集 
• Ctrl+n(文字入力中に使用すると自動で補完) 
- 長い変数名でも一発で入力可能 
• 矩形選択(Ctrl+v)して「I//<Esc>」 
or 
:<number>, <number> norm I// 
- 指定した範囲の行頭に「//」を挿入 
• gg=G(全行に対してコードを整形) 
- 自動でインデントを入れてくれる 
25
その他小技集 
• .(「ドット」、前の編集操作を繰り返す) 
• q<character>(Vimのマクロ機能を呼び出し) 
- <character>にマクロを記録開始 
↓ 
• @<character> 
- <character>に登録したマクロを呼び出し 
26
その他小技集 
• :s/<置換したい文字列>/<置換する文字列>/g 
- 同じ行の中で文字列を置換 
• :%s/<置換したい文字列>/<置換する文字列>/g 
- ファイル全体で文字列を置換 
• 最後の「g」を「c」にすると1つずつ確認しな 
がら置換可能 
• <置換したい文字列>には正規表現を使用可 
27
6. どこでもVimを 
IDEでもブラウザでもVimを使おう 
28
どこでもVimを 
• Vimは様々な環境で使えるようプラグインが 
多数存在 
• Eclipse(Vrapper) 
- 矩形選択などVimの機能をフル活用するには 
少し設定をいじる必要有り 
• Visual Studio(VsVim) 
- 矩形選択など(略) 
• Google Chrome(wasavi) 
29
最後に 
• 今回紹介した操作はとにかくVimを使うことに 
よってのみ習得可能 
• 習得するとテキスト編集が超効率的に 
30
最後に 
• 今回紹介した操作はとにかくVimを使うことに 
よってのみ習得可能 
• 習得するとテキスト編集が超効率的に 
31 
どんどんVimを使おう!

More Related Content

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Vim勉強会