vi, vim, vimdiff, meld - alex-aleyan/linux_wiki GitHub Wiki
Meld Install:
- https://gnome.pages.gitlab.gnome.org/meld/
- CentOS7: comes from EPEL repo.
- CentOS8:
yum install https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/28/Everything/x86_64/os/Packages/m/meld-3.18.0-2.fc28.noarch.rpm
Useful VIM Commands (^ means while holding CTRL key):
-
Move the cursor:
vi file.txt +/foo to move the cursor to the first instance of the foo string in file h, j, k, l left, down, up, right w, e, b forward 1 word, forward to the next end of word, back 1 word H, M, L Move to Highest, Middle, Lowest line on the screen ), } Move forward one sentence, move forward one paragraph u, ^R undo, redo G Go to the last line o, O Start new line below, start new line above ~ Toggle the case of the character under the cursor 5G 3G $G Go to line 5, 3, last line 2| 11| Go to column 2, 11 in the current line 0, $ moves the cursor to the beginning/end of the line
-
Screen Manipulations:
^f move forward one screen ^b move backward one screen ^d move down (forward) one half screen ^u move up (back) one half screen ^l redraws the screen ^r redraws the screen, removing deleted lines
-
Repeat last command:
. repeat last command * highlight all instances of a word under cursor
-
Display Control:
Q puts you into line editor mode.
-
Insert, Delete, Yank, Cut:
i, a, I, A insert text from the cursor, after the cursor, at the beginning of the line, end of the line r, R overwrite letter, start overwriting the line starting from the cursor position x, X, D delete character under cursor, delete character after cursor, delete everything after the cursor Ndl Ndw Ndd delete N letters, N words, N lines Nyl Nyw Nyy yank N letters, N words, N lines Ncl Ncw Ncc cut/change N letters, N words, N lines p P paste below the line or after the cursor, paste above the line or before the cursor
-
Buffer Copy/Cut/Paste (a thru b are user buffers, 1 thru 9 are system buffers):
"a3cl "b5cw use "LETTER in front of cut or yank to put it into a particular buffer "ap "bp use "LETTER in front of the paste command to paste from a particular buffer. "1yy "2yy where the content of buffer 1 shifted to buffer 2 (every time you copy) and so on...
-
Search:
/fooname search forward ?fooname search backwards n next occurrence N previous occurrence
-
Column Commands:
:.=, = returns line number of current line, the total number of lines :r readfromfile.txt to copy content of a file into the currently opened file :r !command to read the output of a command :w writetofile.txt to save the content of the file to a new file :1,10 w afile.txt to save the content of line 1 thru 10 to a file :1,10 w >> afile.txt to append the content of line 1 thru 10 to a file :s/oldfoo/newfoo/ replace FIRST OCCURRENCE of the oldfoo with newfoo on the CURRENT LINE :s/oldfoo/newfoo/g replace ALL OCCURRENCE of the oldfoo with newfoo on the CURRENT LINE :%s/oldfoo/newfoo/g replaces all occurrences of oldfoo with the newfoo in the entire file :%s/oldfoo//g delete all occurrences of oldfoo with the newfoo in the entire file :%s/oldfoo//gc delete all occurrences of oldfoo with the newfoo in the entire file with query :set all :set nu set numbered lines :set nonu unset numbered lines :set ic ignore case when searching :set noic no ignore case when searching :set hlsearch, nohlsearch, noh highlight search, no highlight search, no highlight :set background=dark :highlight normal ctermfg=grey ctermbg=black cterm=none :set tabstop=2 :set nu :set autoindent :set guifont=14 :syntax on :2,4 co 32 copy lines 2 thru 4 to line 32 :2,4 m 32 move lines 2 thru 4 to line 32 :2,4 d delete lines 2 thru 4 :!command_name executes a command without leaving vi; :!pwd :9 !command_name copy command's output to line 9 :n go to the next opened file if more than 1 file are opened :rew go to the first opened file if more than 1 file are opened :args list all opened files :w, q, x, qw save, quit vi, save and quit, save and quit
Useful VIMDIFF Commands:
do - Get changes from other window into the current window.
dp - Put the changes from current window into the other window.
]c - Jump to the next change.
[c - Jump to the previous change.
zr - open ALL folded lines.
zo - open folded lines.
zc - close folded lines.
Ctrl+w,w - change window.
:diffupdate
:only | wq - quit other windows, write and quit
:qa quit all
.vimrc
set background=dark
highlight normal ctermfg=grey ctermbg=black cterm=none
set tabstop=4
set syntax=bash
set nu
set autoindent
set guifont=14
syntax on
set softtabstop=2
set tabstop=2 shiftwidth=2 expandtab
set showcmd
set cursorline
set wildmenu
set showmatch
set hlsearch
set incsearch