vim: Force specific syntax via command-line argument
When I want to easily read my PostgreSQL schema, I dump it to stderr
and redirect it to vim
:
pg_dump -h localhost -U postgres dog_food --schema-only | vim -
This gives:
vim
does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:
:set syntax=sql
Which gives:
Being the lazy developer I am, I would like to force vim
to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever>
every time I open it with stdin
data..
Is there a way to set vim
syntax by passing a command line argument?
vim stdout stdin sql syntax-highlighting
add a comment |
When I want to easily read my PostgreSQL schema, I dump it to stderr
and redirect it to vim
:
pg_dump -h localhost -U postgres dog_food --schema-only | vim -
This gives:
vim
does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:
:set syntax=sql
Which gives:
Being the lazy developer I am, I would like to force vim
to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever>
every time I open it with stdin
data..
Is there a way to set vim
syntax by passing a command line argument?
vim stdout stdin sql syntax-highlighting
add a comment |
When I want to easily read my PostgreSQL schema, I dump it to stderr
and redirect it to vim
:
pg_dump -h localhost -U postgres dog_food --schema-only | vim -
This gives:
vim
does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:
:set syntax=sql
Which gives:
Being the lazy developer I am, I would like to force vim
to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever>
every time I open it with stdin
data..
Is there a way to set vim
syntax by passing a command line argument?
vim stdout stdin sql syntax-highlighting
When I want to easily read my PostgreSQL schema, I dump it to stderr
and redirect it to vim
:
pg_dump -h localhost -U postgres dog_food --schema-only | vim -
This gives:
vim
does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:
:set syntax=sql
Which gives:
Being the lazy developer I am, I would like to force vim
to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever>
every time I open it with stdin
data..
Is there a way to set vim
syntax by passing a command line argument?
vim stdout stdin sql syntax-highlighting
vim stdout stdin sql syntax-highlighting
asked Mar 10 '16 at 11:40
Adam MatanAdam Matan
83331525
83331525
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can use:
vim -c 'set syntax=sql' -
2
Note: Works for me even without the colon in the command.
– Murphy
Mar 10 '16 at 12:27
1
Shorter variant:vim '+set syn=sql' -
– Stéphane Chazelas
Mar 10 '16 at 13:01
5
Typically you're better off usingset filetype=sql
(orft=sql
for short); that will also load the indentation files and such and not just the syntax highlighting...
– Martin Tournoij
Mar 16 '16 at 7:11
add a comment |
You can even automate that by putting the command into your ~/.vimrc
:
augroup filetype
au! StdinReadPre * set filetype=sql
augroup END
add a comment |
vim -R -c 'set ft=sql' -
-R
opens Vim in read-only mode. Your system may have the aliasview
forvim -R
, but Neovim does not support it.
set ft
is short forset filetype
. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f268889%2fvim-force-specific-syntax-via-command-line-argument%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use:
vim -c 'set syntax=sql' -
2
Note: Works for me even without the colon in the command.
– Murphy
Mar 10 '16 at 12:27
1
Shorter variant:vim '+set syn=sql' -
– Stéphane Chazelas
Mar 10 '16 at 13:01
5
Typically you're better off usingset filetype=sql
(orft=sql
for short); that will also load the indentation files and such and not just the syntax highlighting...
– Martin Tournoij
Mar 16 '16 at 7:11
add a comment |
You can use:
vim -c 'set syntax=sql' -
2
Note: Works for me even without the colon in the command.
– Murphy
Mar 10 '16 at 12:27
1
Shorter variant:vim '+set syn=sql' -
– Stéphane Chazelas
Mar 10 '16 at 13:01
5
Typically you're better off usingset filetype=sql
(orft=sql
for short); that will also load the indentation files and such and not just the syntax highlighting...
– Martin Tournoij
Mar 16 '16 at 7:11
add a comment |
You can use:
vim -c 'set syntax=sql' -
You can use:
vim -c 'set syntax=sql' -
edited Mar 10 '16 at 12:59
Stéphane Chazelas
309k57582942
309k57582942
answered Mar 10 '16 at 12:24
LambertLambert
9,07021228
9,07021228
2
Note: Works for me even without the colon in the command.
– Murphy
Mar 10 '16 at 12:27
1
Shorter variant:vim '+set syn=sql' -
– Stéphane Chazelas
Mar 10 '16 at 13:01
5
Typically you're better off usingset filetype=sql
(orft=sql
for short); that will also load the indentation files and such and not just the syntax highlighting...
– Martin Tournoij
Mar 16 '16 at 7:11
add a comment |
2
Note: Works for me even without the colon in the command.
– Murphy
Mar 10 '16 at 12:27
1
Shorter variant:vim '+set syn=sql' -
– Stéphane Chazelas
Mar 10 '16 at 13:01
5
Typically you're better off usingset filetype=sql
(orft=sql
for short); that will also load the indentation files and such and not just the syntax highlighting...
– Martin Tournoij
Mar 16 '16 at 7:11
2
2
Note: Works for me even without the colon in the command.
– Murphy
Mar 10 '16 at 12:27
Note: Works for me even without the colon in the command.
– Murphy
Mar 10 '16 at 12:27
1
1
Shorter variant:
vim '+set syn=sql' -
– Stéphane Chazelas
Mar 10 '16 at 13:01
Shorter variant:
vim '+set syn=sql' -
– Stéphane Chazelas
Mar 10 '16 at 13:01
5
5
Typically you're better off using
set filetype=sql
(or ft=sql
for short); that will also load the indentation files and such and not just the syntax highlighting...– Martin Tournoij
Mar 16 '16 at 7:11
Typically you're better off using
set filetype=sql
(or ft=sql
for short); that will also load the indentation files and such and not just the syntax highlighting...– Martin Tournoij
Mar 16 '16 at 7:11
add a comment |
You can even automate that by putting the command into your ~/.vimrc
:
augroup filetype
au! StdinReadPre * set filetype=sql
augroup END
add a comment |
You can even automate that by putting the command into your ~/.vimrc
:
augroup filetype
au! StdinReadPre * set filetype=sql
augroup END
add a comment |
You can even automate that by putting the command into your ~/.vimrc
:
augroup filetype
au! StdinReadPre * set filetype=sql
augroup END
You can even automate that by putting the command into your ~/.vimrc
:
augroup filetype
au! StdinReadPre * set filetype=sql
augroup END
edited Mar 10 '16 at 12:16
answered Mar 10 '16 at 12:07
MurphyMurphy
1,7861617
1,7861617
add a comment |
add a comment |
vim -R -c 'set ft=sql' -
-R
opens Vim in read-only mode. Your system may have the aliasview
forvim -R
, but Neovim does not support it.
set ft
is short forset filetype
. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.
New contributor
add a comment |
vim -R -c 'set ft=sql' -
-R
opens Vim in read-only mode. Your system may have the aliasview
forvim -R
, but Neovim does not support it.
set ft
is short forset filetype
. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.
New contributor
add a comment |
vim -R -c 'set ft=sql' -
-R
opens Vim in read-only mode. Your system may have the aliasview
forvim -R
, but Neovim does not support it.
set ft
is short forset filetype
. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.
New contributor
vim -R -c 'set ft=sql' -
-R
opens Vim in read-only mode. Your system may have the aliasview
forvim -R
, but Neovim does not support it.
set ft
is short forset filetype
. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.
New contributor
edited 10 hours ago
New contributor
answered 10 hours ago
anishpatelanishpatel
1135
1135
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f268889%2fvim-force-specific-syntax-via-command-line-argument%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown