######### ####### ####### #######
## ## ## ## # ## #
## ## ## ## ##
###### ## ## #### ####
## ## ## ### ###
## ## ## ## ##
## ## ## # ## # ##
## ####### ####### #######
~ Linux / FOSS Meetup Linz ~
~ Jan 2024 ~
CC BY-SA 4.0 Daniel KNITTL-FRANK
### ### #### # #
## ## ## ## ##
## ## ## #### ####
## ## ## ## ## ## ##
## ## ## ## ### ##
## ## ## ## # ##
### ## ## ##
# #### #### ####
https://en.wikipedia.org/wiki/Vim_(text_editor)
How to start vim? Type vim
How to exit Vim? Type :wq<Enter>
to save and exit,
:q!
to exit without save
(Pro-tip: ZZ
and ZQ
in normal mode)
Vi is like a Ferrari, if you're a beginner, it handles like a
*****
, but once you get the hang of it, it's small, powerful and FAST! --- (Unknown)VIM is like a new model Ferrari, and sounds like one too - "VIIIIIIMMM!" --- (Stephen Riehm, Germany)
https://elias.rhi.hi.is/vim/quotes.html
i
nsert, v
isual, etc.)<Esc>
to exit any mode and return to normal modeVim comes with vimtutor
binary which provides an "interactive" tutorial.
You should try it :]
^
k Hint: The h key is at the left and moves left.
< h l > The l key is at the right and moves right.
j The j key looks like a down arrow.
v
But you can almost always simply use the arrow keys to navigate
Shameless plug: … or you can learn Neo to avoid moving your hand to the arrow keys
To enter insert mode:
i
: i
nserta
: a
ppendo
: starts a new lineDon't panic and <ESC>
u
: u
ndo<C-R>
: r
edo
(g-
/g+
for walking through undo-tree)
<C-V>
: block/column selectionV
: line-based selecto
: jump to start/end of selectiongv
: re-select previous selectionx
: delete character (cross out)dd
: d
elete linecc
: c
hange lines
: s
ubstitute character under cursorJ
: J
oin linesy
: copy (y
ank)d
or x
: cut (d
elete)p
, P
: p
aste after, P
aste beforew
: w
ord forwardb
: word b
ackwarde
: e
nd of word)
, (
: sentence forward, backward}
, {
: paragraph forward, backward%
: matching item, e.g. ()
[]
{}
^
: start of text0
, $
: start and end of line1G
or 1gg
: go to line 1
Compose single keys to build powerful actions:
2.
: repeat last action 2
times
yw
: y
ank to next w
ord
y3w
: y
ank next 3
w
ords
das
: d
elete a
s
entence
ciw
: c
hange i
nner w
ord
gUiw
: U
pper-case i
nner w
ord
v
enters v
isual mode (selecting text)
viw
: i
nner w
ordvis
: i
nner s
entencevib
: i
nner b
lock, e.g. ()
[]
vi"
: i
nside double quotesvap
: a
round p
aragraphva]
: a
round bracketsvat
: a
round t
ag/regex
, ?regex
: search regular expression forward, backward*
, #
: forward search for word under cursor, backward searchn
, N
: next match, previous match
fc
, Fc
: next/previous character 'c' (inclusive)
tc
, Tc
: next/previous character 'c' (exclusive);
, ,
: repeat forward, repeat backward
:%s/pattern/replace/g
: s
ubstitute text file-wide
=
: auto-indent text/source code>
, <
: indent, unindentgq
: format text:center
: center text:left
: left align text:right
: right aliign text<C-N>
: autocomplete next<C-P>
: autocomplete previous<C-X> <C-L>
: autocomplete line<C-X> <C-F>
: autocomplete file path<C-X> <C-N>
: autocomplete with context<C-X> <C-O>
: omni-completionAccess registers with "r
"ry3w
: y
ank next 3
w
ords into register "r
"
"r2p
: p
aste 2
times from register "r
"Registers can be used to store and replay macros
qr
: start recording into register "r"; press q
when finished@r
: execute macro from register "r"@@
: re-run last macro@:
: re-run last "ex" command
E.g. macro to capitalize first word in sentence, then jump to next sentence:
()guw~)
Pro-tip: Macros are simply text in registers, you can yank, edit, and paste them:
"rp
and "ry
Need to filter current line through external command?
:.!cmd
: filter current line through command
(Pro-tip: Type !!
)
(Pro-tip: !!sh
to execute the current line as shell command)
:[range][command]
Useful commands:
:make
: execute Makefile:!cmd
: run external command:%!cmd
: filter and replace content by command:1,10w file
: w
rite first 10 lines to file:r!date
: r
ead current date and time into file:g/pattern/command
: perform g
lobal command:v/pattern/command
: perform inv
erted global command
:g/^$/d
: delete empty lines:g/^#/norm A #
add " #" after each Markdown header line``` set number " show line numbers
set ignorecase smartcase " ignore case if pattern lower case
set incsearch " incremental search set hlsearch " highlight all matches
" show non-printing characters (make sure your terminal supports UTF8!) set list listchars=tab:→ ,nbsp:␣,trail:•,space:⋅ ```
Can be persisted in ~/.vimrc
. If you want to have a look at my settings,
check out https://github.com/knittl/.files/blob/master/.vimrc
~/.vim/plugin/
https://github.com/junegunn/vim-plug
Installing:
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://github.com/junegunn/vim-plug/raw/master/plug.vim
Then add to your ~/.vimrc
:
call plug#begin()
Plug 'git repository url'
call plug#end()
mattn/emmet-vim
: HTML and CSS editing on steroidstpope/vim-surround
: Clever way of changing surrounding elementstpope/vim-fugitive
: Never leave Vim to do Git stuffplasticboy/vim-markdown
: Better visual editing of markdown filesjunegunn/vim-easy-align
: Align text and tablesman vim
:help