Photo by David Travis on Unsplash

Check the newline code of the opened file

:set fileformat?
:se ff?

Visualization of line feed code

Display line feed code

:se list

Hide newline code

:se nolist

Specify line feed code to open


:edit ++fileformat=unix


:e ++ff=dos


:e ++ff=mac

Specify line feed code

:se ff=dos
:se ff=mac
:se ff=unix

Remove line feed code


Reopen the file with the specified character code

Reopen the file in UTF-8

#Option 1
:e ++enc=utf-8
#Option 2
:edit ++enc=utf-8

Save file with specified character code

Save the file in UTF-8

#Option 1
:set fileencoding=utf-8
#Option 2
:se fenc=utf-8

Check current encoding

Vim encoding

:se enc?

File encoding

:se fenc?



Compare files under the specified directory and display only file names

diff -qr /home/vagrant/example1 /home/vagrant/example2

Compare ignoring newline spaces and newline codes

cd /home/vagrant/
diff -Bw --strip-trailing-cr example1.txt example2.txt

Display only the differences side by side

cd /home/vagrant/
diff -y example1.txt example2.txt | grep "|\|<"

Side-by-side comparison (vimdiff)

⚠️ Vim must be installed

#Option 1
cd /home/vagrant/
vimdiff example1.txt example2.txt
#Option 2
cd /home/vagrant/
vim -d example1.txt example2.txt

Diff Options

Compare by directory

diff -r /home/vagrant/example1 /home/vagrant/example2

Show file name only

diff -q /home/vagrant/example1 /home/vagrant/example2

Ignore newlines

diff -B example1.txt example2.txt

Ignore whitespace

diff -w example1.txt example2.txt

Ignore newline code

diff — strip-trailing-cr example1.txt example2.txt

Ignore case

diff -i example1.txt example2.txt

Side by side comparison

diff -y example1.txt example2.txt






DevOps Consultant. I’m strongly focused on automation, security, and reliability.