Vi Notes: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 23: Line 23:
  :set nonumber
  :set nonumber


=== End of file ===
=== End of line mark ===
 
:set list
 
=== Navigate to End of file ===


  G
  G


( capital )
( capital )
=== Join lines ===
aka remove line returns
J
Joins this line and then next with a space, resulting on one line.
gJ
join this line with the next with no space, handy for base64 encodes stuff


=== vim turn of auto indent ===
=== vim turn of auto indent ===
Line 71: Line 87:


  :syntax off
  :syntax off
== Interactive find replace ==
:%s/old/new/gc
:%s+old+new+
trailing g for many times in one line else once.


===fancy find replace===
===fancy find replace===
Line 100: Line 124:


  brackets2 stuff brackets1
  brackets2 stuff brackets1
== base64 ==
; decode
mark a visual area, then ":", you get
:'<,'>
make it this:
:'<,'>!python -m base64 -d
;encode?
:'<,'>!python -m base64
the whole file you say?
decode:
:%!python -m base64 -d
encode:
:%!python -m base64
I mean why ever leave vi?


== No wrap ==
== No wrap ==
Line 143: Line 195:


  :%s/\%xa0//g
  :%s/\%xa0//g
== Stupid mouse ==
mac being fancy and letting terminals know about my mouse.
cut that out wouldya?
file : ~/.vimrc
set mouse=


== Also See ==
== Also See ==

Latest revision as of 17:15, 25 February 2021

Search

forward:

/searchterm

backward

?searchterm

edit binary file in vi

:%!xxd

line numbering

Turn on:

:set number

Turn off:

:set nonumber

End of line mark

:set list

Navigate to End of file

G

( capital )

Join lines

aka remove line returns

J

Joins this line and then next with a space, resulting on one line.

gJ

join this line with the next with no space, handy for base64 encodes stuff

vim turn of auto indent

Use while pasting text.

:set paste
<then paste you stuff>
:set nopaste

tai64nlocal file in vi

:%!tai64nlocal

insert today's date

:r !date

Make <f5> be the "insert date" key.

:nnoremap <F5> "=strftime("%c")<CR>P
:inoremap <F5> <C-R>=strftime("%c")<CR>

more: http://vim.wikia.com/wiki/Insert_current_date_or_time

set tabs to be the ENGDEV way in vi

also called indenting

in the file:

/* ex: set tabstop=4 expandtab: */

or in ~/.vimrc

set tabstop=4
set expandtab

highlight searches:

set hlsearch

turn off colour

:syntax off

Interactive find replace

:%s/old/new/gc
:%s+old+new+

trailing g for many times in one line else once.

fancy find replace

uses match substitution. (X) -> \1

convert:

Target[server-5.location-5.mem]: `/usr/local/bin/snmp_mem_usage.pl public 192.168.5.5 real`

to

Target[server-1.location-5.Swap]: memTotalSwap.0&memTotalSwap.0:public@192.168.5.129:161::::2 - memAvailSwap.0&memAvailSwap.0:public@192.168.5.129:161::::2

in two (in vi):

%s: `/usr/local/bin/snmp_mem_usage.pl public ::g
%s/:\(.\+\) real`/ memTotalReal.0\&memTotalReal.0:public@\1:161::::2 - memAvailReal.0\&memAvailReal.0:public@\1:161::::2/

or more generically, reversing stuff:

%s/(brackets1) stuff (brackets2)/\2stuff\1/g

converts:

brackets1 stuff brackets2

to

brackets2 stuff brackets1

base64

decode

mark a visual area, then ":", you get

:'<,'>

make it this:

:'<,'>!python -m base64 -d
encode?
:'<,'>!python -m base64

the whole file you say?

decode:

:%!python -m base64 -d

encode:

:%!python -m base64

I mean why ever leave vi?

No wrap

:set nowrap

Convert to unix file format

:set ff=unix
  • unix LF only (each line ends with an LF character).
  • dos CRLF (each line ends with two characters, CR then LF).
  • mac CR only (each line ends with a CR character).

PIck up where you left off

might already be in /etc/vim/vimrc

" Uncomment the following to have Vim jump to the last position when                                                       
" reopening a file
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal! g'\"" | endif
endif

Unicode /Special characters

what am I looking at?
move the cursor over the character and issue "ga"

For example:

Submitted Jan 12 
ga
< > 160, Hex 00a0, Octal1240

Find replace:

:%s/\%xNN//g

for example:

:%s/\%xa0//g

Stupid mouse

mac being fancy and letting terminals know about my mouse.

cut that out wouldya?

file : ~/.vimrc

set mouse=

Also See