mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Setting Filetype With Modelines as a vim til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
||||
warrant a full blog post. These are mostly things I learn by pairing with
|
||||
smart people at [Hashrocket](http://hashrocket.com/).
|
||||
|
||||
_433 TILs and counting..._
|
||||
_434 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -496,6 +496,7 @@ _433 TILs and counting..._
|
||||
- [Searching For Hex Digits](vim/searching-for-hex-digits.md)
|
||||
- [Set End Of Line Markers](vim/set-end-of-line-markers.md)
|
||||
- [Set Your Color Scheme](vim/set-your-color-scheme.md)
|
||||
- [Setting Filetype With Modelines](vim/setting-filetype-with-modelines.md)
|
||||
- [Show All Syntax Highlighting Rules](vim/show-all-syntax-highlighting-rules.md)
|
||||
- [Split Different](vim/split-different.md)
|
||||
- [Splitting For New Files](vim/splitting-for-new-files.md)
|
||||
|
||||
25
vim/setting-filetype-with-modelines.md
Normal file
25
vim/setting-filetype-with-modelines.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Setting Filetype With Modelines
|
||||
|
||||
Vim and various plugins generally use known file extensions to determine the
|
||||
filetype of a file. This is important because it is how Vim decides which
|
||||
filetype-specific settings to enable, such as syntax highlighting.
|
||||
|
||||
If I am editing a file such as `build.boot`, Vim is not going to know that
|
||||
its filetype should be set to `clojure`. The `build.boot` file is full of
|
||||
clojure code though, so I'm losing out on syntax highlighting and so forth.
|
||||
I can settle for manually setting the filetype to clojure (e.g. `:set
|
||||
ft=clojure`) each time I open up the file.
|
||||
|
||||
Or I can use a modeline setting. By including a comment at the top or
|
||||
bottom of the file specifying the filetype setting, I can ensure that each
|
||||
time I go to edit the file, the appropriate filetype will be set.
|
||||
|
||||
That modeline comment will look something like:
|
||||
|
||||
```clojure
|
||||
; vim: set ft=clojure:
|
||||
```
|
||||
|
||||
See `:h modeline` for more details.
|
||||
|
||||
h/t Brian Dunn
|
||||
Reference in New Issue
Block a user