NUMBER | DATE | DESCRIPTION | NAME |
---|---|---|---|
0.9 |
2012-09-10 |
initial draft |
PS |
0.91 |
2012-09-21 |
add examples of:using your own script/apps, search multiple files,revision history,etc |
PS |
This is a quick demonstration about the functionality of VIM editor from a JTAC standpoint, This document provide a lot of text “screenshot” to demonstrate what the editor looks like when used in different scenarios. This document will not provide much details about the basic usage/commands/operations stuff - for that vimtutor command line tool that comes with VIM has done a great job.
overview
-
feature rich
-
it’s very rare that one job can be done only in other text editor but not in VIM, On the other hand, VIM has a lot of UNIQUE features that few other editors have
[although this is almost true, it is only based on experience of the authors. In theory, although the chances are slim, it is still possible that there exists a 3rd editor ("that 2nd editor" should be vi’s good company: emacs) that brings a new feature currently not yet supported by the two]
.
-
-
portability
-
available in all major platforms
-
*nix, MAC, Win
[again per my own experiences, I’ll rate linux/unix-like version the top, then macOS version. Windows version are as good as releases in other platforms in terms of features, but not as "nature" as unix/mac version (just think about its strangeC:\
file system notation…) personally I prefer to stick to vim-over- cygwin whenever I have to use windows]
-
-
"modal" editing, keyboard oriented
[believe it or not, keyboard IS more efficient , but that efficiency only comes after you (intentionally) stick to it to train your muscle memory and finally get used to it. otherwise mouse is still faster/easier for most people]
-
insert/normal/visual/replace/commandline/… mode
-
EVERYTHING can be done efficiently with keyboard
-
-
highly program(script)-able, customizable, flexible, extensible
-
easily compose new operator/operations per your own demand
-
vimL: programming language:
[vim Language, built-in ability to combine vim command together to make a script. personally I think vimL is the essential/unique power of vim comparing with other editors]
-
Here is a good article introducing VIM for its "20 years anniversary" :
1. vim as an text editor
1.1. editor(e.g: notepad, ULTRAEDIT)
-
Vim has 6 basic modes and 6 additional modes.
-
4 of them are most commonly used
-
insert
like notepad, whatever you typed in will be inserted as file content
some of the frequently used
[this really depends on your personal favorite/habit - since there are always multiple ways to do the same thing in vim, different person might have quite different “musal memories”]
insert-mode commands -
normal mode
every keystroke is a "command".For navigation and manipulation of text.
some of the frequently used normal-mode commands
-
visual mode
visually select text in characters-wise, line-wise, or block-wise For navigation and manipulation of text selections, this mode allows you to perform most normal commands, and a few extra commands, on selected text.
some of the frequently used visual-mode commands
-
command-line mode
jump into the bottom of the editor, and type in vim command
-
-
vim help
:help vim-modes-info :help Normal-mode :help visual-mode :help Insert-mode :help Command-line-mode
-
vimtutor - a (very intuitive) program to learn vim program:
-
vimtutor: a shell command to teach you how to use vim
vimtutor=============================================================================== = W e l c o m e t o t h e V I M T u t o r - Version 1.7 = =============================================================================== Vim is a very powerful editor that has many commands, too many to explain in a tutor such as this. This tutor is designed to describe enough of the commands that you will be able to easily use Vim as an all-purpose editor. The approximate time required to complete the tutor is 25-30 minutes, depending upon how much time is spent with experimentation. ATTENTION: The commands in the lessons will modify the text. Make a copy of this file to practise on (if you started "vimtutor" this is already a copy). It is important to remember that this tutor is set up to teach by use. That means that you need to execute the commands to learn them properly. If you only read the text, you will forget the commands! Now, make sure that your Shift-Lock key is NOT depressed and press the j key enough times to move the cursor so that Lesson 1.1 completely fills the screen. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 1.1: MOVING THE CURSOR ** To move the cursor, press the h,j,k,l keys as indicated. ** ^ 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 1. Move the cursor around the screen until you are comfortable. 2. Hold down the down key (j) until it repeats. Now you know how to move to the next lesson. 3. Using the down key, move to Lesson 1.2. NOTE: If you are ever unsure about something you typed, press <ESC> to place you in Normal mode. Then retype the command you wanted. NOTE: The cursor keys should also work. But using hjkl you will be able to move around much faster, once you get used to it. Really! "/tmp/tutorunYxYO" 970 lines, 33256 characters
-
-
moving around(motions)
-
h/l/j/k/ctrl-f/ctrl-b/…
-
-
insert/delete/change/replace/etc
-
i/I/x/X/d../c../C/r/R
-
-
undo/redo
-
u/c-r
-
-
charactor/line/block-wise text selection
-
v/V/ctrl-v + motion keys
-
-
search (real-time, incremental)
-
keystroke: / ? # g# * g* n N
-
/<UP> /<DOWN> ?<UP> ?<DOWN>…
-
options: set hls is nows
-
-
search and replace - substitution
:%s/cisco/juniper/gc
-
more resources
:help usr_02
1.2. search with more weapons
-
regex(regular expression or "pattern"):
-
search for portion of data that we care most
-
-
range:
-
A range permits a command to be applied to a group of lines
-
many way to define a range:
-
visual select
[this is done by press v,V or ctrl-v from normal mode, then move the cursor by motion keys(e.g, h,l,j,k). Pressing ‘:’ after that will bring (nicely) your cursor into the bottom command line area with the visual selection range marks :'<,'> that you can start your command with.]
delete visual selected texts:'<,'>delete
-
mark
[this is done by pressing mN, where N is a letter a to z, to generate a mark, say mark ‘a’, to mark a position for later use]
search for keyword ‘abc’ from mark ‘a’ to mark ‘b’:'a,'bg/abc/
-
line numbers
indent from line 1 to line 20:1,20>
-
search back and forth
search for “abc”, but only from last occurrence of ‘`#show '’ to the next occurrence of it:?#show ?,/#show /g/abc/
-
-
-
global: search and perform other useful actions:
-
default action on search is "jump to the matches" (to have a look)
-
there can be other actions triggered on (a) match(es)
[this is extremely powerful — ANY vim command can act on the matched texts, see :help global]
-
replace(substitution),
-
print,
-
delete,
-
copy(‘yank’ in vi/vim term),
-
sort
-
etc
-
-
vim :global command syntax
search for “matches”:[range]g[lobal]/{pattern}/[cmd]
search for “non-matches”:[range]v[global]/{pattern}/[cmd]
-
how it works
The global commands work by first scanning through the [range] lines and marking each line where a match occurs (for a multi-line pattern, only the start of the match matters). In a second scan the [cmd] is executed for each marked line with its line number prepended. For ":v" and ":g!" the command is executed for each not marked line. If a line is deleted its mark disappears.
— :help global
-
1.3. search example: regex (JTAC may like)
[this is useful for the device log syntax folding that will be demonstrated in later sections, which requires using regex to recognize each command line and its output]
/^\(\S\S\+[^ <(]\{0,37}\S[#>%$]\s*\S\+\|slot \d\d\=->\S\+\|->.\+\|\*-\*-\*-\*-\*-\)/
-
must contain at least one of following as a PS var
[Prompt String Variable]
:'#' : cisco,juniper...priviledge mode, unix root '>' : cisco,juniper...exec mode,some unix shell '%' '$' : some unix shell prompt '->' : junos-e vxworks shell '*-*-*-*-*-' : junos-e show-tech
-
and ,
-
for PS #,> or %:
-
at least 2 charactors before #,e.g.: R1#blabla
-
leading spaces are ok in CMD : R1# blabla
-
no space preceding : R1 blabla (not ok)
-
must has at least 2 non-blank chars in beginning of the line, and
-
must NOT contain any of following chars before the PS var,
: blank < : a literal '<' charactor ( : a literal '(' charactor ] : a literal ']' charactor
-
must has no more than 40 chars in total before a # or > or % char, and
-
must has at least 1 non-blank (space, tab) charactor as a command, and
-
-
or , for PS ‘->’ (junoe "shell" mode): different flavors are supported
-
this can be the ERX LM line card shell mode
slot NN->CMD
where N can be 1 or 2 digits (e.g. LM line card number),
-
this can be ERX LM serial shell mode
->CMD
where CMD can be 1 (like an t, means task) or more CHs ,
-
this can be the ERX SRP shell mode ,w/ a preceding space,
-> CMD
-
-
or , for ‘*-*-*-*-*-’
-
no any other contition modifier (there must be no other charactors),
-
this is simply ERX tech-support command delimitor
-
-
-
overall, basically it matches a command line in logs generated by:
-
JUNOS based product (M/T/MX)
-
JUNOSe(ERX)
-
CISCO
-
UNIX/LINUX
-
any other devices that use # , > or % as a prompt (can be changed per demand)
-
1.4. search example: global
sometime one single CLI print long long outputs(600+ lines) you need a way to collect only some lines based on a desired criterials. for example in the following long (600+ lines) outputs of a ‘show’ command:
1 NWRKNJ-VFTTP-138:vol#show ip int lag OLT01.2570039
2 lag OLT01.2570039 line protocol VlanSub is up, ip is up
...<snipped>...
42 IP policy input jnpr-VIDEO:ONLY
43 classifier-group dhcp entry 1
44 0 packets, 0 bytes
45 rate-limit-profile dhcplimit
46 committed rate: 1280 bps, committed burst: 8192 bytes
47 excess burst: 0 bytes
48 committed: 0 packets, 0 bytes, action: transmit
49 conformed: 0 packets, 0 bytes, action: drop
50 exceeded: 0 packets, 0 bytes, action: drop
51 classifier-group jnpr-VIDEO-TRAFFIC entry 1
...<snipped>...
62 classifier-group jnpr-VIDEO-TRAFFIC entry 2
...<snipped>...
535 classifier-group jnpr-VIDEO-TRAFFIC entry 45
...<snipped>...
644 Dropped exceeded packets 0, bytes 0
645
647 NWRKNJ-VFTTP-138:vol#
So, the issue here is: how to collect ACL entries with NON ZERO counters only in the following line ?
-
regex
:'<,'>g/classifier-group.*\n\s*[1-9]\d* packets/
result:found 3 ACL entries (out of 50+) with non-zero counters in the following line:'<,'>g/classifier-group.*\n\s*[1-9]\d* packets/ 44 classifier-group dhcp entry 1 525 classifier-group VIDEO-TRAFFIC entry 44 536 classifier-group DNS-TRAFFIC entry 1
-
regex
:'<,'>g/classifier-group.*\n\s*[1-9]\d* packets/.,+1p
result:ACL entries along with following non-zero value counters:'<,'>g/classifier-group.*\n\s*[1-9]\d* packets/.,+1p 44 classifier-group dhcp entry 1 45 1 packets, 378 bytes 525 classifier-group VIDEO-TRAFFIC entry 44 526 84 packets, 12665 bytes 536 classifier-group DNS-TRAFFIC entry 1 537 2 packets, 226 bytes
-
a short version
"empty" pattern will call the _previous applied pattern: really handy!:g// :g//.,+1p
1.5. search example: global with range (good for large files)
:?#show ?,$g/classifier-group.*\n\s*[0-9]\d* packets/.,+1p
:?#show ?,/#show /g/classifier-group.*\n\s*[0-9]\d* packets/.,+1p
1.6. search example: spanning files
there are many ways to search across files/folders. Here are 2 way that is commonly used:
-
use vim’s built-in grep: vimgrep
search "error" or "fail", case insensitive, in all log files under curr cursor and call the search result,edit,modi,save..as usual
:vimgrep /show resource\c\|fail\c/j ./logs/**/*.log
-
use external grep tool
use external grep toolgrep! -R "errors" ./logs/**
Vim’s quickfix window was originally designed as a special mode to speedup the edit-compile-edit cycle. The idea is to save the error messages from the compiler in a file and use Vim to jump to the errors one by one. You can examine each problem and fix it, without having to remember all the error messages.
but in practice, regardless of code developing, “quickfix” window can also be used to quickly locate the target matching result.
:cw or :copen
:help quickfix
+ 55305 +--645 lines: NWRKNJ-VFTTP-138:vol#show ip int lag OLT01.2570039
+ 55950 +--646 lines: NWRKNJ-VFTTP-138:vol#show ip int lag OLT01.2570039
+ 56596 +--645 lines: NWRKNJ-VFTTP-138:vol#show ip int lag OLT01.2570039
+ 57241 +--645 lines: NWRKNJ-VFTTP-138:vol#show ip int lag OLT01.2570039
+ 57886 +--646 lines: NWRKNJ-VFTTP-138:vol#show ip int lag OLT01.2570039
+ 58532 +--648 lines: NWRKNJ-VFTTP-138:vol#show ip int lag OLT01.2570039
59180 NWRKNJ-VFTTP-138:vol#show resou
- 59181 NWRKNJ-VFTTP-138:vol#show resource
| 59182 Resource Threshold Trap: enabled
| 59183 max current rising falling hold-down
| 59184 type location capacity value threshold threshold time
| 59185 --------------------------- -------- -------- ------- --------- --------- ---------
| 59186 ip interface system 96001 13439 86401 960 300
| 59187 ip interface slot 1 16383 1 14745 164 300
| 59188 ip interface slot 2 16383 0 14745 164 300
| 59189 ip interface slot 3 16383 0 14745 164 300
./vzlogs/2012-0807-0813.log [utf-8] [jel] [59181/76232,22] [77%] [-----------------------------------0-
3 ./vzlogs/2012-0611-0858.log|20240 col 23| ^MPHLAPA-VFTTP-113:vol#show resource
4 ./vzlogs/2012-0711-0022.log|343 col 18| ^MCMDNNJ-VFTTP-27#show resource
5 ./vzlogs/2012-0807-0813-info.log|442 col 22| NWRKNJ-VFTTP-138:vol#show
resource
6 ./vzlogs/2012-0807-0813.log|59181 col 22| NWRKNJ-VFTTP-138:vol#show resource
7 ./vzlogs/2012-0810-0516.log|1866 col 18| ^MLSANCA-VFTTP-88#show resource
8 ./vzlogs/2012-0810-0886.log|205 col 18| ^MWASHDC-VFTTP-89#show resource
9 ./vzlogs/2012-0811-0055.log|926 col 18| ^MPHLAPA-VFTTP-87#show resources
10 ./vzlogs/2012-0811-0055.log|33906 col 18| ^MPHLAPA-VFTTP-87#show resource
11 ./vzlogs/2012-0811-0056.log|333 col 19| ^MTAMPFL-VFTTP-130#show resource
12 ./vzlogs/2012-0811-0056.log|5208 col 23| ^MTAMPFL-VFTTP-130:vol#show resource
13 ./vzlogs/2012-0811-0058.log|221 col 19| ^MNWRKNJ-VFTTP-153#show resource
14 ./vzlogs/2012-0811-0079.log|247 col 18| ^MPHLAPA-VFTTP-79#show resource
15 ./vzlogs/2012-0811-0081.log|1272 col 18| ^MPHLAPA-VFTTP-91#show resource
16 ./vzlogs/2012-0811-0083.log|237 col 18| ^MDLLSTX-VFTTP-88#show resource
17 ./vzlogs/2012-0811-0088.log|2193 col 18| ^MWASHDC-VFTTP-99#show resource^M
18 ./vzlogs/2012-0811-0104.log|393 col 19| ^MNYCMNY-VFTTP-120#show resource
19 ./vzlogs/2012-0812-0048.log|1550 col 18| ^MPHLAPA-VFTTP-91#show resource^M
20 ./vzlogs/2012-0812-0048.log|16088 col 18| ^MPHLAPA-VFTTP-91#show resource^M
21 ./vzlogs/2012-0812-0059.log|253 col 19| ^MWASHDC-VFTTP-130#show resource
22 ./vzlogs/2012-0812-0071.log|1030 col 18| ^MPHLAPA-VFTTP-75#show resource
23 ./vzlogs/2012-0812-0082.log|250 col 19| ^MWASHDC-VFTTP-131#show resource
24 ./vzlogs/2012-0812-0084.log|934 col 18| ^MNWRKNJ-VFTTP-53#show resource
25 ./vzlogs/2012-0812-0094.log|284 col 19| ^MNYCMNY-VFTTP-136#show resource
the quick fix window, listing all matched lines from all files containing any matches | |
put the cursor in a line in the quickfix window, press <enter>, the corresponding file containing current match will be opened in another window | |
the file opened in a new window , with the matched line(s) displayed | |
the matched line in the opened file |
1.7. window split
[vim’s auto-completion system is as fantastic as its other features, you can use the pretty much the similiar way to complete a command as when you are typing a command in a modern linux bash , or a cisco router]
29 ^MBSTNMA-VFTTP-117#show version
30 Juniper Edge Routing Switch E320
31 Copyright (c) 1999-2012 Juniper Networks, Inc. All rights reserved.
32 System Release: e320_12-1-1p0-3.rel
33 Version: 12.1.1 patch-0.3 [BuildId 14015] (February 20, 2012 14:18)
34 Active Hotfixes:
35 e320_12-1-1p0-3_hf2331.hfx
36 e320_12-1-1p0-3_hf2236.hfx
37 e320_12-1-1p0-3_hf2235.hfx
38 e320_12-1-1p0-3_hf2228.hfx
39 e320_12-1-1p0-3_hf2421.hfx
40 e320_12-1-1p0-3_hf2383.hfx
vzlogs/2012-0829-0443.log [utf-8] [jel] [29/6208,20] [0%] [0--------------------------------]
67 ^MBSTNMA-VFTTP-117#show hardware
68 Chassis
69 -------
70 serial assembly assembly Major/Minor
71 type number number rev. rev
72 ------- ---------- ---------- -------- -----------
73 Chassis 4309237522 4580002400 A10 0.10
74
75 Modules
76 -------
77 serial assembly assembly ram Major/Minor
78 slot type number number rev. (MB) rev
vzlogs/2012-0829-0443.log [utf-8] [jel] [67/6208,20] [1%] [0--------------------------------
29 ^MBSTNMA-VFTTP-117#show version 67 ^MBSTNMA-VFTTP-117#show hardwar
30 Juniper Edge Routing Switch E320 68 Chassi
31 Copyright (c) 1999-2012 Juniper 69 ------
Networks, Inc. All rights reserved. 70 serial assembl
32 System Release: e320_12-1-1p0-3.rel 71 type number number
33 Version: 12.1.1 patch-0.3 72 ------- ---------- --------
[BuildId 14015] (February 20, 2012 73 Chassis 4309237522 45800024
14:18) 74
34 Active Hotfixes: 75
35 e320_12-1-1p0-3_hf2331.hfx 76
36 e320_12-1-1p0-3_hf2236.hfx 77 serial
37 e320_12-1-1p0-3_hf2235.hfx 78 slot type number
38 e320_12-1-1p0-3_hf2228.hfx 79 ---- ------- ---------- -
39 e320_12-1-1p0-3_hf2421.hfx 80 0 LM-10 4608380483 4
40 e320_12-1-1p0-3_hf2383.hfx 81 1 LM-4 4709130293 4
41 System running for: 859 days, 23 hours82 2 --- ---
33 minutes, 33 seconds 83 3 LM-10 4307406340 4
42 (since THU APR 22 2010 14:46:084 4 --- ---
UTC) 85 5 LM-10 4710230418 4
43 86 6 SRP-320 4709152986 4
44 slot state type admin spare 87 6 SFM-320 4709152986 4
running release slot uptime 88 7 SRP-320 4709152996 4
45 ---- -------- ------- ------- ----- --89 7 SFM-320 4709152996 4
--------------- --------------- 90 8 SFM-320 4709141732 4
@ 91 9 SFM-320 4709141744 4
vzlogs/2012-0829-0443.log [utf-8] [jel] [29/62> vzlogs/2012-0829-0443.log [u
1.8. multi-page display (layout option in MSword)
[this requires MPage plugin]
6 ^MBSTNMA-VFTTP-117#term len 0 33 Version: 12.1.1 patch-0.3
7 ^MBSTNMA-VFTTP-117#term width 200 34 Active Hotfixes:
8 ^MBSTNMA-VFTTP-117#show clock 35 e320_12-1-1p0-3_hf2331.hfx
9 WED AUG 29 2012 14:19:13 UTC 36 e320_12-1-1p0-3_hf2236.hfx
10 ^MBSTNMA-VFTTP-117# 37 e320_12-1-1p0-3_hf2235.hfx
11 ^MBSTNMA-VFTTP-117# 38 e320_12-1-1p0-3_hf2228.hfx
12 ^MBSTNMA-VFTTP-117# 39 e320_12-1-1p0-3_hf2421.hfx
13 ^MBSTNMA-VFTTP-117#support 40 e320_12-1-1p0-3_hf2383.hfx
14 ^MPassword: ***** 41 System running for: 859 days, 23 h
15 ^MBSTNMA-VFTTP-117(support)#shell 42 (since THU APR 22 2010 14:
16 43
17 -> 44 slot state type admin spar
18 -> 45 ---- -------- ------- ------- ----
19 -> 46 0 online LM-10 enabled spar
20 -> exit 47 1 online LM-4 enabled ---
21 ^MBSTNMA-VFTTP-117(support)#exit 48 2 --- --- --- ---
22 ^MBSTNMA-VFTTP-117# 49 3 inactive LM-10 enabled ---
23 ^MBSTNMA-VFTTP-117# 50 4 --- --- --- ---
24 ^MBSTNMA-VFTTP-117# 51 5 online LM-10 enabled ---
25 ^MBSTNMA-VFTTP-117# 52 6 online SRP-320 enabled ---
26 ^MBSTNMA-VFTTP-117# 53 6 online SFM-320 enabled ---
27 ^MBSTNMA-VFTTP-117# 54 7 standby SRP-320 enabled ---
28 ^MBSTNMA-VFTTP-117# 55 7 online SFM-320 enabled ---
29 ^MBSTNMA-VFTTP-117#show version 56 8 online SFM-320 enabled ---
30 Juniper Edge Routing Switch E320 57 9 online SFM-320 enabled ---
31 Copyright (c) 1999-2012 Juniper Ne 58 10 online SFM-320 enabled ---
32 System Release: e320_12-1-1p0-3.re 59 11 online LM-10 enabled spar
vzlogs/2012-0829-0443.log [utf-8] [jel] [6/6208,1] [0%] > vzlogs/2012-0829-04
1.9. MUCH MORE as an editor
-
external tool integration
-
folding
-
advanced undo system: (time machine)
-
undo over branch,
-
permanent undo over close
-
-
split
-
diff & patch
-
multi-page(MPage)
-
text hyper links(utl)
-
math
-
column/block editing(c-v)
-
alignment(Align)
-
write/append selected texts into other files
-
multiple clipboard (register)…
-
syntax highlighting (customizable)
-
colorscheme can be easily changed to your favorite
-
default and koehler is my favorite
-
-
user defined command (command)
-
event triggered action (autocmd)
-
platform independent Chinese input system (vimim)
-
…
-
encryption
you can encrypt your file , open it with a password, work on it, then save it still in the encrypted from.
2. external tools integration (JTAC may like)
-
JTAC help customer to troubleshooting the outage
-
to troubleshoot JTAC need log(files)
-
good tools can help
-
notepad is too slight handling large files …
[notepad is still a good note pad, even though MS-word/office are dominating today]
-
more is no more much useful
-
less is actually much more feature-rich,faster and agile
[one of the best (my favorite) text ‘viewer’/or ‘pager’]
-
grep good/bad info out of raw log
-
sort to make log entries in (wanted) order
-
uniq to remove redundant entries
-
cut good info out of raw entries
-
ed/sed/awk is useful for pipelines/oneliner lovers or scripting
-
diff old&new files and then patch the old into new one
-
…
-
how to only search a specific portion of a file (range)?
a log file may contain over 20 command captures, but what if we only want to search in the output of "show system log" command?
you can copy a portion of the file & paste into a temporary file for your grep to run on it, but this is not convenient and sometimes boring if you have to repeat over. -
you have to blindly type in the keyword you want to search
use grep with pipe in terminal is handy,but blindly typing in long keyword/pattern from terminal without seeing them when you are typing is sometime pain/error-prone.
e.g you have to remember(or write down) this long stupid-looking command that you want to search before you can type them in the terminal: print__11Ic1Detector -
it will add more pain and inconvenience in the case that you are not sure about the keyword to search. — you will have to refine the pattern and repeat the above whole process allover again and again.
-
integrates all(most) equivalent functions of these tools
-
provides a universal interface to for external utilities
-
use legendary *nix tool in a new/more nature way, from inside vim
-
all CLI based apps,supporting stdin/stdout steams, including you own APPs, can be re-used
-
that’s why "text stream"(pipes) is part of essential UNIX philosophy
-
-
you can do following in almost real time and a much intuitive way:
-
search with a pattern
-
get search result
-
start a new search based on the search result (‘search out of search result’)
-
undo the search (steps back to where we were)
-
redo a search (steps forward to the previous search result)
-
refine the new search pattern
-
repeat the whole process
-
-
syntax
:{motion}{ext-prog}
2.1. external tool example: ‘grep’ from inside vim
2.1.1. quick review of ‘grep’
grep is a utility for searching plain-text data sets for lines matching a regular expression. Its name comes from the old ‘ed’ command g/re/p (global / regular expression / print) grep is versatile tool with full feature regex support, here we list the simplest and most commonly usage just in order to demonstrate how to use external tools from within vim.
following are some quick examples, each paired with an equivalent vim command that calls external grep command directly but from within vim editor
-
get useful info
cat FILE | grep -i "what-i-want" RANGE!grep -i "what-i-want"
-
trash garbage info
cat FILE | grep -v "what-i-don't-need" RANGE!grep -v "what-i-don't-need"
-
logical ‘OR’
cat FILE | grep -E "want-this|or-that" RANGE!grep -E "want-this|or-that"
-
"search out of search results", recursively
[This is one of the many places that vim can get work done better than traditional way - you can look at the text in the vim editor while thinking of what can be the next good pattern/keyword for the next grep , and see the grep result right away in the same editor. This is indeed much better than the traditional way that you each time have to check the grep result by redirecting it either to a temp file so you can open with another editor, or to a text pager/viewer (like ‘more’ or ‘less’), then quit the file or text pager, refine your grep and repeat the whole thing all over.]
Example 8. find lines about bgp related info, generated 8/16/2012, and containing keyword "peer reset"“traditional” waycat FILE | grep "bgp" | grep "8/16/2012" | grep "peer reset"
vim wayRANGE!grep "bgp" | grep "8/16/2012" | grep "peer reset"
-
repeat the refining process right on refined text which you are visually seeing in the editor
— this is a really powerful but still convenient method to approach a complex target -
never need to leave/exit editor to use external tools from another terminal!
2.1.2. grep example: "increamental multi-steps search"
To make it simple, you can always just use the simplest grep, do it multiple times , each time with a new pattern, to gradually narrow down the target logs entries. Or, for "power" grep user, putting everything in one line (“one-liner”) is a faster way to get the end result in just one go.
.RCMDVA-VFTTP-18#show log data sev deb
1
RCMDVA-VFTTP-18#show log data sev deb
2 *** stored log messages ***
3 *** log: all
4 *** severity: DEBUG and higher
5 *** no baseline
6
7 NOTICE 08/07/2012 03:41:54 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to hold timer expired
8 NOTICE 08/07/2012 03:42:16 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core enters established state
9 NOTICE 08/07/2012 03:45:02 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to hold timer expired
...<snipped>...
216 NOTICE 08/07/2012 07:54:57 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core enters established state
217 NOTICE 08/07/2012 07:57:06 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to hold timer expired
218 NOTICE 08/07/2012 07:57:21 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core enters established state
219 DEBUG 08/07/2012 07:59:35 UTC ethernet (GigabitEthernet14/0/3.1680): Ethernet::setIfAdminStatusCommon() for VlanSub 0x2300b925 ifAdminStatus=Down, validateOnly = true, icrAdmin = 1, askIcr = true
220 DEBUG 08/07/2012 07:59:44 UTC ethernet: Ethernet::removeVlanSubInterface VlanSub 0x2300b925 over VlanMajor 0x2200004e
221 NOTICE 08/07/2012 08:00:04 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to hold timer expired
222 NOTICE 08/07/2012 08:00:28 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core enters established state
223 DEBUG 08/07/2012 08:01:38 UTC ethernet (GigabitEthernet14/1/7.1596): Ethernet::setIfAdminStatusCommon() for VlanSub 0x23002b5e ifAdminStatus=Down, validateOnly = true, icrAdmin = 1, askIcr = true
224 DEBUG 08/07/2012 08:01:43 UTC ethernet: Ethernet::removeVlanSubInterface VlanSub 0x23002b5e over VlanMajor 0x2200005d
225 NOTICE 08/07/2012 08:03:22 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to hold timer expired
226 DEBUG 08/07/2012 08:03:30 UTC ethernet (GigabitEthernet13/0/3.504): Ethernet::setIfAdminStatusCommon() for VlanSub 0x23000914 ifAdminStatus=Down, validateOnly = true, icrAdmin = 1, askIcr = true
227 DEBUG 08/07/2012 08:03:34 UTC ethernet: Ethernet::removeVlanSubInterface VlanSub 0x23000914 over VlanMajor 0x22000046
228 NOTICE 08/07/2012 08:03:48 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core enters established state
...<snipped>...
1735 DEBUG 08/20/2012 19:02:34 UTC ethernet: Ethernet::removeVlanSubInterface VlanSub 0x2300be27 over VlanMajor 0x22000055
1736 DEBUG 08/20/2012 19:02:37 UTC ethernet (GigabitEthernet12/0/2.1343): Ethernet::setIfAdminStatusCommon() for VlanSub 0x2300be28 ifAdminStatus=Down, validateOnly = true, icrAdmin = 1, askIcr = true
1737 DEBUG 08/20/2012 19:02:42 UTC ethernet: Ethernet::removeVlanSubInterface VlanSub 0x2300be28 over VlanMajor 0x22000045
1738 DEBUG 08/20/2012 19:16:31 UTC ethernet (GigabitEthernet13/0/2.3185): Ethernet::setIfAdminStatusCommon() for VlanSub 0x23004add ifAdminStatus=Down, validateOnly = true, icrAdmin = 1, askIcr = true
1739 DEBUG 08/20/2012 19:16:34 UTC ethernet: Ethernet::removeVlanSubInterface VlanSub 0x23004add over VlanMajor 0x22000048
1740 DEBUG 08/20/2012 19:30:37 UTC ethernet (GigabitEthernet14/1/5.98): Ethernet::setIfAdminStatusCommon() for VlanSub 0x2300be07 ifAdminStatus=Down, validateOnly = true, icrAdmin = 1, askIcr = true
1741 DEBUG 08/20/2012 19:30:41 UTC ethernet: Ethernet::removeVlanSubInterface VlanSub 0x2300be07 over VlanMajor 0x2200004a
-
have timestamps during Aug.7 abt. 5 to 6 UTC, AND
-
be related any of the following:
-
are about bgp AND
-
reset by peer, OR ,
-
to have more clues about the cause, any of the following events in between are wanted:
-
link down/up
-
warn(ings)
-
error
-
fail(ures)
-
-
:'<,'>!grep "08\/07"
:'<,'>!grep "0[5-6]:"
:'<,'>!grep -iE "bgp|link|warn|error|fail"
:'<,'>!grep -iE "code 54|link|warn|error|fail|"
|
1 RCMDVA-VFTTP-18#show log data sev deb
85 NOTICE 08/07/2012 05:18:59 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to tcp connection error: TCP error code 54 (Connection reset by peer)
97 NOTICE 08/07/2012 05:32:50 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to tcp connection error: TCP error code 54 (Connection reset by peer)
100 NOTICE 08/07/2012 05:56:15 UTC ethernet (GigabitEthernet12/0/2): linkDown Ethernet 0x6000016
135 NOTICE 08/07/2012 06:26:25 UTC bgpNeighborChanges (vol): internal peer 130.81.248.130 in core leaves established state due to tcp connection error: TCP error code 54 (Connection reset by peer)
967 NOTICE 08/07/2012 06:56:42 UTC ethernet (GigabitEthernet12/0/2): linkUp Ethernet 0x6000016
1728 WARNING 08/07/2012 18:33:10 UTC ha: High Availability is disabled. View the srp redundancy status to determine the cause.
As mentioned, you can also achieve the same effect by composing a complex grep regex in one line
:'<,'>!grep -iE "08\/07.* 0[5-6]:(.*bgp.*code 54|link|warn|error|fail)"
:'<,'>!grep -iE "08\/07.* 0[5-6]:(.*bgp.*code 54|link|warn|error|fail)"
2.1.3. more grep example
need help from ‘grep’ since there is no fancy options a/v by original ‘dir’ command
[even MS-dos support some of the sort options to some extent for their
version of ‘dir’]
CLR2.Austin-TX#dir ?
FILE PATH The name of the local file or directory to list
short Provide brief listing
<cr>
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:/incoming <DIR> 0 10/03/2007 16:11:26
disk0:/outgoing <DIR> 0 10/03/2007 16:11:26
disk0:clr2-austin-ping.cnf 1712159 1712159 08/07/2012 08:52:10
disk0:20110419.cnf 1240326 1240326 08/22/2012 10:46:02
disk0:xoBGP736.cnf 215140 215140 08/22/2012 12:24:46
disk0:20100727.cnf 3331572 3331572 07/27/2012 07:49:14
disk0:moe1440-736-020111.cnf 1295880 1295880 02/01/2011 18:37:56
disk0:GE-test.cnf 1295880 1295880 02/01/2011 18:22:56
disk0:10-3-1xo.cnf 1212543 1212543 03/21/2011 04:43:40
disk0:Santana.cnf 3328569 3328569 06/15/2012 03:58:58
disk0:clr2-austin.cnf 1711986 1711986 08/02/2012 08:14:12
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:jan29th08.scr 1103161 1103161 01/29/2008 16:45:52
disk0:March7MOE.scr 348591 348591 03/07/2008 12:04:38
disk0:March11MoeConfig.scr 349102 349102 03/11/2008 09:57:34
disk0:March19MOE.scr 349921 349921 03/19/2008 14:01:12
disk0:may15th.scr 20637 20637 05/15/2008 11:07:50
disk0:June11th.scr 22926 22926 06/11/2008 13:43:26
disk0:August19th.scr 23192 23192 08/19/2008 13:50:42
disk0:latency-812.scr 59733 59733 09/05/2008 10:36:08
disk0:latenRecreate812.scr 163015 163015 09/05/2008 18:18:14
disk0:latency_finalResutls723.scr 161098 161098 09/07/2008 22:17:38
disk0:ATTStaticPPP823Final.scr 7012873 7012873 09/09/2008 16:48:12
disk0:VZ_latency0912_812p033.scr 187429 187429 09/12/2008 11:37:58
disk0:LI_work_812.scr 187528 187528 09/25/2008 13:35:52
disk0:li_823.scr 187555 187555 09/26/2008 09:48:34
disk0:snmp.scr 794894 794894 12/15/2008 16:50:18
disk0:emc613.scr 6000 6000 02/05/2009 11:56:10
disk0:emc613mod.scr 6087 6087 02/05/2009 12:51:50
disk0:xo_bgp_recret.scr 11072 11072 02/25/2010 19:21:54
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:xo613bgp.scr 10274 10274 03/04/2010 12:26:34
disk0:backup-jan-31-2011.scr 60257 60257 01/31/2011 16:52:36
disk0:lab-config.scr 478140 478140 02/01/2011 12:58:54
disk0:lab-config-wrong.scr 127785 127785 02/01/2011 00:01:10
disk0:lab-config-right.scr 471302 471302 02/01/2011 13:07:46
disk0:COC3_COC12_5_08_22_2011_23_45.dmp 24166111 24166111 08/22/2011 23:45:56
disk0:lab-config-b4upgrade.scr 471248 471248 02/01/2011 18:47:22
disk0:lab-config-afterupgrade.scr 470600 470600 02/01/2011 19:15:36
disk0:test.scr 474491 474491 03/31/2011 05:13:26
disk0:7-3-6XO.scr 473396 473396 03/21/2011 04:32:46
disk0:7-3-6XO_modified.scr 473046 473046 03/21/2011 04:46:32
disk0:7-3-6-XO_April29.scr 474538 474538 04/29/2011 09:41:06
disk0:srp_stats.tsa 16346209 16346209 09/03/2012 06:44:20
ram:bulkstats1.sts 66004 66004 09/03/2012 06:44:20
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
:'<,'>!grep ".*.dmp"
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:COC3_COC12_5_08_22_2011_23_45.dmp 24166111 24166111 08/22/2011 23:45:56
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
get all ‘GE’ ( AND ) ‘dmp’ files
[if you grep out of previous grep results, naturely the new operation
is always logical “AND” to previous operation, just like you grep everything
at one go :'<,\'>!grep "GE.*.dmp"]
:'<,'>!grep "GE"
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
:'<,'>!grep "08/22/2012"
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:20110419.cnf 1240326 1240326 08/22/2012 10:46:02
disk0:xoBGP736.cnf 215140 215140 08/22/2012 12:24:46
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
:'<,'>!grep ".*.dmp.*08/22/2012"
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
:'x,'y!grep -iE "08/22/2012|GE"
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:20110419.cnf 1240326 1240326 08/22/2012 10:46:02
disk0:xoBGP736.cnf 215140 215140 08/22/2012 12:24:46
disk0:GE-test.cnf 1295880 1295880 02/01/2011 18:22:56
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
:'<,'>!grep -iEv ".*.cnf|.*.scr"
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:/incoming <DIR> 0 10/03/2007 16:11:26
disk0:/outgoing <DIR> 0 10/03/2007 16:11:26
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:COC3_COC12_5_08_22_2011_23_45.dmp 24166111 24166111 08/22/2011 23:45:56
disk0:srp_stats.tsa 16346209 16346209 09/03/2012 06:44:20
ram:bulkstats1.sts 66004 66004 09/03/2012 06:44:20
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
2.2. external tool example: ‘sort’ from inside vim
ERX-40-89-f2#dir
Please wait...
unshared in
file size size date (UTC) use
--------------------------------------- --------- --------- ------------------- ---
disk0:/incoming <DIR> 0 10/03/2007 16:11:26
disk0:/outgoing <DIR> 0 10/03/2007 16:11:26
disk0:clr2-austin-ping.cnf 1712159 1712159 08/07/2012 08:52:10
disk0:20110419.cnf 1240326 1240326 04/19/2012 10:46:02
disk0:xoBGP736.cnf 215140 215140 03/04/2010 12:24:46
disk0:20100727.cnf 3331572 3331572 07/27/2012 07:49:14
disk0:moe1440-736-020111.cnf 1295880 1295880 02/01/2011 18:37:56
disk0:10-3-1xo.cnf 1212543 1212543 03/21/2011 04:43:40
disk0:Santana.cnf 3328569 3328569 06/15/2012 03:58:58
disk0:clr2-austin.cnf 1711986 1711986 08/02/2012 08:14:12
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
:'<,'>!sort
disk0:10-3-1xo.cnf 1212543 1212543 03/21/2011 04:43:40
disk0:20100727.cnf 3331572 3331572 07/27/2012 07:49:14
disk0:20110419.cnf 1240326 1240326 04/19/2012 10:46:02
disk0:clr2-austin.cnf 1711986 1711986 08/02/2012 08:14:12
disk0:clr2-austin-ping.cnf 1712159 1712159 08/07/2012 08:52:10
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
disk0:/incoming <DIR> 0 10/03/2007 16:11:26
disk0:moe1440-736-020111.cnf 1295880 1295880 02/01/2011 18:37:56
disk0:/outgoing <DIR> 0 10/03/2007 16:11:26
disk0:Santana.cnf 3328569 3328569 06/15/2012 03:58:58
disk0:xoBGP736.cnf 215140 215140 03/04/2010 12:24:46
:'<,'>!sort -k2nrb
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:20100727.cnf 3331572 3331572 07/27/2012 07:49:14
disk0:Santana.cnf 3328569 3328569 06/15/2012 03:58:58
disk0:clr2-austin-ping.cnf 1712159 1712159 08/07/2012 08:52:10
disk0:clr2-austin.cnf 1711986 1711986 08/02/2012 08:14:12
disk0:moe1440-736-020111.cnf 1295880 1295880 02/01/2011 18:37:56
disk0:20110419.cnf 1240326 1240326 04/19/2012 10:46:02
disk0:10-3-1xo.cnf 1212543 1212543 03/21/2011 04:43:40
disk0:xoBGP736.cnf 215140 215140 03/04/2010 12:24:46
disk0:/incoming <DIR> 0 10/03/2007 16:11:26
disk0:/outgoing <DIR> 0 10/03/2007 16:11:26
:'<,'>!sort -k4.7nrb -k4.1nbr -k4.4nbr -k5.1nbr -k5.4nbr -k5.7nbr
disk0:COC3_COC12_5_08_22_2012_22_43.dmp 24166561 24166561 08/22/2012 22:45:56
disk0:GE_FE_0_08_22_2012_06_42.dmp 31593741 31593741 08/22/2012 06:45:42
disk0:GE_FE_0_08_07_2012_10_02.dmp 28617646 28617646 08/07/2012 10:06:04
disk0:clr2-austin-ping.cnf 1712159 1712159 08/07/2012 08:52:10
disk0:clr2-austin.cnf 1711986 1711986 08/02/2012 08:14:12
disk0:20100727.cnf 3331572 3331572 07/27/2012 07:49:14
disk0:Santana.cnf 3328569 3328569 06/15/2012 03:58:58
disk0:20110419.cnf 1240326 1240326 04/19/2012 10:46:02
disk0:10-3-1xo.cnf 1212543 1212543 03/21/2011 04:43:40
disk0:moe1440-736-020111.cnf 1295880 1295880 02/01/2011 18:37:56
disk0:xoBGP736.cnf 215140 215140 03/04/2010 12:24:46
disk0:/incoming <DIR> 0 10/03/2007 16:11:26
disk0:/outgoing <DIR> 0 10/03/2007 16:11:26
2.3. external tool example: reuse your own programs/scripts
if you have some of your own well-tested programes/scripts and enjoyed using
them in the terminal, you can always re-use them from inside vim. The even
better thing is that the result will be displayed “on the fly”.
[This is more efficient than relying on traditional method that you
have to switch between your editor and terminals, and quite often you’ll need to
copy/paste between your work file and some temp files/etc. However, for better
integration with VIM, your script/program better support stdin/stdout “text
streams” as input/output flow, otherwise you might have to wrap them into that
looking :)]
- 26 ^MLSANCA-VFTTP-142#show version
| 27 Juniper Edge Routing Switch E320
| 28 Copyright (c) 1999-2012 Juniper Networks, Inc. All rights reserved.
| 29 System Release: e320_12-1-1p0-3.rel
| 30 Version: 12.1.1 patch-0.3 [BuildId 14015] (February 20, 2012 14:18)
| 31 Active Hotfixes:
| 32 e320_12-1-1p0-3_hf2228.hfx
| 33 e320_12-1-1p0-3_hf2235.hfx
| 34 e320_12-1-1p0-3_hf2236.hfx
| 35 e320_12-1-1p0-3_hf2331.hfx
| 36 e320_12-1-1p0-3_hf2421.hfx
| 37 e320_12-1-1p0-3_hf2383.hfx
| 38 System running for: 1378 days, 22 hours, 14 minutes, 54 seconds
| 39 (since MON DEC 01 2008 21:30:03 UTC)
| 40
| 41 slot state type admin spare running release slot uptime
| 42 ---- -------- ------- ------- ----- ------------------- --------------
| 43 0 standby LM-10 enabled spare e320_12-1-1p0-3.rel ---
| 44 1 online LM-4 enabled --- e320_12-1-1p0-3.rel 89d11h:20m:31s
| 45 2 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:28m:04s
| 46 3 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:24m:00s
| 47 4 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:28m:23s
| 48 5 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:20m:49s
| 49 6 standby SRP-320 enabled --- e320_12-1-1p0-3.rel ---
| 50 6 online SFM-320 enabled --- --- 89d11h:43m:50s
| 51 7 online SRP-320 enabled --- e320_12-1-1p0-3.rel 89d11h:43m:57s
| 52 7 online SFM-320 enabled --- --- 89d11h:43m:39s
| 53 8 online SFM-320 enabled --- --- 89d11h:43m:44s
| 54 9 online SFM-320 enabled --- --- 89d11h:43m:30s
| 55 10 online SFM-320 enabled --- --- 89d11h:43m:34s
| 56 11 online LM-10 enabled spare e320_12-1-1p0-3.rel 0d07h:29m:41s
| 57 12 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:23m:47s
| 58 13 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:20m:33s
| 59 14 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:26m:30s
| 60 15 inactive LM-10 enabled --- e320_12-1-1p0-3.rel ---
| 61 16 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:06m:50s
| 62
| 63 ^MLSANCA-VFTTP-142#
+ 64 +-- 74 lines: ^MLSANCA-VFTTP-142#show hardware
+ 138 +-- 30 lines: ^MLSANCA-VFTTP-142#show utili detailontrol-flow-detection count delta
+ 168 +--416 lines: ^MLSANCA-VFTTP-142#show log data
+ 584 +-- 7 lines: ^MLSANCA-VFTTP-142#show log data nv-file
+ 591 +-- 11 lines: ^MLSANCA-VFTTP-142#show subscribers summary slot
vzlogs/2012-0910-0848.log [utf-8] [jel] [26/9561,20] [0%] [0---------------------------
:'<,'>!showversion
- 26 ^MLSANCA-VFTTP-142#show version
| 27 Juniper Edge Routing Switch E320
| 28 Copyright (c) 1999-2012 Juniper Networks, Inc. All rights reserved.
| 29 System Release: e320_12-1-1p0-3.rel
| 30 Version: 12.1.1 patch-0.3 [BuildId 14015] (February 20, 2012 14:18)
| 31 Active Hotfixes:
| 32 e320_12-1-1p0-3_hf2228.hfx
| 33 e320_12-1-1p0-3_hf2235.hfx
| 34 e320_12-1-1p0-3_hf2236.hfx
| 35 e320_12-1-1p0-3_hf2331.hfx
| 36 e320_12-1-1p0-3_hf2421.hfx
| 37 e320_12-1-1p0-3_hf2383.hfx
| 38 System running for: 1378 days, 22 hours, 14 minutes, 54 seconds
| 39 (since MON DEC 01 2008 21:30:03 UTC)
| 40 Time this "show version" CLI command was executed: Tue Sep 11 00:44:57 2012
| 41
| 42 slot state type admin spare running release slot uptime
| 43 ---- -------- ------- ------- ----- ------------------- --------------
| 44 0 standby LM-10 enabled spare e320_12-1-1p0-3.rel ---
| 45 1 online LM-4 enabled --- e320_12-1-1p0-3.rel 89d11h:20m:31s since Wed Jun 13 13:24:26 2012
| 46 2 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:28m:04s since Wed Jun 13 13:16:53 2012
| 47 3 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:24m:00s since Wed Jun 13 13:20:57 2012
| 48 4 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:28m:23s since Wed Jun 13 13:16:34 2012
| 49 5 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:20m:49s since Wed Jun 13 13:24:08 2012
| 50 6 standby SRP-320 enabled --- e320_12-1-1p0-3.rel ---
| 51 6 online SFM-320 enabled --- --- 89d11h:43m:50s since Wed Jun 13 13:01:07 2012
| 52 7 online SRP-320 enabled --- e320_12-1-1p0-3.rel 89d11h:43m:57s since Wed Jun 13 13:01:00 2012
| 53 7 online SFM-320 enabled --- --- 89d11h:43m:39s since Wed Jun 13 13:01:18 2012
| 54 8 online SFM-320 enabled --- --- 89d11h:43m:44s since Wed Jun 13 13:01:13 2012
| 55 9 online SFM-320 enabled --- --- 89d11h:43m:30s since Wed Jun 13 13:01:27 2012
| 56 10 online SFM-320 enabled --- --- 89d11h:43m:34s since Wed Jun 13 13:01:23 2012
| 57 11 online LM-10 enabled spare e320_12-1-1p0-3.rel 0d07h:29m:41s since Mon Sep 10 17:15:16 2012
| 58 12 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:23m:47s since Wed Jun 13 13:21:10 2012
| 59 13 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:20m:33s since Wed Jun 13 13:24:24 2012
| 60 14 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:26m:30s since Wed Jun 13 13:18:27 2012
| 61 15 inactive LM-10 enabled --- e320_12-1-1p0-3.rel ---
| 62 16 online LM-10 enabled --- e320_12-1-1p0-3.rel 89d11h:06m:50s since Wed Jun 13 13:38:07 2012
| 63
| 64 ^MLSANCA-VFTTP-142#
+ 65 +-- 74 lines: ^MLSANCA-VFTTP-142#show hardwaretailontrol-flow-detection count delta
+ 139 +-- 30 lines: ^MLSANCA-VFTTP-142#show utili detail
+ 169 +--416 lines: ^MLSANCA-VFTTP-142#show log data nv-file
+ 585 +-- 7 lines: ^MLSANCA-VFTTP-142#show log data nv-fileary slot
+ 592 +-- 11 lines: ^MLSANCA-VFTTP-142#show subscribers summary slot
vzlogs/2012-0910-0848.log [utf-8,+] [jel] [26/9562,1] [0%] [0--------------------------------------------------
36 lines filtered
call the external "showversion" program, and apply the selected range of text as the stdin to the program | |
because the every line of “show version” output (line26-line62,total 36) was processed by the external program and was replaced by the result |
the “showversion” program is written by Jonathan with the original name: “realTimeGetterAllFromShowVersion”. Here we use it to domonstrate how to re-use the existing program that you took time to write/test, from within vim. so your/others effort/hard work won’t be wasted. |
3. vim folding:make huge file small (JTAC may like)
-
manual
-
better than nothing
-
use for temporary
-
no need modify(good)
-
disadvantage: Do not persist across file reload
-
-
indent
-
better
-
good for well-indented text (code in consistent indent style, or JUNOS config)
-
advantage: no need modify file content
-
-
marker
-
Markers in the text tell where folds start and end.
-
This allows you to precisely specify the folds.
-
-
expr
-
powerful
-
-
syntax
-
really powerful, but takes time and sharp learning curve to make it work
-
an example:
-
-
more to read:
:help foldmethod |fold-manual| manual Folds are created manually. |fold-indent| indent Lines with equal indent form a fold. |fold-expr| expr 'foldexpr' gives the fold level of a line. |fold-marker| marker Markers are used to specify folds. |fold-syntax| syntax Syntax highlighting items specify folds. |fold-diff| diff Fold text that is not changed. :help fold-manual :help fold-indent :help ...
3.1. folding: marker
[each + sign in the left column is ‘alive’, click it will toggle the folding; The sign will switch between a + and a - accordingly, and the ‘sub-fold’ under current fold appears when current fold got extended]
1
2 ## Last changed: 2011-10-19 16:23:32 UTC
3 version 10.4S6.6;
+ 4 +--1053 lines: groups
1057 apply-groups [ re0 re1 ALL-GE-INTERFACES-TRAPS ALL-XE-INTERFACES-TRAPS ALL-AE-INTERFACES-TRAPS ];
+ 1058 +-- 11 lines: dynamic-profiles
+ 1069 +--235 lines: system
- 1304 chassis {
| 1305 apply-groups CHASSIS-ALL-FPC_PIC-MAX_QUEUES;
|+1306 +--- 3 lines: redundancy
|+1309 +--- 3 lines: routing-engine
|+1312 +--- 5 lines: aggregated-devices
|+1317 +--- 7 lines: fpc 0
|+1324 +--- 7 lines: fpc 1
|+1331 +--- 3 lines: fpc 10
|+1334 +--- 3 lines: fpc 11
| 1337 network-services all-ip;
| 1338 }
+ 1339 +--1659 lines: interfaces
+ 2998 +-- 7 lines: forwarding-options
+ 3005 +-- 5 lines: event-options
+ 3010 +--124 lines: snmp
+ 3134 +--137 lines: routing-options
+ 3271 +--266 lines: protocols
+ 3537 +--836 lines: policy-options
+ 4373 +--963 lines: class-of-service
+ 5336 +--1298 lines: firewall
+ 6634 +-- 99 lines: access
+ 6733 +-- 90 lines: routing-instances
+ 6823 +-- 9 lines: services
6832 access-profile ACCESS_PROFILE-VZ_DHCPUSER;
+ 6833 +-- 26 lines: diameter
6859
3.2. folding: indentation
16 a
- 17 b
2 18 c
- 19 d
4 20 e
2 21 f
22 g
16 a
- 17 b
2 18 c
-+ 19 +----- 2 lines: d
2 21 f
22 g
16 a
-+ 17 +--- 5 lines: b
22 g
3.3. folding: indentation: JUNOSe/CISCO config file
[personally I prefer folding on mark than indentation in this case. Mark folding looks more ‘compact’ and hence ‘cleaner’, because the marker method includes the the ‘headers’ (e.g, ‘groups’) line while indentation method only folds the indented lines, excluding the headers]
1
2 ## Last changed: 2011-10-19 16:23:32 UTC
3 version 10.4S6.6;
4 groups {
+ 5 +--1051 lines: re0
1056 }
1057 apply-groups [ re0 re1 ALL-GE-INTERFACES-TRAPS ALL-XE-INTERFACES-TRAPS ALL-AE-INTERFACES-TRAPS ];
1058 dynamic-profiles {
+ 1059 +-- 9 lines: DYNAMIC_PROFILE-STATIC_INTERFACE
1068 }
1069 system {
+ 1070 +--233 lines: domain-name verizon-gni.net;
1303 }
1304 chassis {
+ 1305 +-- 33 lines: apply-groups CHASSIS-ALL-FPC_PIC-MAX_QUEUES;
1338 }
1339 interfaces {
+ 1340 +--1657 lines: ge-0/0/0
2997 }
2998 forwarding-options {
+ 2999 +-- 5 lines: family inet
3004 }
3005 event-options {
+ 3006 +-- 3 lines: event-script
3009 }
3010 snmp {
+ 3011 +--122 lines: location PRVDRIWA05W0550018A;
3133 }
3134 routing-options {
+ 3135 +--135 lines: nonstop-routing;
3270 }
3271 protocols {
+ 3272 +--264 lines: igmp
3536 }
3537 policy-options {
+ 3538 +--834 lines: prefix-list PREFIX-DUMMY
4372 }
4373 class-of-service {
+ 4374 +--961 lines: classifiers
5335 }
5336 firewall {
+ 5337 +--1296 lines: family inet
+ 5337 +--1296 lines: family inet
6633 }
6634 access {
+ 6635 +-- 97 lines: radius-server
6732 }
6733 routing-instances {
+ 6734 +-- 88 lines: vol-voip
6822 }
6823 services {
+ 6824 +-- 7 lines: radius-flow-tap
6831 }
6832 access-profile ACCESS_PROFILE-VZ_DHCPUSER;
6833 diameter {
+ 6834 +-- 24 lines: origin
6858 }
6859
6860 # vim:foldmarker={,}:foldmethod=marker:
~
mx/vz-mx-config.txt [utf-8] [conf] [6632/6860,1] [96%] [-------------------------------------------------------------------0---]
3.4. folding: syntax: JUNOSe config
[as near as I know, JUNOSe/cisco configuration file (or any other network devices in the current industry ) doesn’t look as well structured as JUNOS/JUNOS-like configurations, which makes the syntax fold for JUNOSe/cisco-like configuration files far more complex and less consistent-looking than JUNOS-like configuration files]
142 WASHDC-FTTP-02#show configuration
+ 143 +-- 7 lines: ! Configuration script being generated on TUE OCT 26 2010 16:38:52 UTC
+ 150 +-- 6 lines: boot config running-configuration
+ 156 +-- 6 lines: !
162 virtual-router default
163 virtual-router vol
164 !
+ 165 +-- 2 lines: ip vrf vol-voip
167 !
168 virtual-router analyzer
169 !
170 license b-ras Aepl1tCe54
+ 171 +-- 3 lines: aaa domain-map "noaccess-vzdhcpuser.com"
174 !
+ 175 +-- 3 lines: aaa domain-map noneden"
178 !
+ 179 +-- 3 lines: aaa domain-map "vzdhcpuser.com"
182 !
+ 183 +-- 3 lines: aaa domain-map "vzvoipuser.com"
186 !
+ 187 +-- 3 lines: aaa profile FTTPvzvoipuser.com"
190 !
191 license bfd "bidr$forw!detect"
192 hostname "WASHDC-FTTP-02"
+ 193 +-- 30 lines: aaa new-modelct"
+ 223 +-- 2 lines: ! -FTTP-02"
225 service password-encryption
226 baseline show-delta-counts
227 control-plane
228 !
+ 229 +-- 3 lines: controller sonet 5/0
232 !
+ 233 +-- 3 lines: controller sonet 5/1
236 !
+ 237 +-- 4 lines: controller sonet 5/2
241 !
+ 242 +-- 4 lines: controller sonet 5/3
246 !
+ 247 +-- 3 lines: controller sonet 8/0
3.5. folding: syntax: JUNOS logs
[6 vs. 6000 lines, the ratio depends on how long output the command line printed. in this case a ‘show config’ prints thousands of lines. actually to achive this effect, the long regex demonstrated earlier as an example was used to locate the command line itself as part of the work; folding on ‘syntax’ was created in a ‘syntax file’; and the syntax folding action was triggered on a ‘set filetype’ event, which, was either triggered by a manual vim ex command, or the vim automatic file type detection method …]
+-- 26 lines: lab@MX-FIOS-02-re0> show version
+-- 8 lines: lab@MX-FIOS-02-re0> show system uptime
+-- 11 lines: lab@MX-FIOS-02-re0> show system alarms
+--150 lines: lab@MX-FIOS-02-re0> show system software
+--113 lines: lab@MX-FIOS-02-re0> show configuration
+--5677 lines: lab@MX-FIOS-02-re0> show configuration | no-more
3.6. folding: syntax: JUNOSe logs
+ 36 +-- 38 lines: ^MWASHDC-VFTTP-95#show version
+ 74 +-- 74 lines: ^MWASHDC-VFTTP-95#show hardware
+ 148 +-- 30 lines: ^MWASHDC-VFTTP-95#show utili detail
+ 178 +-- 9 lines: ^MWASHDC-VFTTP-95#show log data
+ 187 +--580 lines: ^MWASHDC-VFTTP-95#show log data nv-file
+ 767 +-- 2 lines: ^MWASHDC-VFTTP-95#!
+ 769 +-- 23 lines: ^MWASHDC-VFTTP-95#show subscribers summary port
+ 792 +-- 28 lines: ^MWASHDC-VFTTP-95#show resource
+ 820 +-- 20 lines: ^MWASHDC-VFTTP-95#show issu
+ 840 +-- 9 lines: ^MWASHDC-VFTTP-95#show issu brief
+ 849 +-- 85 lines: ^MWASHDC-VFTTP-95#dir
+ 934 +-- 23 lines: ^MWASHDC-VFTTP-95#show redundancy history
+ 957 +-- 48 lines: ^MWASHDC-VFTTP-95#show redundancy history detail
+ 1005 +-- 12 lines: ^MWASHDC-VFTTP-95#show flash
+ 1017 +-- 88 lines: ^MWASHDC-VFTTP-95#show environment all
+ 1105 +-- 63 lines: ^MWASHDC-VFTTP-95#show version all
+ 1168 +--1742 lines: ^MWASHDC-VFTTP-95#show log data sev deb
+ 2910 +-- 2 lines: ^MWASHDC-VFTTP-95#show log data sev deb | inc arity
+ 2912 +--580 lines: ^MWASHDC-VFTTP-95#show log data nv-file sev deb
+ 3492 +-- 2 lines: ^MWASHDC-VFTTP-95#!
3.7. folding: syntax: linux command logs
ping@640g-laptop:~$
ping@640g-laptop:~$
+-- 2 lines: ping@640g-laptop:~$ pwd
+--100 lines: ping@640g-laptop:~$ ls
+-- 3 lines: ping@640g-laptop:~$ du -sh
+-- 27 lines: ping@640g-laptop:~$ df -h
+-- 4 lines: ping@640g-laptop:~$ less temp1.txt
+-- 50 lines: abc#show config
+-- 31 lines: ping@640g-laptop:~$ telnet 172.25.84.201
+-- 4 lines: lab@MX-FIOS-01-Re1> exit
+-- 31 lines: ping@640g-laptop:~$ cat temp.txt
+-- 2 lines: ping@640g-laptop:~$ rm temp.txt
~
~
~
mylogin.tcl - 10 [utf-8] [jel] [4/308,1] [1%] [-0----------------------
4. vim as file manager: netrw (windows explorer)
-
folder operation
-
files operation:cp,mv,delete
-
jumping back and forth
-
going up and down
-
bookmarks/browsing history
-
open files with associated applications: pdf, word, png, rmvb, etc.
-
etc
In VIM this is essentially done by the netrw plugin, which is now one of the VIM built-in plugins - it comes with VIM so no need to install the plugin anymore.
This plugin don’t need to be activated - it will just work by default.
4.1. advantage of vim as a FM
-
search file/folders fast
-
the same skill you learned about how to search text in a file!
-
all regex applys!
-
-
open/edit remote files/dirs directly from local machine (JTAC,JUNOS)
-
traditional way:
-
copy(download) remote file to local machine
(plus: ftp,http,scp,sftp,etc tools need to be explicitly involves) -
open/edit local copy, save to a local temp file
-
copy(upload) to remote place (ftp,http,scp,sftp tools involves)
-
-
with VIM:
-
open/edit remote file directly, save, done
[some may think this is not too much fancy in unix system - all unix-like system comes with a standard vi/vim installed. However, Think about how do you modify files in a remote system that supports SSH, but no fancy terminal-based editor installed- for example, you may want to edit some files in your iphone :p ]
-
-
-
open edit file from achives directly
-
traditional way:
-
extract to another temp folder
-
open/edit files from the temp folder, save
-
make a new achive
-
-
with VIM:
-
open/edit files from archieve , save, done
-
-
4.2. example:open local FS
" ============================================================================
" Netrw Directory Listing (netrw v144a)
" /home/ping/e-serials
" Sorted by name
" Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Hiding: ^\..*
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec
" ============================================================================
12-1-1/
SEL-coredump-shreboot/
e-serials-old/
erx-tools/
erxmai/
SFM_issues_and_logs_updated1.csv*
SFM_issues_and_logs_updated1.xls*
/data/backup/Juniper/e-serials [utf-8,-,RO] [netrw] [1/60,1] [1%]
4.3. example:open archive file: tarball
1 " tar.vim version v26
2 " Browsing tarfile /home/ping/Downloads/XML-Parser-2.40.tar.gz
3 " Select a file with cursor and press ENTER
4
5 XML-Parser-2.40
6 XML-Parser-2.40/Changes
7 XML-Parser-2.40/Makefile.PL
8 XML-Parser-2.40/MANIFEST
9 XML-Parser-2.40/META.yml
10 XML-Parser-2.40/Parser.pm
11 XML-Parser-2.40/README
12 XML-Parser-2.40/Expat
13 XML-Parser-2.40/Expat/encoding.h
14 XML-Parser-2.40/Expat/Expat.pm
15 XML-Parser-2.40/Expat/Expat.xs
16 XML-Parser-2.40/Expat/Makefile.PL
17 XML-Parser-2.40/Expat/typemap
18 XML-Parser-2.40/inc
19 XML-Parser-2.40/inc/Devel
20 XML-Parser-2.40/inc/Devel/CheckLib.pm
21 XML-Parser-2.40/Parser
22 XML-Parser-2.40/Parser/LWPExternEnt.pl
XML-Parser-2.40.tar.gz [utf-8,-,RO] [tar] [1/78,1] [1%] [0-------------]
move cursor here |
now move to line 13 and press <enter>, the file listed in line 13 “XML-Parser-2.40/encoding.h” will be opened in a second window:
13 XML-Parser-2.40/Expat/encoding.h
14 XML-Parser-2.40/Expat/Expat.pm
15 XML-Parser-2.40/Expat/Expat.xs
XML-Parser-2.40.tar.gz [utf-8,-,RO] [tar] [13/78,1] [16%] [0----]
1 /*****************************************************************
2 ** encoding.h
3 **
4 ** Copyright 1998 Clark Cooper
5 ** All rights reserved.
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the same terms as Perl itself.
9 */
10
11 #ifndef ENCODING_H
12 #define ENCODING_H 1
13
14 #define ENCMAP_MAGIC 0xfeebface
15
16 typedef struct prefixmap {
17 unsigned char min;
18 unsigned char len; /* 0 => 256 */
19 unsigned short bmap_start;
20 unsigned char ispfx[32];
21 unsigned char ischar[32];
22 } PrefixMap;
tarfile::XML-Parser-2.40/Expat/encoding.h [utf-8] [cpp] [1/91,1] [1%] [0--
original window that contains the file lists in the tar ball | |
new window with opened file
[the file that is just opened is the one that you pressed <return> when your cursor was on] |
4.4. example:open remote FS: JUNOS
[ftp is not the only option, vim support almost all protocols(fttp/scp/sftp/rcp/rsync/…)to retrieve remote FS info, see :help netrw for more info]
" ============================================================================
" Netrw Directory Listing (netrw v144a)
" ftp://lab@172.25.84.216//
" Sorted by name
" Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Hiding: ^\..*
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec
" ============================================================================
altconfig/
altroot/
bin/
boot/
config/
data/
dev/
etc/
kernel@/
lib64/
libexec/
mfs/
mnt/
modules/
opt/
packages/
proc/
root/
sbin/
staging@/
tmp/
usr/
var/
COPYRIGHT
~
~
~
~
*ftp://lab@172.25.84.216//* [utf-8,-,RO] [netrw] [30/32,1] [93%]
4.5. example:open remote FS :JUNOS: list view
" ============================================================================
" Netrw Directory Listing (netrw v144a)
" ftp://lab@172.25.84.216//
" Sorted by name
" Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Hiding: ^\..*
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec
" ============================================================================
altconfig/ dr-x------ 2 root wheel 512 Aug 24 2011
altroot/ dr-x------ 2 root wheel 512 Aug 24 2011
bin/ drwxr-xr-x 2 root wheel 512 Nov 16 2011
boot/ drwxr-xr-x 4 root wheel 512 Nov 16 2011
config/ drwxr-xr-x 6 root wheel 512 Jul 9 20:39
data/ dr-x------ 2 root wheel 512 Aug 24 2011
dev/ dr-xr-xr-x 3 root wheel 512 Jan 1 1970
etc/ drwxr-xr-x 11 root wheel 2048 Jul 9 20:39
lib64/ drwxr-xr-x 2 root wheel 512 Nov 16 2011
libexec/ drwxr-xr-x 2 root wheel 512 Nov 16 2011
mfs/ drwxr-xr-x 4 root wheel 512 Jul 8 19:29
mnt/ drwxr-xr-x 2 root wheel 512 Mar 12 2009
modules/ drwxr-xr-x 7 root wheel 512 Nov 16 2011
opt/ drwxr-xr-x 6 root wheel 512 Nov 16 2011
packages/ drwxr-xr-x 3 root wheel 2560 Nov 16 2011
proc/ dr-xr-xr-x 1 root wheel 0 Aug 26 12:40
root/ drwxr-xr-x 2 root wheel 512 Nov 22 2011
sbin/ drwxr-xr-x 3 root wheel 2048 Nov 16 2011
tmp/ drwxrwxrwt 3 root wheel 512 Aug 26 03:34
usr/ drwxr-xr-x 8 root wheel 512 Nov 16 2011
var/ drwxr-xr-x 31 root wheel 512 Jul 8 19:30
COPYRIGHT -rw-r--r-- 1 root wheel 6187 Aug 24 2011
kernel@ lrwxr-xr-x 1 root wheel 17 Nov 16 2011
staging@ lrwxrwxrwx 1 root wheel 8 Nov 16 2011
4.6. example:open remote FS directly: JUNOS: tree view
" ============================================================================
" Netrw Directory Listing (netrw v144a)
" ftp://lab@172.25.84.216//var/
" Sorted by name
" Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Hiding: ^\..*
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec
" ============================================================================
../
ftp://lab@172.25.84.216//var/
| account/
| at/
| backups/
| bin/
| crash/
| cron/
| db/
| empty/
| etc@/
| heimdal/
| home/
| jail/
| log/
| | client@/
| | ext/
| | flowc/
| | ggsn/
| | r1@/
| | smartd.trace*
| | appidd
| | aprobed
| | apsd
| | authd_profilelib
| | authd_sdb.log
| | authlib_jdhcpd_trace.log
| | authlib_jdhcpd_trace.log.0.gz
NetrwTreeListing 1 [utf-8,-,RO] [netrw] [1/178,1] [0%]
4.7. example:open archive file on remote FS "on the fly": JUNOS
[so yes there is no doubt vim also supports accessing local archives (in whatever known format) ‘on the fly’]
jdhcpd_sdb.log.1.gz 1 Jul 13 08:52:00 MX-FIOS-02-re0 newsyslog[22326]: logfile turned o
jdhcpd_sdb.log.2.gz 2 Jul 13 08:55:37 MX-FIOS-02-re0 fpc2 ICHIP(1)_REG_ERR:Non first c
jdhcpd_sdb.log.3.gz 3 Jul 13 08:55:37 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
jdhcpd_sdb.log.4.gz 4 Jul 13 08:59:38 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
jdhcpd_sdb.log.5.gz 5 Jul 13 09:03:40 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
jdhcpd_sdb.log.6.gz 6 Jul 13 09:07:41 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
jdhcpd_sdb.log.7.gz 7 Jul 13 09:11:42 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
jdhcpd_sdb.log.8.gz 8 Jul 13 09:15:43 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
ksyncd 9 Jul 13 09:19:44 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:first cell
ldp.trace 10 Jul 13 09:23:46 MX-FIOS-02-re0 fpc2 ICHIP(0)_REG_ERR:first cell
license 11 Jul 13 09:23:46 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
license_subs_trace.log 12 Jul 13 09:27:47 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
lmpd 13 Jul 13 09:31:48 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:first cell
lsp.stats 14 Jul 13 09:31:48 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
lsp.stats.0.gz 15 Jul 13 09:35:49 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
mastership 16 Jul 13 09:37:50 MX-FIOS-02-re0 fpc2 ICHIP(1)_REG_ERR:first cell
messages 17 Jul 13 09:39:50 MX-FIOS-02-re0 fpc2 ICHIP(0)_REG_ERR:first cell
messages.0.gz 18 Jul 13 09:43:52 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
messages.1.gz 19 Jul 13 09:47:53 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
messages.2.gz 20 Jul 13 09:51:54 MX-FIOS-02-re0 fpc2 ICHIP(1)_REG_ERR:first cell
messages.3.gz 21 Jul 13 09:51:54 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:first cell
messages.4.gz 22 Jul 13 09:55:55 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
messages.5.gz 23 Jul 13 09:59:56 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
messages.6.gz 24 Jul 13 10:07:59 MX-FIOS-02-re0 fpc2 ICHIP(1)_REG_ERR:first cell
messages.7.gz 25 Jul 13 10:07:59 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
messages.8.gz 26 Jul 13 10:20:02 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
messages.9.gz 27 Jul 13 10:24:04 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
mpls.trace 28 Jul 13 10:30:05 MX-FIOS-02-re0 fpc2 ICHIP(1)_REG_ERR:first cell
op-script.log 29 Jul 13 10:32:06 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pf 30 Jul 13 10:36:07 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pfed 31 Jul 13 10:40:08 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pfed_jdhcpd_trace.log 32 Jul 13 10:44:10 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pfed_trace.log 33 Jul 13 10:52:12 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pgmd 34 Jul 13 10:56:13 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
poweron_seq.log 35 Jul 13 11:04:16 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pppoed_era_jpppoed_era_36 Jul 13 11:08:17 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pppoed_era_jpppoed_era_37 Jul 13 11:12:18 MX-FIOS-02-re0 fpc2 ICHIP(0)_REG_ERR:first cell
pppoed_era_jpppoed_era_38 Jul 13 11:12:18 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pppoed_era_jpppoed_era_39 Jul 13 11:16:19 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
pppoed_era_jpppoed_era_40 Jul 13 11:20:20 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
rtspd 41 Jul 13 11:24:22 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
snapshot 42 Jul 13 11:28:23 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
utmp 43 Jul 13 11:32:24 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
wtmp 44 Jul 13 11:34:25 MX-FIOS-02-re0 fpc2 ICHIP(1)_REG_ERR:first cell
wtmp.0.gz 45 Jul 13 11:40:26 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
wtmp.1.gz 46 Jul 13 11:44:28 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
wtmp.2.gz 47 Jul 13 11:48:29 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
wtmp.3.gz 48 Jul 13 11:52:30 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
wtmp.4.gz 49 Jul 13 11:56:31 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:first cell
~ 50 Jul 13 11:56:31 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
~ 51 Jul 13 12:00:32 MX-FIOS-02-re0 fpc2 ICHIP(3)_REG_ERR:Non first c
ftp://lab@172.25.84.216//var/log/ [utf-8,RO] [78%]ftp://lab@172.25.84.216//var/log/messages.0.gz
:set nowrap
file currently viewed in the vertical window on the right |
5. vim as terminal emulator: Conqterm (secureCRT) (JTAC may like)
This is done by vim Conque Shell plugin. Once installed, it can be activated to start a bash terminal into a VIM buffer.
:ConqueTerm bash
5.1. Conqterm examples
ping@640g-laptop:~$
ping@640g-laptop:~$ pwd
/home/ping
ping@640g-laptop:~$
~
~
~
~
~
~
ping@640g-laptop: ~
-- INSERT --
vim "insert mode" indicator |
5960
5970 PRVDRI-VFTTP-32:vol#
5971 PRVDRI-VFTTP-32:vol#show ip int g12/1/5.1619
5972 GigabitEthernet12/1/5.1619 line protocol VlanSub is up, ip is up
5973 Network Protocols: IP
5974 Unnumbered Interface on loopback100
5975 ( IP address 74.103.242.1 )
5976 Operational MTU = 1500 Administrative MTU = 0
5977 Operational speed = 1000000000 Administrative speed = 0
5978 Discontinuity Time = 3959287872
5979 Router advertisement = disabled
5980 Proxy Arp = enabled
5981 ARP spoof checking = enabled
5982 Network Address Translation is disabled
5983 TCP MSS Adjustment = disabled
5984 SA-validation Enabled
5985 Administrative debounce-time = disabled
5986 Operational debounce-time = disabled
......
6068 traffic-class RT-VIDEO
6069 mark 128 mask 224
6070 PRVDRI-VFTTP-32:vol#
Verizon SSH Jumpstation - PRVDRI-VFTTP-32
-- INSERT --
line number | |
router (ERX) command line typed in | |
router (ERX) command line output captures | |
snipped - original output is long | |
vim "insert mode" indicator - we ARE in an editor, no doubt! |
5.2. terminal emulator:list of cool features
-
pattern search ,jumping using same skills as if in normal text file
-
syntax highlight
-
(syntax) fold
-
multi-tab (like secureCRT)
-
split, multi page, etc
-
suspend/resume anytime as will
-
save logs
-
etc…
6. vim as free hand drawing tool: drawit (paint,visio,word)(JTAC may like)
6.1. free hand tools considerations
-
JTAC sometimes need draw ascii graph:
-
network topology (mostly)
-
flow chart (occasionally)
-
-
available tools overview:
-
notepad is only good at horizontal lines, try it with vertical lines
-
paint is lightweight, but … anyone use that?
-
word/visio is standard/powerful/… but heavy & expensive
-
heavy in the sense like "overkills" for simple tasks
-
expensive not in sense of price, more in sense of time
-
UltraEdit and others might be nice, but try it with a MPLSVPN topo
-
-
ascii art vs. binary tools:
-
ascii art is always my first choice whenever possible:
-
small/portable/easy to maintain,
-
still cool/good enough to demonstrate the issue
-
-
small: only several K or within a hundred of Bytes
-
clear: arrow, signs, letters,numbers are always enough to demonstrate
-
portable: 100% green, no need to install any fancy software
-
maintain: the cool thing is you can just write topology directly into configs/code!
-
There are a couple of plugins available to draw ascii-arts, my personal favorite is drawit.
6.2. example:draw a "decent-looking" MPLS-VPN topology, in 2 minutes
[I finished it in this vim presentation within 1.5 min I guess :) ]
-
4 P backbone
-
2 PE
-
2 CE
-
lines/marks/rectangle/eclipse (for better readability)
6.3. example:a more complicated topology
+-----------------+ *************** *****************
|MX2 | ****** (AS65222) ****** ******lo0 |(AS65020) ******
| | ** (130.130/16) ** *** (area 2)|(220.220/16) ***
+-+-+---+-+---+-+-+ ** +-----+(InetRoutes) ** ** +--+--+ **
| | | | | | * |t1 |(131.131/16) * * |c2 | *
| | | | | | ** |(r8) |(132/16) ** ** |(r9) | **
+-+ +-+ +-+ ** +--+--+(133/25) ** *** +-++--+ ***
xe-1/3/2 ****** |(em1) ****** (em2.600)||(em2.1 ) ******
xe-1/3/3 *************** .2 ***||************
xe-9/3/0 | 192.168.16.0/24 ||
xe-9/3/1 | (OSPF/l2vpn)..||..........
|(em2.300) . |+-+ .
..............................................|(172.16.0.12/30) .(em1.600)| | (172.16.0.8/30)
. (agg 10/16) |(fe0/0/2) . +++ | (fe0/1/3)
. <========= .13|=========> .(c1-c2-l2)| | | (em1.1 )
(fe0/0/0)+-----+(em1) (em2) +--+--+(em2) . (em1) ++-+-++ .
| . .1 |r1 |(fe0/0/1) L1 (fe0/0/0) |r3 |(fe0/0/3) L2,L1 pass.(fe0/1/1) |r6:PE| .
+--.----+6.1 +-------------------------------+3.3 +--------------------.------------+9.6 |.2 .
| (em1)+--+--+ .14 (10.0.4.12/30) .13 +--+--+ .14 (10.0.2.12/30) .13 )+-----+ (fe0/1/2)
| . | \(em1) (em2)/ | \-.2 . -/.5 \-(em1)
| (fe0/0/2)|.5 -(fe0/0/3) (fe0/0/1)-/ | \(at0/1/0) . /(fe0/1/0) \- .
| . (em1)| \.18 /.1 |.5 . \(em2) .(10.0.8.4/30) (em1) \-(10.0.8.0)
| . | \ / |(em2) \- (10.0.2.0/30) -/ <=========== \-(v61)
| . | \- -/ |(so0/2/0)\L1 pass. /L1(rip to ISISL1/2). \-passive L1
| . | \L1 L1/ | . \-L2 . -/ ===========> . \-
| . 10| \ / | . \(at0/2/1) / (default) . \- |192
| . .| \- -/ |10 . \(em1) /.6 . \- (fe0/0/0) |.
| . 0| \ /(10.0.4.0) |. . .\-.1 -/(fe0/0/0) . \- |168
| . .| \ / |0 . . +-----+ (em2) . .1 \-----+ |.
-----+ . 4|L1 \- -/ L2|. . IS ext L1 |r5 |.6 .<========= |data | |0~3
| . .| / |2 . <======== |3.5 | .(rip route)|centr+---+/
| . 4| / \ |. . to L2. +-----+.9 . .13 ------+ |24
| . /| -/ \- |4 . . /.9 \(fe0/1/0) . -/ (r11) |
| . 30| / \(10.0.4.16) |/ . -/(em2) \- . -/(fe-0/0/1) |
| . | / \ |30 . /(so-0/1/0) \ . -/ (em1) |
| . | -/ \- | . / . \L1 (default) . /
| . | / \(fe0/0/2) |(so0/1/0) /L2 . \ ===========> . -/passive L1
| . | / \ |(em1) -/L1 pass. \- (rip to ISIS) .-/
| . | -/ \- | . /(10.0.2.8/30) \ <=========== / (v71)
| . (em2)|.6 / \ | . / (10.0.8.8/30)\(fe0/3/1) -/(10.0.8.12/30)
| (fe0/0/3)| /(em1) (em2) \.17 |.6 -/(em1) . \(em2) -/(em2)
| . | -/(fe-0/0/2) \- | /(so-0/1/1) . \.10 -/(fe-0/3/0)
| . +--+--+.2 +--+--+ .10 . (em2) +-----+ .14 .
| . .2 |r2 | (em2) (10.0.4.8/30) (em1) |r4:PE|(fe0/0/3)(em1) .(fe-0/3/3) |r7:PE| .
+-------+6.2 +-------------------------------+3.4 +-.-------------------.-----------+9.7 | .
| (em2)+-----+ (fe-0/0/1).10 (fe-0/0/1).9++--+++ ..18 (10.0.2.16/30). .17 ++---++ .
(fe0/0/0) (10.0.6.2) (c1-c2-l2)| | \ L2,L1 pass . / |c1 | .
10.0.5/24. <======> +-++ \ . / +---+ .
. (agg 10/16) +----\\(fe-0/0/0) . /(fe-0/3/2) .
....................................................\\(em3.1 ) . /(em2.70 ) .
(em3.600)\\.5 ./.1 .
(192.168.16.0/24)\\(172.16.0.4/30) /. .
(OSPF/L2vpn)\\ / ..................
\\ / (172.16.0.0/30)
\\ (OSPF AREA 0) / EBGP
(em4.600)\\(em4.1) /
*\\**************
****** \\ / ******
**** \\ / ****
* .2 \\.6 /.2 *
** +-----+ **
* |c1 | *
** +(r10)+ **
* +-----\ *
**** (AS65010) \(area 1) ****
****** (200.200/16)\ ******
em1:xe-1/3/2 <---loopback-----> em2:xe-1/3/3 *****************
em3:xe-9/3/0 <---loopback-----> em4:xe-9/3/1
Multi-level IS-IS, Areas 0001 and 0002 with ISO NET based on router number. lo0 address of r3 and r4 not injected into Area 0001 to ensure optimal forwarding between 10.0.3.3 and 10.0.3.4. Passive setting on r5’s core interfaces for optimal Area 0002-to-core routing. No authentication or route summarization. Routing policy at r5 to leak L1 externals (DC routes) to L2. Redistribution of static default route to data center from both r6 and r7. Redistribution of 192.168.0/24 through 192.168.3/24 routes from RIP into IS-IS by both r6 and r7. All adjacencies are up, reachability problem discovered at r1 and r2 caused by local aggregate definition. Corrected through IBGP policy to effect 10.0/16 route advertisement from r3 and r4 to r1 and r2; removed local aggregate from r1 and r2. Suboptimal routing detected at the data center and at r1/r2 for some locations. This is the result of random nexthop choice for data center’s default, and the result of r1 and r2’s preference for r3’s RID over r4 with regard to the 10.0/16 route. This is considered normal behavior, so no corrective actions are taken. |
7. vim as a doc browser: txtbrowser, Man
7.1. spec browser
" Press <F1> to display help text 1
2
- rfc2328.txt (/Dropbox/temp-transfer) 3
|- content 4
|| 1. Introduction 5 Network Working Group J. Moy
|| 2. The Link-state Database: organi> 6 Request for Comments: 2328 Ascend Communications, Inc.
|| 3. Splitting the AS into Areas 7 STD: 54 April 1998
|| 4. Functional Summary 8 Obsoletes: 2178
|| 5. Protocol Data Structures 9 Category: Standards Track
|| 6. The Area Data Structure 10
|| 7. Bringing Up Adjacencies 11
|| 8. Protocol Packet Processing 12 OSPF Version 2
|| 9. The Interface Data Structure 13
|| 10. The Neighbor Data Structure 14
|| 11. The Routing Table Structure 15 Status of this Memo
|| 12. Link State Advertisements (LSA> 16
|| 13. The Flooding Procedure 17 This document specifies an Internet standards track protocol for the
|| 14. Aging The Link State Database 18 Internet community, and requests discussion and suggestions for
|| 15. Virtual Links 19 improvements. Please refer to the current edition of the "Internet
|| 16. Calculation of the routing tab> 20 Official Protocol Standards" (STD 1) for the standardization state
| 21 and status of this protocol. Distribution of this memo is
|- figures 22 unlimited.
|| Figure 1a: Network map components 23
|| Figure 1b illustrates the link-stat> 24 Copyright Notice
|| Figure 1b: Network map components 25
|| Figure 2 shows a sample map of an A> 26 Copyright (C) The Internet Society (1998). All Rights Reserved.
|| Figure 2: A sample Autonomous System 27
|| Figure 3: The resulting directed gr> 28 Abstract
|| Figure 4: Individual link state com> 29
|| Figure 5. 30 This memo documents version 2 of the OSPF protocol. OSPF is a
|| Figure 5: The SPF tree for Router R> 31 link-state routing protocol. It is designed to be run internal to a
|| Figure 6 shows a sample area config> 32 single Autonomous System. Each OSPF router maintains an identical
|| Figure 7 shows the resulting link-s> 33 database describing the Autonomous System's topology. From this
|| Figure 7 by the dashed stub routes.> 34 database, a routing table is calculated by constructing a shortest-
|| Figure 6: A sample OSPF area config> 35 path tree.
|| Figure 7: Area 1's Database. 36
|| Figure 8: The backbone's database. 37 OSPF recalculates routes quickly in the face of topological changes,
|| Figure 9 shows the collection of da> 38 utilizing a minimum of routing protocol traffic. OSPF provides
|| Figure 9: Router RT10's Data struct> 39 support for equal-cost multipath. An area routing capability is
|| Figure 10: The graph of adjacencies 40 provided, enabling an additional level of routing protection and a
|| Figure 11 shows the graph of interf> 41 reduction in routing protocol traffic. In addition, all OSPF
|| Figure 11: Interface State changes 42 routing protocol exchanges are authenticated.
|| Figure 12: Neighbor state changes (> 43
|| Figure 13: Neighbor state changes (> 44 The differences between this memo and RFC 2178 are explained in
|| Figure 14 shows an example of an ad> 45 Appendix G. All differences are backward-compatible in nature.
|| Figure 14: An adjacency bring-up ex> 46
|| Figure 15: Area 1 with IP addresses> 47
|| Figure 16: Forwarding address examp> 48
|| Figure 17: Routing through transit > 49
|| Figure 18: Usage of the Authenticat> 50 Moy Standards Track [Page 1]
| 51 ^L
|- tables 52 RFC 2328 OSPF Version 2 April 1998
|| Table 2: The portion of Router RT6'> 53
|| Table 3: The portion of Router RT6'> 54
|| Table 4. These summaries show whic> 55 Implementations of this memo and of RFCs 2178, 1583, and 1247 will
|| Table 4: Networks advertised to the> 56 interoperate.
|| Table 5: Backbone distances calcula> 57
__Tag_List__ [utf-8,-] [taglist] [3/86,1] > Dropbox/temp-transfer/rfc2328.txt [utf-8] [txt] [4/12201,1] [0%] [0---
7.2. man page browser
VIM(1) VIM(1)
NAME
vim - Vi IMproved, a programmers text editor
SYNOPSIS
vim [options] [file ..]
vim [options] -
vim [options] -t tag
vim [options] -q [errorfile]
ex
view
gvim gview evim eview
rvim rview rgvim rgview
DESCRIPTION
Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.
There are a lot of enhancements above Vi: multi level undo, multi windows and buffers, syntax highlighting, command line editing, filename completion, on-line help, visual selection, etc..
See ":help vi_diff.txt" for a summary of the differences between Vim and Vi.
While running Vim a lot of help can be obtained from the on-line help system, with the ":help" command. See the ON-LINE HELP section below.
Most often Vim is started to edit a single file with the command
vim file
......
Script to detect the type of a file by its contents. See ":help 'filetype'".
/usr/share/vim/vim73/print/*.ps
Files used for PostScript printing.
For recent info read the VIM home page:
<URL:http://www.vim.org/>
SEE ALSO
vimtutor(1)
move cursor on top of any places in the “vimtutor” command under the man page “SEE ALSO” section, and press ctrl-], vim will take you to the man page of that new command under current cursor. a ctrl-o will jump back to ‘man vim’ again.
1] D/t/rfc2328.txt [2] /h/p/vimtutor
1 VIMTUTOR(1)
2
3
4
5 NAME
6 vimtutor - the Vim tutor
7
8 SYNOPSIS
9 vimtutor [-g] [language]
10
11 DESCRIPTION
12 Vimtutor starts the Vim tutor. It copies the tutor file first, so that it can be modified without changing the original file.
13
14 The Vimtutor is useful for people that want to learn their first Vim commands.
15
16 The optional argument -g starts vimtutor with gvim rather than vim, if the GUI version of vim is available, or falls back to Vim if gvim is not found.
17
18 The optional [language] argument is the two-letter name of a language, like "it" or "es". If the [language] argument is missing, the language of the current locale will be used. If a
19 tutor in this language is available, it will be used. Otherwise the English version will be used.
20
21 Vim is always started in Vi compatible mode.
22
23 FILES
24 /usr/share/vim/vim73/tutor/tutor[.language]
25 The Vimtutor text file(s).
26
27 /usr/share/vim/vim73/tutor/tutor.vim
28 The Vim script used to copy the Vimtutor text file.
29
30 AUTHOR
31 The Vimtutor was originally written for Vi by Michael C. Pierce and Robert K. Ware, Colorado School of Mines using ideas supplied by Charles Smith, Colorado State University. E-mail:
32 bware@mines.colorado.edu.
33 It was modified for Vim by Bram Moolenaar. For the names of the translators see the tutor files.
34
35 SEE ALSO
36 vim(1)
8. vim as IDE: ctag (elips,visual studio?) (DE may like, not for JTAC)
8.1. extra power as an IDE
-
realtime syntax hi
-
industry "standard" source code browser :
-
ctag,
-
cscope
-
-
vimdiff
-
web develop
-
a lot more …
8.2. code browser:taglist
" Press <F1> to display he> 1 /* vi:set ts=8 sts=4 sw=4:
2 *
- gvimext.h (/home/ping/temp> 3 * VIM - Vi IMproved by Bram Moolenaar
|- macro 4 *
|| AFX_STDAFX_H__3389658B> 5 * Do ":help uganda" in Vim to read copying and usage conditions.
|| STRICT 6 * Do ":help credits" in Vim to see a list of people who contributed.
|| INC_OLE2 7 * See README.txt for an overview of the Vim source code.
|| _CRT_SECURE_NO_DEPRECA> 8 */
|| _CRT_NONSTDC_NO_DEPREC> 9
|| UINT_PTR 10 /*
|| UINT_PTR 11 * getchar.c
|| ResultFromShort 12 *
|| INITGUID 13 * functions related with getting a character from the user/mapping/redo/...
|| MAX_HWND 14 *
| 15 * manipulations with redo buffer and stuff buffer
|- typedef 16 * mappings and abbreviations
|| LPCSHELLEXTCLASSFACTORY 17 */
|| LPCSHELLEXT 18
| 19 #include "vim.h"
|- class 20
|| CShellExtClassFactory 21 /*
|| CShellExt 22 * These buffers are used for storing:
23 * - stuffed characters: A command that is translated into another command.
- gvimext.cpp (/home/ping/te> 24 * - redo characters: will redo the last change.
|- variable 25 * - recorded characters: for the "q" command.
|| fmte 26 *
|| medium 27 * The bytes are stored like in the typeahead buffer:
|| hres 28 * - K_SPECIAL introduces a special key (two more bytes follow). A literal
|| cbFiles 29 * K_SPECIAL is stored as K_SPECIAL KS_SPECIAL KE_FILLER.
|| oldenv 30 * - CSI introduces a GUI termcap code (also when gui.in_use is FALSE,
...snipped...
|- function 48 #endif
|| getGvimName 49 static struct buffheader recordbuff = , NULL, 0, 0};
|| getGvimNameW 50
|| getRuntimeDir 51 static int typeahead_char = 0; /* typeahead char that's not flushed */
|| dyn_libintl_init 52
|| dyn_libintl_end 53 /*
|| null_libintl_gettext 54 * when block_redo is TRUE redo buffer will not be changed
|| null_libintl_bindtextd> 55 * used by edit() to repeat insertions and 'V' command for redoing
|| null_libintl_textdomain 56 */
__Tag_List__ [utf-8,-] [tagli> src/getchar.c [utf-8] [c] [1/5267,26] [0%] [-------------------------------------------------------------------------------------------------------------------------0->
8.3. diff tool:vimdiff
1 *^H ^H********** - 1 *^H ^H**********
2 ^MPassword: ^C -----------------------------------------
3 % Access denied 2 % Access denied
4 ^MTAMPFL-VFTTP-117> 3 ^MTAMPFL-VFTTP-117>
5 ^MTAMPFL-VFTTP-117> 4 ^MTAMPFL-VFTTP-117>
6 ^MTAMPFL-VFTTP-117> 5 ^MTAMPFL-VFTTP-117>
7 ^MTAMPFL-VFTTP-117> 6 ^MTAMPFL-VFTTP-117>
8 ^MTAMPFL-VFTTP-117> 7 ^MTAMPFL-VFTTP-117>
+ 9 +--1986 lines: ^MTAMPFL-VFTTP-117>rnet (Gigabit> + 8 +--1986 lines: ^MTAMPFL-VFTTP-117>rnet (>
1995 DEBUG 01/27/2012 10:57:06 UTC ethernet: Etherne> 1994 DEBUG 01/27/2012 10:57:06 UTC ethernet: >
1996 DEBUG 01/27/2012 13:24:23 UTC ethernet (Gigabit> 1995 DEBUG 01/27/2012 13:24:23 UTC ethernet (>
1997 DEBUG 01/27/2012 13:24:29 UTC ethernet: Etherne> 1996 DEBUG 01/27/2012 13:24:29 UTC ethernet: >
1998 DEBUG 01/27/2012 13:42:56 UTC ethernet (Gigabit> 1997 DEBUG 01/27/2012 13:42:56 UTC ethernet (>
1999 DEBUG 01/27/2012 13:43:02 UTC ethernet: Etherne> 1998 DEBUG 01/27/2012 13:43:02 UTC ethernet: >
2000 DEBUG 01/27/2012 15:27:42 UTC ethernet (Gigabit> 1999 DEBUG 01/27/2012 15:27:42 UTC ethernet (>
2001 DEBUG 01/27/2012 15:27:48 UTC ethernet: Etherne> -----------------------------------------
2002 DEBUG 01/27/2012 15:29:00 UTC ethernet (Gigabit> 2000 DEBUG 01/27/2012 15:29:00 UTC ethernet (>
2003 DEBUG 01/27/2012 15:29:05 UTC ethernet: Etherne> 2001 DEBUG 01/27/2012 15:29:05 UTC ethernet: >
2004 DEBUG 01/27/2012 15:29:35 UTC ethernet (Gigabit> 2002 DEBUG 01/27/2012 15:29:35 UTC ethernet (>
2005 DEBUG 01/27/2012 15:29:41 UTC ethernet: Etherne> 2003 DEBUG 01/27/2012 15:29:41 UTC ethernet: >
2006 DEBUG 01/27/2012 15:42:05 UTC ethernet (Gigabit> 2004 DEBUG 01/27/2012 15:42:05 UTC ethernet (>
2007 DEBUG 01/27/2012 15:42:11 UTC ethernet: Etherne> 2005 DEBUG 01/27/2012 15:42:11 UTC ethernet: >
+ 2008 +--3565 lines: DEBUG 01/27/2012 16:54:18 UTC eth + 2006 +--3565 lines: DEBUG 01/27/2012 16:54:18
5573 Dropped exceeded packets 0, bytes 0 5571 Dropped exceeded packets 0, bytes 0
5574 5572
5575 ^MTAMPFL-VFTTP-117:vol# ^H ^H ^H ^H ^H ^H ^H ^H> 5573 ^MTAMPFL-VFTTP-117:vol# ^H ^H ^H ^H ^H ^>
5576 ^MTAMPFL-VFTTP-117:vol# 5574 ^MTAMPFL-VFTTP-117:vol#
5577 ^MTAMPFL-VFTTP-117:vol#show int g12/1/7^G^H^H^H> 5575 ^MTAMPFL-VFTTP-117:vol#show int g12/1/7^>
5578 ^MTAMPFL-VFTTP-117:vol# ^H ^H ^H ^H ^H ^H ^H ^H> 5576 ^MTAMPFL-VFTTP-117:vol# ^H ^H ^H ^H ^H ^>
vzlogs/2012-0201-0769.log [utf-8] [jel] [1/5580,3] [0%> [No Name] [utf-8,+] [1/5578,1] [0%] [0->
8.4. web develop:vimwiki (webadmin may like)
super quick web developing tool, need a whole seperate presentation to demonstrate the power. not much useful for JTAC.
8.5. git/vcs integration
super version management tools, need a whole seperate presentation to demonstrate the power.
9. vim programming language: vimL
-
vim is programmable - vimL programming language
-
combine all existing command/operations into action sequence
9.1. vimL example:clean a log file
-
remove special control characters
[e.g, ascii code 8 or 9,representing BS (Backspace) or HT(Horizontal Tab), see unix man page man ascii for more detail]
-
‘CR’ (unix version of return)
-
-
"translate" control characters back into the control
-
turn the “backspace” in the log into "deleting 1 characters before it"
Example 24. vimLcommand! Log2AsciidocClean call Log2AsciidocClean() function! Log2AsciidocClean() "clean the file "remove some special CH, like ^M :%s#\r\|\s\=\(^G\|^M\)## endfunc
Although the “special” characters listed visually (represented by a literal ^
andG
) in this example does not looks “special”, they are printed here only for the visibility purpose. The character itself (e.g. you pressed a BACKSPACE key) is not visible in the real file. In vim there is a way to generate this kind of non-visible character: by pressing a “ctrl-V” (make itVisual
) and another “ctrl-M”, a “Backspace”,repsensented in the text as a^M
(ascii code 0x07) is inserted. A^M
(\r
) can be generated the same way.execute new created command:Log2AsciidocClean
-
+ 8441 +-- 15 lines: ^MDLLSTX-VFTTP-71:vol#show log data nv-file
+ 8456 +-- 9 lines: ^MDLLSTX-VFTTP-71:vol# ^H ^H ^H ^H ^H ^H ^H ^H ^H ^H ^HH
+ 8465 +-- 2 lines: ^MDLLSTX-VFTTP-71:vol#term^H ^H^H ^H^H ^H^H ^H
8467 ^MDLLSTX-VFTTP-71:vol#show user det
+ 8468 +-- 13 lines: ^MDLLSTX-VFTTP-71:vol#show user detail
8481 ^MDLLSTX-VFTTP-71:vol#show resou
+ 8482 +-- 32 lines: ^MDLLSTX-VFTTP-71:vol#show resource
+ 8555 +-- 2 lines: ^MDLLSTX-VFTTP-71:vol# ^H ^H
+ 8560 +-- 73 lines: ^MDLLSTX-VFTTP-71:vol#shw hardw^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H^H ^How hard
+ 8633 +-- 3 lines: ^MDLLSTX-VFTTP-71:vol# ^H ^H
8636 ^MDLLSTX-VFTTP-71:vol#term lenth ^H ^H^H ^H^H ^Hgth 0
+ 8637 +-- 2 lines: ^MDLLSTX-VFTTP-71:vol#term with 200^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H^H ^Hidth 200
+ 8639 +-- 38 lines: ^MDLLSTX-VFTTP-71:vol#show vesion^H ^H^H ^H^H ^H^H ^Hrsion
+ 8677 +-- 32 lines: ^MDLLSTX-VFTTP-71:vol#show resurse^H ^H^H ^H^H ^H^H ^H^H ^Hsource^H ^He ^H ^H
+ 8441 +-- 26 lines: DLLSTX-VFTTP-71:vol#show log data nv-file
8467 DLLSTX-VFTTP-71:vol#show user det
+ 8468 +-- 13 lines: DLLSTX-VFTTP-71:vol#show user detail
8481 DLLSTX-VFTTP-71:vol#show resou
+ 8482 +-- 32 lines: DLLSTX-VFTTP-71:vol#show resource
+ 8557 +-- 3 lines: DLLSTX-VFTTP-71:vol#shw hardw
+ 8560 +-- 76 lines: DLLSTX-VFTTP-71:vol#show hard
8636 DLLSTX-VFTTP-71:vol#term length 0
+ 8637 +-- 2 lines: DLLSTX-VFTTP-71:vol#term width 200
+ 8639 +-- 38 lines: DLLSTX-VFTTP-71:vol#show version
+ 8677 +-- 32 lines: DLLSTX-VFTTP-71:vol#show resource
9.2. vimL example:indent command output
-
turn a huge log file into a structured HTML file
-
you can then share the web link instead of bothering attachment/go to a server/passwd/etc..
-
all can be done with a few keystrokes in a second!
end of the command output
[there is a longer story behind this. Following code was partially captured from a sequence of code groups that each will fulfill a partial work to proceed one step toward my target: turning a pure text log file to the source of a structured HTML file. One handy feature of the generated HTML will be the presence of “go back to TOC” label following each command line, which is done by inserting a “<<top>>” mark right after each command line (done by a vim substitution regex).]
command! Log2AsciidocIndent call Log2AsciidocIndent()
function! Log2AsciidocIndent()
"indent between <<top>> and next command
"skip the 1st comand
":execute "normal! gg" . '/^\(\S\S\+.\{0,40}\S#\s*[^:]\+\|slot \d\d\=->\S\+.*\|->.*\|\*-\*-\*-\*-\*-\)' . "\<cr>" ."j"
"this doesn't work well, always report some errors
":g/<<top>>/+1,/^== \(\S\S\+.\{0,40}\S#\s*[^:^H^G]\+\|slot \d\d\=->\S\+\|->.\+\|\*-\*-\*-\*-\*-\)/-1 >
"testing this...
let maxline = line("$")
"start from top line
normal! gg
while line(".") <= maxline
"(from where we left) search <<top>>, mark the line right below it as x
execute "normal! /top\<cr>"
echom "match 1 found #" . line(".")
normal! j0mx
echom "mark x is #" . line("'x")
"(from 1st mark found), look for cmd line, mark the line right above it as y
"execute "normal!" . ' /^== \(\S\S\+.\{0,40}\S#\s*[^:]\+\|slot \d\d\=->\S\+.*\|->.*\|\*-\*-\*-\*-\*-\)' . "\<cr>"
execute "normal!" . " /^== \<cr>"
echom "match 2 found #" . line(".")
normal! k0my
echom "mark y is #" . line("'y")
"fold the output capture
execute "'x,'y>"
"procede from the line after the command line
normal! jj0
"check current line#
echom "new line to proceed after folding is " . line('.')
"break if reach bottom
if line(".") >= maxline
echom "reaching end of file"
break
endif
if line("'x") == line("'y")
echom "x,y marks stays the same,sth wrong or reaching end of file"
normal! G0my
execute "'x,'y>"
break
endif
echom "our position of this round is ".line(".")
endwhile
endfunc
with the above vimL code, a long text log file can be converted to a
not-so-bad-looking web page, with a Table Of Content linking to each of the
command executed.
[with my current VIM script(I may change/enhance it from time to time),
I type following newly created vim command to get the job done:
:Log2AsciidocClean
:Log2AsciidocTop
:Log2AsciidocIndent
:Log2AsciidocList
:Asciidoc2Html
each of the above “user command” do one different job in the processing flow.
These can be further simplified into one VIM user command like:
:Log2Asciidoc
But personally I prefer to disassemble it to different processing stage, so I can review
the partial result just in case something went wrong.
]
original
text log file: 2012-0619-0971.log
⇒
converted log file in HTML page: 2012-0619-0971.html
10. appendix
10.1. motion commands
hjkl,gk|a-up,gj|a-dn #left down up right,up,down in long line(useful!)
map j gj #j means gj,for long lines under set nowrap
map k gk
imap <UP> <ESC>gki #same for insert mode
imap <DOWN> <ESC>gji
gf #go open the file under cursor
C-f,C-b,C-d,C-u #page down/up, half page down/up
C-Y,C-E #scroll down,up a line
zh,zl,zH,zL #scroll left,right a column,half screen
z<CR>|zt,z.|zz,z-|zb #"drag" curr line to top,center,bottom
ze,zs right|end,left|start
H,M,L,g0,g^,gm,g$ #go top,mid,tail,left,left-non-blank,mid,right of curr screen
#keep column info change|unchange
:set scrolloff=3 #add padding to margin when scrolling
:set scrolljump=3 #scroll 3 lines when reach the margin of screen
;set sidescroll=3 #same, but scroll horizontally
G,gg,25G|25gg|:25 #jump to end,begin of the file,show current location
#jump to line 25
60% #go to 60% of the full text
0|HOME,$,3$,^|_,+,- #go to beginning,end of curr line,3 lines
#1st non-bl CH of curr,next,prev line
ga #display the ascii num for curr CH
g C-g #display curr poistion,or selected text stats
9go,:goto 9 #go to #9 Ch in the file
w/W,e/E,b/B,ge #to head,end of curr w/W,head,end of prev w/W
w normal word
W space sperated
2w,3e,^,0/HOME,$/END #2w fwd,3w fwd,1st non-blank ch,start,eol
#cap is to ignore punctuation ch,so be preferred
fx,Fx,tx,Tx, ; , #in a line find fwd,back TO CH 'x'
#go fwd,back to BEFORE x,
#repeat it,in reverse order
#use CR and backspace to navigate in help
10.2. different ways to go to insert-mode
i,I,gI #ins at curr,non-blank beg of line,beg of line
10iaESC #insert 10 CH "a"
s,S #del curr ch,line and insert
a,A,o,O #APPEND more txt after curr ch/line,
#open a new line after,bef curr line
10.3. insert-mode commands
ctrl-w, ctrl-u :delete word (all) before the cursor
c-t,c-d #indent,de-indent
s-left,s-right #one word left, right
ctrl-e, ctrl-y :insert CHs below/above curr line
ctrl-n, ctrl-p :complete part of a keyword (not by dictionary)
rely on "complete" option
:help ins-completion for more
ctrl-r {register} :insert content of a reg (paste under ins mode)
:same for ex-mode
'"' the unnamed register, containing the text of
the last delete or yank
'%' the current file name
'#' the alternate file name
'*' the clipboard contents (X11: primary selection)
'+' the clipboard contents
'/' the last search pattern
':' the last command-line
'-' the last small (less than a line) delete
'.' the last inserted text
s-left|c-left :one word back
s-right|c-right :one word forward
c-a,c-@ repeat last inserted text,and then back normal
C-X C-F file names (great!)
C-X C-L whole lines
C-X C-D macro definitions (also in included files)
C-X C-I current and included files
C-X C-K words from a dictionary
C-X C-T words from a thesaurus
C-X C-] tags
C-X C-V Vim command line
C-P/N prev/next
C-X C-E/Y scoll up/down
C-X C-O omni complete (for coding)
c-v SOME-KEYS
#sometimes useful and make text docs more readable
c-k digraphs #type special chs(std ISO-646 ch)
C-k,Co #insert,Ctrl-k,Co,then you get: ©
:digraphs #list all digraphs
:dig a: 9639 #define a 'map' , a: to ▧ (super!)
c-o NORMAL-MODE-CMD #execute normal mode cmd from insert mode
10.4. copy/paste/change/replace/etc
ce|cw,c$|C,S|cc #CHANGE(cx) till eOw,eol,whole line
ciw #replace whole word under cursor
de,dw|dW,d3w|3dw,d$|D #DELETE(dx) fr curr till:eow,1word,3words,eol
d0,dd,2dd,dG,d20G #...beginOfline,1line,2lines,eOf,line#20
x|dl,X|dh #...curr ch,prev ch
C-w,C-u #DEL under insert mode 1word back,to head the line
yy|Y,5yy,yW,y$,y0,yG #COPY(yx) 1line,5lines,word,...
p,P #PASTE whatever just deleted after,before cursor
rx,3rx,3rENTER #REPLACE(rx) a ch with x,3 x,1(not 3!!) enter
#cut/cp/paste(across app,using visual mode)
v SELECTTEXT "+y #cp to the system clipboard using Xwin '+' reg.
"+gP #paste contents from clipboard(X-reg:+)
#other select/cp/del methods
:%y a select all and copy to buffer a
:1,$y copy all
:1,$d delete all
#using text object
"+yap #cp the current paragragh into clipboard
d3ap #delete 3 paragraghs from current line, good!
#copy the output of : command to clipboard
:redir @+ #type this before the vim command
:nmap <buffer> #type the vim command,e.g. print the mapping
:redir END #type this after the vim command
10.5. visual-mode commands
v,S-v|V,C-v #VISUAL:normal,line,block
o,O #under normal&line,block v-mode to toggle cursor position
C-v
$ #all CHs after curr cursor will be marked, good!
I,c,C #insert,change,change to eol,to every line in block,
but except shorter lines(great!)
~,U,u
A #insert to the end of everyline in block , including shorter lines
$A #select and append to end of everyline (diff with A, good!)
~,U,u
S-v d,y,c|s|R|S = v D,Y,C
#delete,copy,delete&go-insert some lines
S-v J,gJ #joining selected lines&seperate w/ blank,w/o blank
C-v I,c/C,A #ins,change(del&start ins),append txts in block mode
#changes will be cp to all lines:
c #del blocks(leave unslected)&start insert
# inserted txt be copied to all lines in block
C #del from the left edge of block to eol&start...
A #...
rCH #replace all block with ch
gv #select same visual again
10.6. become a “vimer”
VIM looks hard for a beginner, especially for those who always prefer GUI based editors that are easily available around. The biggest headache is that there are a lot of "command" to remember before you can even proceed with your editing work. However, the power is also generated from the same and, Once you get use to it, you will wonder how you ever got along without it!
10.7. much more features
-
we only demonstrate the very surface,
(a very small part of) most popular features -
there are MUCH MUCH MORE that VIM is really good at…
-
more popular/cool features (that I’m using)
-
popular/cool: really depending on what do you want it to do
-
web/wiki developing: TOhtml, vimwiki, vimviki
-
diary
-
selective printing(hardcopy & pdf convert)
-
gnu screen/tmux integretion
-
version control integretion
-
integration into/with other apps(mutt,w3m,firefox,etc)
-
knowledge/note tool (mybase? evernote?)
personal wiki : vimwiki single file DB : Voom
-
-
inspired a lot of other project
-
pentadactyl
-
vimperator
-
10.8. vim , unix philosophy, learning curve, etc
-
UNIX philosophy
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
Doug McIlroy
— inventor of Unix pipes -
editor learning curve
[the “curve” itself,however,is quite confusing and controversial]
-
editor war/jokes
[mostly between vi vs. emacs users]
10.9. (some) resource lists
-
google: tons of vim document, tips, articles, discussions, …
-
vim help system.Unbelievable good.
-
:help user-manual
-
:help ANYTHING
-
-
An application to help learning vim: vimtutor
The Vimtutor is useful for people that want to learn their first Vim commands.
— man vimtutor -
A game to help learning vim
-
vimL:
-
:help eval.txt
-
:help options.txt
-
:help usr_41.txt
-
10.10. download this presentation
-
this presentation is available in following format:
[again, these are all done by from within vim , with only a couple of commands calling external apps(but executed from within vim)]
-
HTML-TOC2
[a “side-panel” TOC]
-
pdf1
[this is the dblatex version]
-
pdf2
[this is the fop version]
-
pdf3
[this is open-office version, rendered from HTML]
-
epub
[Firefox EPUBReader addon is one of the best epub reader available, and it’s platform independent]
-
text
[this is my favorite format. simple pure text as it is, its looks clear and comfortable enough , at leat for me :-) . firefox is the prefered browser for it]
-
xml
[the best xml reader that I’m aware of so far, is the yelp - gnome-help-viewer yelp]
-
chm
[windows html help file]
-
MSword(may not look good)
[this is converted by open-office,rendered from HTML]
-
MSword(not tested,may not work)
[generated from experimental fodt backend]
-
-
not complete (forgot start the recording from the start :D )
-
no audio (forgot to open microphone :D )
-
-
other available formats:
this page and every other version of this same document, are done in vim. |
+