vi Editor
May 2, 2015 — 21:27

Author: silver  Category: bsd linux  Comments: 0

vimrc:

~/.vimrc

set number
filetype indent on
set expandtab
set shiftwidth=2
set softtabstop=2
syntax on
" set background=light
set background=dark
" colorscheme default

(” = comment)


commands:

:no paste
:set list
:set nolist

reindent:

gg=G


view/start vi readonly:

$ vi -R

xml syntax:

:set filetype=xml
:filetype indent on
gg=G


yl yank (copy) current character
yn yank n characters
yw yank the current word


run external shell command:

:!command
:!ls -la /tmp

:sh


vim visual mode:

visual line: SHIFT+V
visual block: CTRL+V


move code blocks:

on bracket/curley brace/parentheses: %


search history:

same as with ":"
press “/” then “UP” or “DOWN” key


goto column:

use "|<NUMBER>"
e.g. 80| moves to column 80


search:

to search for the word you are on
*
#


case:

to upper case, to lower case
~ (tilde)


bookmark:

set a bookmark called 'a'
ma
go to the bookmark called 'a' (the ` is the key left of 1)
`a

center:

center the screen on your current position
zz


current word:

select the current word (visual)
viw


format json:

:%!python -m json.tool

Leave a Reply