SlideShare a Scribd company logo
Coding with VIM
20180115, Enzo.Wang
Outlines
● overview
● beginner saver
● mark
● highlight
● directory viewer
● search and replace
● diff
● cscope and ctags
● extra edit skills
● autocomplete
● syntax check
● remap keystroke
● colorscheme
● set up vim in new linux environment
● work with linux shell
● plugins
VIM is an IDE, almost 100%.
Overview
● vim is not vi (fix it by alias vi=’vim’)
● Code on compiler server not on PC, without source code network sync issue
● Without mouse, you still can code
● General editor for different languages such as c, js, python, lua, etc
● Customize hotkey in ~/.vimrc
● Plugins provide more features
● Steep learning curve (but it will pay off)
● 4 common modes
○ normal mode
○ insert mode
○ visual mode
○ ex mode
● Window, buffer, and tab
window 1 window 2
2 tabs
3 buffers
Beginner Saver
● :qa (quit all)
● :q! (no save then quit)
● :w (save file)
● :x (save and quit)
● :123 (go to line 123)
● :help <keyword>
● :vs, :sp (open window)
● :e <file_to_open> (open
file)
● :%s/abc/def/gc (replace
abc by def)
● :set nu (show line
number)
● :tabe (new tab)
● 2dd (delete 2 lines)
● 2yy (copy 2 lines)
● v (select)
● y (yank, aka copy)
● p (paste)
● u, Ctrl-R (undo, redo)
● h, j, k, l (move cursor)
● 0, $ (go to first and last char of
line)
● gg, G (go top, end)
● {{, }}, [[, ]] (go block)
● Ctrl-U, Ctrl-D (page up, down)
● Ctrl-Y, Ctrl-E (scroll up, down)
● Ctrl-O, Ctrl-I (jump older, newer)
ex mode normal mode insert mode
A, a, O, o, I, i
ESC
ESC
:
● w, b, e (move by word)
● . (repeat last command)
● zz (align to half window)
● /, ? (search pattern)
● n, N (find next, previous)
● *, # (find same word)
● vi(, va( (yank string between “(“
“)”)
● ciw (change whole word)
● ~ (switch case)
● J (join next line)
● = (auto indent)
● <Ctrl-W>w (window traverse)
visual mode
v, VESC
Mark
● help jump to interested location
● set mark by m{a-z}{A-Z},
{A-Z} take effects even file is closed
● jump to mark by ‘{a-z}{A-Z}
● install vim-signature plugin
to show marks
● :marks
Highlight
● install Mark plugin (http://www.vim.org/scripts/script.php?script_id=2666)
● View words in different color, help to trace code and debug
Directory Viewer
● Install NERDTree plugin (https://github.com/scrooloose/nerdtree)
● search: /_WORD_ , /_WORD_c
Search and Replace
Search and Replace
● replace: :%s/_WORD_/_REPLACE_/g
:%s/CONFIG/config/g
● svn diff
○ update diff-cmd setting in ~/.subversion/config
■ diff-cmd = /home/enzo.wang/svndiff_wrap.sh
○ linux:~ $ cat ~/svndiff_wrap.sh
#!/bin/sh
DIFF=”/usr/bin/vimdiff”
LEFT=${6}
RIGHT=${7}
$DIFF $LEFT $RIGHT
linux:~ /busybox $ svn diff busybox.config
Diff
Diff
● :vertical diffsplit your/file/is/this.c
:vertical diffsplit ~/busybox.config.bak
○ build tag script
linux:~ $ cat ~/buildtags.sh
rm tags
rm cscope.*
find src1/ -name “*.h” -o -name “*.c” > cscope.files
find src2/ -name “*.h” -o -name “*.c” >> cscope.files
find src3/ -name “*.h” -o -name “*.c” >> cscope.files
cscope -bkq -i cscope.files
ctags -R
○ build tags usage
linux:~ $ cd ~/project
linux:~/project $ cp ~/buildtags.sh .
linux:~/project $ source buildtags.sh
○ set up in ~/.vimrc
if has("cscope")
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
set cscopetag
set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i-
"" Find symbol and calling function
map g<C-]> :cs find c <C-R>=expand("<cword>")<CR><CR>
map g<C-> :cs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-N> :cn<CR>zz
nnoremap <C-P> :cp<CR>zz
use often for code trace
cscope and ctags
cscope and ctags
taglist plugin tagbar plugin
● view and edit binary file
○ :%!xxd
○ :%!xxd -r
Extra Edit Skills
Extra Edit Skills
● <Ctrl-V> to block edit
<Ctrl-V>, G, I, //, <ESC>
Extra Edit Skills
● :help record, record and replay
qa, i, printf(“, <ESC>, A, “);, <ESC>, j, 0, q
@a
5@@
HOW?
● :sort
● useful to diff two unsorted
texts :sort
Extra Edit Skills
:sort
Extra Edit Skills
● highlight column 80
○ set up in ~/.vimrc with “autocmd BufNewFile, BufRead *.[ch] setl cc=80”
Autocomplete
● goolgle “autocomplete vim”, choose one you like
● I use Supertab plugin (https://github.com/ervandew/supertab)
Syntax Check
● google “vim syntax check <language>"
● Lua exmaple with vim-lua-ftplugin (https://github.com/xolox/vim-lua-ftplugin)
Remap Keystroke
● Remap <ESC>
○ :inoremap jk <ESC>
● Disable arrow key
○ :noremap <UP> <NOP>
○ :noremap <DOWN> <NOP>
○ :inoremap <UP> <NOP>
○ :inoremap <DOWN> <NOP>
○ :inoremap <RIGHT> <NOP>
○ :inoremap <LEFT> <NOP>
smaller working zone, faster
● align search result to center
○ :nnoremap N Nzz
○ :nnoremap n nzz
● copy and paste
○ :map <C-C> “ty
○ :map <C-C><C-C> “tp
● scroll up and down intuitively
○ :nnoremap <C-J> <C-E>
○ :nnoremap <C-K> <C-Y>
● adjust window size intuitively
○ :nnoremap + <C-W>+
○ :nnoremap - <C-W>-
○ :nnoremap <LEFT> <C-W><
○ :nnoremap <RIGHT> <C-W>>
Remap Keystroke
Colorscheme
Set up Vim in New Linux Environment
jack.lin@192.168.1.1:~$
scp -r enzo.wang@192.168.1.2:~/.vim ~/.vim
jack.lin@192.168.1.1:~$
scp enzo.wang@192.168.1.2:~/.vimrc ~/.vimrc
Now enzo.wang can help jack.lin debug with vim
just on compiler server.
Work with Linux Shell
● write shell result
○ :r !<command>
○ :r !pwd
○ :r !date
● write file content
○ :r <file>
● Ctrl-z then fg
● copy text between different sessions
(especially useful in tmux)
○ :nnoremap <C-L> :w! ~/.vimbuff<CR>
○ :nnoremap <C-L><L> :r ~/.vimbuff<CR>
○ :vnoremap <C-L> :w! ~/.vimbuff<CR>
○ :vnoremap <C-L><C-L> :r ~/.vimbuff<CR>
Plugins
● https://vimawesome.com/ - find your next vim plugin
● Suggest to have
○ pathogen - plugin manager
○ powerline - status line
○ NERDTree - directory viewer
○ mark - word highlight
○ vim-signature - display mark
○ ctrl-p - find files easily
○ taglist, tagbar - tags viewer
○ supertab - autocomplete
References
● Vim Keyboard Shortcuts Cheatsheet
● Learn Vim Progressively
● A vim Tutorial and Primer
● Learn to speak vim — verbs, nouns, and modifiers!
● Intro to Vim's Grammar
● Vim Text Objects: The Definitive Guide
● https://vimawesome.com/
● https://github.com/wecanspeak/vim-note
Q && A || Share

More Related Content

What's hot

Tugas Program C++
Tugas Program C++Tugas Program C++
Tugas Program C++
Reynes E. Tekay
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
ilsamaryum
 
Sol10
Sol10Sol10
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
Vikas Sharma
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
Parthipan Parthi
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwift
shark-sea
 
Class array
Class arrayClass array
Class arraynky92
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th Study
Chris Ohk
 
Angular Refactoring in Real World
Angular Refactoring in Real WorldAngular Refactoring in Real World
Angular Refactoring in Real World
bitbank, Inc. Tokyo, Japan
 
Bubble Sort
Bubble SortBubble Sort
Ooprc3c
Ooprc3cOoprc3c
Ooprc3c
Ankit Dubey
 

What's hot (17)

Tugas Program C++
Tugas Program C++Tugas Program C++
Tugas Program C++
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
Sol10
Sol10Sol10
Sol10
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Vcs23
Vcs23Vcs23
Vcs23
 
Include
IncludeInclude
Include
 
cosc 281 hw2
cosc 281 hw2cosc 281 hw2
cosc 281 hw2
 
Chat code
Chat codeChat code
Chat code
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
Elf文件解析
Elf文件解析Elf文件解析
Elf文件解析
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwift
 
Class array
Class arrayClass array
Class array
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th Study
 
Angular Refactoring in Real World
Angular Refactoring in Real WorldAngular Refactoring in Real World
Angular Refactoring in Real World
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 
Code
CodeCode
Code
 
Ooprc3c
Ooprc3cOoprc3c
Ooprc3c
 

Similar to Coding with Vim

GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
Wen Liao
 
Kick my mouse away
Kick my mouse awayKick my mouse away
Kick my mouse away
Xatierlike Lee
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)Lin Yo-An
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginners
Marcin Rogacki
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
Bob Tiernay
 
Unix shell talk - RIT SSE
Unix shell talk - RIT SSEUnix shell talk - RIT SSE
Unix shell talk - RIT SSE
Matt Mokary
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
Kim Phillips
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
Paul Lam
 
Php engine
Php enginePhp engine
Php engine
julien pauli
 
Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3
Jano Suchal
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos WengerAmos Wenger
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
DataStax Academy
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
Edward Capriolo
 
Designate Install and Operate Workshop
Designate Install and Operate WorkshopDesignate Install and Operate Workshop
Designate Install and Operate Workshop
Graham Hayes
 
Graphics in C++
Graphics in C++Graphics in C++
Graphics in C++
Ahsan Mughal
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
jeresig
 
Getting by with just psql
Getting by with just psqlGetting by with just psql
Getting by with just psql
Corey Huinker
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
SignalFx
 

Similar to Coding with Vim (20)

GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
 
Kick my mouse away
Kick my mouse awayKick my mouse away
Kick my mouse away
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)
 
Dev day linux redu
Dev day linux reduDev day linux redu
Dev day linux redu
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginners
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
 
Unix shell talk - RIT SSE
Unix shell talk - RIT SSEUnix shell talk - RIT SSE
Unix shell talk - RIT SSE
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
 
Php engine
Php enginePhp engine
Php engine
 
Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wenger
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
Designate Install and Operate Workshop
Designate Install and Operate WorkshopDesignate Install and Operate Workshop
Designate Install and Operate Workshop
 
Graphics in C++
Graphics in C++Graphics in C++
Graphics in C++
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
 
Getting by with just psql
Getting by with just psqlGetting by with just psql
Getting by with just psql
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
 

Recently uploaded

Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 

Recently uploaded (20)

Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 

Coding with Vim

  • 2. Outlines ● overview ● beginner saver ● mark ● highlight ● directory viewer ● search and replace ● diff ● cscope and ctags ● extra edit skills ● autocomplete ● syntax check ● remap keystroke ● colorscheme ● set up vim in new linux environment ● work with linux shell ● plugins VIM is an IDE, almost 100%.
  • 3. Overview ● vim is not vi (fix it by alias vi=’vim’) ● Code on compiler server not on PC, without source code network sync issue ● Without mouse, you still can code ● General editor for different languages such as c, js, python, lua, etc ● Customize hotkey in ~/.vimrc ● Plugins provide more features ● Steep learning curve (but it will pay off) ● 4 common modes ○ normal mode ○ insert mode ○ visual mode ○ ex mode
  • 4. ● Window, buffer, and tab window 1 window 2 2 tabs 3 buffers
  • 5. Beginner Saver ● :qa (quit all) ● :q! (no save then quit) ● :w (save file) ● :x (save and quit) ● :123 (go to line 123) ● :help <keyword> ● :vs, :sp (open window) ● :e <file_to_open> (open file) ● :%s/abc/def/gc (replace abc by def) ● :set nu (show line number) ● :tabe (new tab) ● 2dd (delete 2 lines) ● 2yy (copy 2 lines) ● v (select) ● y (yank, aka copy) ● p (paste) ● u, Ctrl-R (undo, redo) ● h, j, k, l (move cursor) ● 0, $ (go to first and last char of line) ● gg, G (go top, end) ● {{, }}, [[, ]] (go block) ● Ctrl-U, Ctrl-D (page up, down) ● Ctrl-Y, Ctrl-E (scroll up, down) ● Ctrl-O, Ctrl-I (jump older, newer) ex mode normal mode insert mode A, a, O, o, I, i ESC ESC : ● w, b, e (move by word) ● . (repeat last command) ● zz (align to half window) ● /, ? (search pattern) ● n, N (find next, previous) ● *, # (find same word) ● vi(, va( (yank string between “(“ “)”) ● ciw (change whole word) ● ~ (switch case) ● J (join next line) ● = (auto indent) ● <Ctrl-W>w (window traverse) visual mode v, VESC
  • 6.
  • 7.
  • 8. Mark ● help jump to interested location ● set mark by m{a-z}{A-Z}, {A-Z} take effects even file is closed ● jump to mark by ‘{a-z}{A-Z} ● install vim-signature plugin to show marks ● :marks
  • 9. Highlight ● install Mark plugin (http://www.vim.org/scripts/script.php?script_id=2666) ● View words in different color, help to trace code and debug
  • 10. Directory Viewer ● Install NERDTree plugin (https://github.com/scrooloose/nerdtree)
  • 11. ● search: /_WORD_ , /_WORD_c Search and Replace
  • 12. Search and Replace ● replace: :%s/_WORD_/_REPLACE_/g :%s/CONFIG/config/g
  • 13. ● svn diff ○ update diff-cmd setting in ~/.subversion/config ■ diff-cmd = /home/enzo.wang/svndiff_wrap.sh ○ linux:~ $ cat ~/svndiff_wrap.sh #!/bin/sh DIFF=”/usr/bin/vimdiff” LEFT=${6} RIGHT=${7} $DIFF $LEFT $RIGHT linux:~ /busybox $ svn diff busybox.config Diff
  • 14. Diff ● :vertical diffsplit your/file/is/this.c :vertical diffsplit ~/busybox.config.bak
  • 15. ○ build tag script linux:~ $ cat ~/buildtags.sh rm tags rm cscope.* find src1/ -name “*.h” -o -name “*.c” > cscope.files find src2/ -name “*.h” -o -name “*.c” >> cscope.files find src3/ -name “*.h” -o -name “*.c” >> cscope.files cscope -bkq -i cscope.files ctags -R ○ build tags usage linux:~ $ cd ~/project linux:~/project $ cp ~/buildtags.sh . linux:~/project $ source buildtags.sh ○ set up in ~/.vimrc if has("cscope") set csto=0 set cst set nocsverb " add any database in current directory if filereadable("cscope.out") cs add cscope.out " else add database pointed to by environment elseif $CSCOPE_DB != "" cs add $CSCOPE_DB endif set csverb set cscopetag set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i- "" Find symbol and calling function map g<C-]> :cs find c <C-R>=expand("<cword>")<CR><CR> map g<C-> :cs find s <C-R>=expand("<cword>")<CR><CR> nnoremap <C-N> :cn<CR>zz nnoremap <C-P> :cp<CR>zz use often for code trace cscope and ctags
  • 16. cscope and ctags taglist plugin tagbar plugin
  • 17. ● view and edit binary file ○ :%!xxd ○ :%!xxd -r Extra Edit Skills
  • 18. Extra Edit Skills ● <Ctrl-V> to block edit <Ctrl-V>, G, I, //, <ESC>
  • 19. Extra Edit Skills ● :help record, record and replay qa, i, printf(“, <ESC>, A, “);, <ESC>, j, 0, q @a 5@@ HOW?
  • 20. ● :sort ● useful to diff two unsorted texts :sort Extra Edit Skills :sort
  • 21. Extra Edit Skills ● highlight column 80 ○ set up in ~/.vimrc with “autocmd BufNewFile, BufRead *.[ch] setl cc=80”
  • 22. Autocomplete ● goolgle “autocomplete vim”, choose one you like ● I use Supertab plugin (https://github.com/ervandew/supertab)
  • 23. Syntax Check ● google “vim syntax check <language>" ● Lua exmaple with vim-lua-ftplugin (https://github.com/xolox/vim-lua-ftplugin)
  • 24. Remap Keystroke ● Remap <ESC> ○ :inoremap jk <ESC> ● Disable arrow key ○ :noremap <UP> <NOP> ○ :noremap <DOWN> <NOP> ○ :inoremap <UP> <NOP> ○ :inoremap <DOWN> <NOP> ○ :inoremap <RIGHT> <NOP> ○ :inoremap <LEFT> <NOP> smaller working zone, faster
  • 25. ● align search result to center ○ :nnoremap N Nzz ○ :nnoremap n nzz ● copy and paste ○ :map <C-C> “ty ○ :map <C-C><C-C> “tp ● scroll up and down intuitively ○ :nnoremap <C-J> <C-E> ○ :nnoremap <C-K> <C-Y> ● adjust window size intuitively ○ :nnoremap + <C-W>+ ○ :nnoremap - <C-W>- ○ :nnoremap <LEFT> <C-W>< ○ :nnoremap <RIGHT> <C-W>> Remap Keystroke
  • 27. Set up Vim in New Linux Environment jack.lin@192.168.1.1:~$ scp -r enzo.wang@192.168.1.2:~/.vim ~/.vim jack.lin@192.168.1.1:~$ scp enzo.wang@192.168.1.2:~/.vimrc ~/.vimrc Now enzo.wang can help jack.lin debug with vim just on compiler server.
  • 28. Work with Linux Shell ● write shell result ○ :r !<command> ○ :r !pwd ○ :r !date ● write file content ○ :r <file> ● Ctrl-z then fg ● copy text between different sessions (especially useful in tmux) ○ :nnoremap <C-L> :w! ~/.vimbuff<CR> ○ :nnoremap <C-L><L> :r ~/.vimbuff<CR> ○ :vnoremap <C-L> :w! ~/.vimbuff<CR> ○ :vnoremap <C-L><C-L> :r ~/.vimbuff<CR>
  • 29. Plugins ● https://vimawesome.com/ - find your next vim plugin ● Suggest to have ○ pathogen - plugin manager ○ powerline - status line ○ NERDTree - directory viewer ○ mark - word highlight ○ vim-signature - display mark ○ ctrl-p - find files easily ○ taglist, tagbar - tags viewer ○ supertab - autocomplete
  • 30. References ● Vim Keyboard Shortcuts Cheatsheet ● Learn Vim Progressively ● A vim Tutorial and Primer ● Learn to speak vim — verbs, nouns, and modifiers! ● Intro to Vim's Grammar ● Vim Text Objects: The Definitive Guide ● https://vimawesome.com/ ● https://github.com/wecanspeak/vim-note
  • 31. Q && A || Share