This presentation was prepared by me (Giacomo Mantani) in his personal capacity. The opinions expressed are the author’s own and do not reflect the view of the CeSeNA Security Team.
We focus on Vim, not Vi.
$ vim FILENAME
or
$ gvim FILENAME
+---------------------------------------+
|# |
|~ |
|~ |
|~ |
|~ |
|"file.txt" [New file] |
+---------------------------------------+
('#" is the cursor position.)
NORMAL (<Esc>
)
INSERT (i
, a
, I
, A
, o
, O
)
VISUAL (v
, V
)
REPLACE (r
, R
)
Command-Line (:
)
The editor behaves differently, depending on which mode you are in.
Do not ever touch your mouse or arrow keys!
hjkl
gg
G
f
F
}
{
In NORMAL mode we can switch to:
INSERT | VISUAL | REPLACE |
---|---|---|
|
|
|
|
||
|
Plus:
:
)<Esc>
)Cmd | Action |
---|---|
|
quit without save |
|
write and quit |
|
write and quit |
Cmd | Action |
---|---|
|
Goto last inserted text |
|
Goto older position in change list |
|
Edit the file under or after the cursor |
|
Goto definition of word under the cursor |
:TOHtml
$ vim phrack49.tar.gz # ;)
Demo.
:set noundofile viminfo=
:noswapfile edit secrets.txt
:X
instead :x
. It prompts a password for write the current file encrypted.key
option will be set with :X
. Never set it manually, it will be into viminfo*!cryptmethod
option. blowfish2
is the best choice.* The viminfo file is designed to store status information.
GnuPG, free implementation of the OpenPGP, allow you to encrypt and sign your data.
Arguing that you don’t care about the right to privacy because you have nothing to hide is no different from saying you don’t care about free speech because you have nothing to say. - Edward Snowden
g??
Rot13 on the fly!
Ebg13 ba gur syl!
.vimrc
CTRL-P
(previous) CTRL-N
(next) match.
CTRL-X CTRL-L
)CTRL-X CTRL-N
)dictionary
’ option (CTRL-X CTRL-K
)thesaurus
’ option (CTRL-X CTRL-T
)CTRL-X CTRL-I
)CTRL-X CTRL-]
)CTRL-X CTRL-F
)CTRL-X CTRL-D
)CTRL-X CTRL-V
)CTRL-X CTRL-U
)CTRL-X CTRL-O
)CTRL-X s
)complete
’ option (CTRL-N
)Do you prefer using <Tab>
?
function! CleverTab()
if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
return "\<Tab>"
else
return "\<C-N>"
endif
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
:syntax enable
:set background=dark
or :set background=light
:colorscheme solarized
:syntax clear
:syntax off
It is also possible to write your own syntax highlighted.
K
run a program to lookup the keyword under the cursor. The name of the program is given with the ‘keywordprg’ option (default is “man”).
Demo.
Contains information about the file list, window layout, global variables, options and more. Exactly what is remembered is controlled by the ‘sessionoptions’ option.
Cmd | Action |
---|---|
|
Create |
|
Load |
|
Restore |
A tag is a location where an identifier is defined. Vim let you to directly jump from any place to the tag. Create them with Exuberant CTAGS or Universal CTAGS.
Cmd | Action |
---|---|
|
Goto startlist definition |
|
Goto definition under the cursor |
|
Jump back |
|
Show traversed tags |
Vim has a set of so called “quickfix” commands. They enable you to compile a program from within Vim and then go through the errors generated and fix them (hopefully).
:make {arguments}
If errors were generated, they are captured and the editor positions you where the first error occurred.
:set makeprg=gcc\ -Wall\ -ggdb3\ -o\ %<\ %
Netrw makes reading files, writing files, browsing over a network or locally easy!
vim scp://hostname/path/to/file
vim ftp://hostname/path/to/file
vim /local/path/
I really enjoy spread knowledge and being helpful and I love to talk with smart people about everything.
Try to practice whenever it is possible!
;)