Essentials of Vi editor - part 3
In my previous two posts (1 and 2 below) we looked at vi basic and editing.
1. Essentials of Vi editor - part 1 - • Vi tutorial - part 1
2. Essentials of Vi editor - part 2 - • Vi tutorial - part 2
In this post let's look at few advanced commands and techniques we can use in vi editor
Indentation and work wrapping
-----------------------------------------------------
>> indent the current line. e.g 3>> indents 3 lines, >} indents a paragraph
<< out dents the current line
:se ai // Enables auto indent
:se noai // Disables auto indentation
:se wm=8 // Sets the wrap margin to 8. As soon as you enter 8 columns it wraps the cursor
:se wm=0 // Auto wrap set off
Filtering
-----------------------------------------------------
!! - applies the filter to the current line
n!! - applies the filter to n number of lines from current line
!} - filters the next paragraph
!{ - filter the previous paragraph
!% - applies the filter from current location to next paranthesis, brace or bracket
These filters can be can be applied to shell commands like tr (transformation), fmt (formatting), grep (search), sed (advanced editing) or awk (a complete programming language). This would mean like sending the filtered text through these commands and getting the output of it and searching or placing back in file as applicable.
e.g In command mode uf you type
!!tr a-z A-Z // And enter. Turns the current line into uppercase. Note however your lower command shows :.!tr a-z A-Z. It converts into a format that vi understands it.
5
Advanced examples with : command
-----------------------------------------------------
// Delete all the lines from the first line (indicated by 1) to current line (indicated by .)
: .,$ s/test/text/g // From current line (indicated by .) to end of line (indicated by $) search and replace all 'test' occurrences to 'text'
: /first/,/last/ ! tr a-z A-Z // Find first line that matches 'first' regexp to the first match following 'last' regex and filter it (indicated by !) using the unix command tr from a-z to A-Z (means convert to upper case)
ma // marks a line by character 'a'
mb // marks a line by character 'b'
!a // jump to the line marked by a
: 'a,'b d // Delete all the lines marked by a through b
In questa pagina del sito puoi guardare il video online Vi tutorial - part 3 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato TechFunnel 01 gennaio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 11 volte e gli è piaciuto 0 spettatori. Buona visione!