Introduction
Some mac users with external colorschemes installed in vim may occur this problem : "vim editor didn't fill the whole screen of terminal" (which creates the blue gap in the sample image after opening vim) , although it doesn't bother in the functional aspects, but it still looks a little annoying or imperfect. This article helps you solve this problem !
Solution
Foreword
At first I tried to find a solution to let vim to fill the terminal, but it seems there are no direct way to make this happen ,so there is a alternative solution, "let terminal background color be same as vim editor when vim is open". I get inspried when looking at here, so I wrote a bash script to make this happen, below is the code,make sure your computer can execute applescript and bash !
Let's start!
- Make a terminal config file with the same background color as vim
- You can use the builtin app "Digital Color Meter" in mac to get the rgb value of the vim background color.
- Then choose Terminal > Preferences , click Profiles, create a profile, then click Text.You can see the "Color and Effects section" under a subject "Background", change the color using the obtained rgb value.
2.Copy the below code, remember to change <1> in the quote to step 1.2's terminal profile name, <2> as your vim editor path.
3.Save the below code as a bash file
#!/bin/bash
original=$(osascript -e 'tell application "Terminal" to return name of current settings of window 1')
osascript -e 'tell application "Terminal"
set current settings of window 1 to settings set "<1>"
end tell'
<2> $@
osascript \
-e 'tell application "Terminal"' \
-e "set current settings of window 1 to settings set \"$original\"" \
-e 'end tell'
unset original
exit 0
Additional step
For convenience, you can rename your bash file as "vim" using "mv" command in terminal (need to use "mv" command to forcely remove file extension in filename)
Then put the file under a empty directory
After placing your directory in a nice place,you can add the below line to ".bash_profile" or ".zprofile" (depends on which default shell you use ) , remember to change <1> to the path of the directory your bash file is.
PATH="<1>:${PATH}"
Now execute the bash script and see if it works !
ps. If you gone through step 5, reopen your terminal, and you can just type "vim" to use vim editor with the problem solved now !
Additional information
- Arguments :
- you can add arguments behind the name of bash file when entering command, these arguements will be thrown to vim in the exact same form.
Example :
```
<bash file path> test.txt
```
the above command is equivalent to "edit text.txt by vim"
Top comments (0)