Skip to content

A couple .vimrc questions

Is there a way to link to a file containing the syntax highlighting style, (/blahblah/kholer for example), in the .vimrc file.

And is there a way to put an if statement in the .vimrc so it can change the tab width etc depending on the filetype.

For expample

if $openedfile is javascript
tabwsidth = 3
fi
8 points7 comments
Open on Reddit
About this post
Posted
Archived
Score
8 · 100% up
Kind
Text
ID
25ibde

Author

6
posts
19
comments
0
media
View profile

7 comments

You can either use the ftplugin folder convention (vim has a couple other of those as well, like put your highlighting color files in ~/.vim/colors/), or do like this:

" Set vim to detect filetypes; will run ~/.vim/ftplugin/<filetype>.vim
" Set automatic indentation depending upon the detected file type
filetype plugin indent on

" Make sure that TABs work exactly as TABs in Makefiles 
autocmd FileType make setlocal noexpandtab
autocmd FileType make setlocal softtabstop=0

" Always use spaces for python
autocmd FileType python setlocal expandtab

" filetypes to turn on spelling for
autocmd FileType markdown,rst,txt setlocal spell
7 points

Yes there are. However you don't need if statements, you can use auto commands.

Please check the builtin docs for this, I'm sure. Someone in the comments has put a n example too.

However I suggest you post such questions to /r/vim which is a little better suited for these questions. The subreddit is active and very helpful, from newbies to masters.

Edit: checkout this Vimcasts episode.

3 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.