This tutorial explains how to add and remove new lines at the end of a file in IntelliJ IDEA.
Adding new line break at end of file on save in IntelliJ IDE
There are multiple ways we can do this.
Use Find Actions
Open Intelli IDEA
Select the text you want to select or
Ctrl + A
to the selected complete file.Select the
Help
Menu +Find Actions
or use the below shortcut commands.- Windows: hotkeys:
Ctrl
+Shift
+A
- Mac: shortcuts:
⌘
+Shift
+ `A
- Windows: hotkeys:
It opens the Find Actions Window popup and types
Ensure every saved file ends with a line break
in the search box and selects it as given below.It opens Settings with the General tab and select
Check the
Ensure every saved file ends with a line break
box to add a line break to each file on save
Use Settings configuration
- Open Intelli IDEA
- Go to
File
->Settings
: Settings window opened - Select
Editor
->General
- Check or uncheck
Ensure every saved file ends with a line break
option
using editorconfig file EditorConfig is a configuration file that contains rules applied to all editors.
Create
.editorconfig
in the root of the applicationadd the insert_final_newline to the
.editorconfig
file and save it.
insert_final_newline = true
insert_final_newline
=true adds new after the file is saved, false indicates does not add a new line
This works in all popular IDE such as IntelliJ IDEA, VSCode, Atom, Eclipse, and Sublime.
Removing new line breaks or blank lines at end of the file on save in IntelliJ IDE
There are multiple ways we can do this.
Use Find Actions
Open Intelli IDEA
Select the text you want to select or
Ctrl + A
to the selected complete file.Select the
Help
Menu +Find Actions
or use the below shortcut commands.- Windows: hotkeys:
Ctrl
+Shift
+A
- Mac: shortcuts:
⌘
+Shift
+ `A
- Windows: hotkeys:
It opens the Find Actions Window popup and types
Remove trailing blank lines at the end of saved file
in the search box and selects it as given below.It opens Settings with the General tab and select
Check the
Remove trailing blank lines at the end of saved file
box to remove trailing blank lines to each file on the save.
Use Settings configuration
- Open Intelli IDEA
- Go to
File
->Settings
: Settings window opened - Select
Editor
->General
- Check or uncheck
Remove trailing blank lines at the end of saved file
option - You can also select Remove trailing spaces on the dropdown that contains Modified Lines or All lines