Managing Files and Directories Flashcards
Editing files with vi Working with files Locating files Searching with grep Manipulating text
In vim, how can you open up a file to a particular line number?
vi +# filename
ex: vi +12 file.txt
In vim, how can you delete multiple lines or a range of lines?
:#,#d
ex: :1,10d
In vim, how can you move to a particular line?
:#
ex: :10
In vim, what does ‘I’ do?
Insert at the beginning of a line
In vim, what does ‘A’ do?
Insert at the end of a line
in vim, what does ‘dd’ do in command mode?
Deletes the entire line
In vim, how do you perform a search?
In command mode, type / and then search (case sensitive)
In vim, what does ‘dw’ do in command mode?
Deletes the word in front up to the cursor
When you perform a search, how can you go to the next and previous occurrence of the search?
‘n’ goes forward, and ‘N’ goes backward
How can you perform a search above your cursor?
?
How can you do a search and replace just once?
:s/find/replace
How can you do a search and replace throughout the whole file?
:%s/find/replace
How can you do a search and replace within a range in the file?
:#,#s/find/replace
What does ‘D’ do in command mode?
Deletes to the end of the line
What does ‘y’ do in command mode?
Yanks (copies)
What does ‘yy’ do in command mode?
Yanks (copies) the current line
What does ‘p’ do in command mode?
pastes
What does ‘ZZ’ do in command mode?
Exits and saves changes
What does ‘:w!’ do?
Saves overwriting the file
What does ‘:q!’ do?
Exits ignoring any changes
In vim, how can you undo an edit?
u
What does ‘:e’ do?
Switches to another file
What does ‘:e!’ do?
Switches to another file without saving current file
How can you open a file in vi and search for a specific string at the same time?
vi +/search file.txt
What does the command ‘cat’ do?
Displays file contents to stdout
What does the command ‘more’ do?
This command is the same as cat, but it is paginated
What does the command ‘less’ do?
This command is the same as ‘more’, but it allows bidirectional scrolling
What does the command ‘head’ do?
This command displays the first 10 lines.