This tutorials explains about how to add and remove new line at end of file in IntelliJ IDEA?
Adding new line break at end of file on save in IntelliJ IDE
There are multiple ways we can do.
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 General tab select
Check
Ensure every saved file ends with a line break
box to add line breeak 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 configuration file that contains rules applied to all editors.
Create
.editorconfig
in root of the applicationadd the insert_final_newline to
.editorconfig
file and save it.
insert_final_newline = true
insert_final_newline
=true adds new after file is saved, false indicates does not add new line
This works in all popular IDE such as IntelliJ IDEA,VSCode, Atom, Eclipse and Sublime.
Removing new line break or blank lines at end of file on save in IntelliJ IDE
There are multiple ways we can do.
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 General tab select
Check
Remove trailing blank lines at the end of saved file
box to remove trailing blank lines to each file on 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 dropdown that contains Modified Lines or All lines