I have this vim plugin
http://www.vim.org/scripts/script.php?script_id=4111
installed. I have included the following lines for the .vimrc:
autocmd BufRead,BufNewFile *.log set syntax=log4j
I am getting "autocmd unknown command"
when I am running
. .vimrc
from the bash
Please help.
The . command in Bash reads the argument as a Bash script; you're executing the Vim configuration as a Bash script. Of course, Bash doesn't know the autocmd command, and therefore complains.
Vim will automatically read in your ~/.vimrc on startup (cp. :help initialization). Just open a new Vim instance, and your new configuration will apply. You can ensure that the .vimrc has been read via :scriptnames (the file path should be listed at the start), or list your defined autocmd via :autocmd BufRead *.log
If you :edit somefile.log, you can verify that the syntax has been set via :setlocal syntax?
You don't need to run that command, once you will open any "*.log" file using "vim" the plugin will be used. if installed correctly.
Related
I have a hotkey set to automatically create some aliases and install a script whenever I SSH into a server (for my work). Does anyone know of a way to set the vim colo from the command line so I can use it in my hotkey? Thank you!
You can run commands when starting vim:
vim +'colorscheme blue' my_file
See man vim:
-c {command}
{command} will be executed after the first file has been read.
{command} is interpreted as an Ex command. If the {command} contains
spaces it must be enclosed in double quotes (this depends on the shell
that is used). Example: Vim "+set si" main.c
Note: You can use up to 10 "+" or "-c" commands.
When I try to use . .vimrc it gives and error:
bash: runtime! command not found
bash: syntax: command not found
bash: filetype: command not found
bash: filetype: command not found
It just randomly stopped working for no reason, all other dotfiles seem to work fine. The .vimrc contains this:
runtime! archlinux.vim
set number
set noswapfile
set nobackup
syntax on
set autoindent
set smartindent
set smarttab
filetype plugin on
filetype indent on
set incsearch
set hlsearch
It also gave an error inside a comment when it was there.
The . (or source) command is a bash command which reads a file (which should be a valid bash script) in the context of the current shell instance.
The .vimrc file is not a bash script, it's something that's read and processed by vim rather than bash.
It's no different to trying to compile C code with a Pascal compiler. The file content is not suitable for what you're trying to do with it. The .vimrc file should be automatically picked up next time you run a vim instance.
~/.vimrc is the runtime configuration file for vim i.e. the file will be read by vim when it starts and all the statements are vim specific.
As you are trying to source the file in bash, you are getting the errors as bash has no idea of the vim specific statements like runtime, syntax etc.
use vimorvi instead of source command to activate .vimrc.Because .vimrc is not *.sh like .bashrc and etc.
I have a problem as follows:
I have a script which copies a log file from remote machine, does some modification on it and then opens it in vim, problem is vim doesn't auto recognize the file type (which outside of the script id does) – I need this for coloring the log.
Script as follows:
/usr/bin/rcp 14.1.61.10$node:/output/LocalLog_IPNode$node.log /export/home/fpd/tmp/tmp_local_log
chmod 777 /export/home/fpd/tmp/tmp_local_log/*
sed -i 's/[A-Z]\{4,8\}.*[oigus][kbdct][sel]\//---/g' /export/home/fpd/tmp/tmp_local_log/LocalLog_IPNode$node.log
vi /export/home/fpd/tmp/tmp_local_log/LocalLog_IPNode$node.log
My .vimrc:
au BufNewFile,BufReadPost LocalLog* set filetype=local_log
Note that the files opens in vim (if it helps the manual command ":set syntax=local_log" doesn't work either).
After exiting the script and manually opening the log everything works fine =(
Your problem is that the autocommand option is only availaible in vim and not vi.
So if this is available on your system, you should replace the last command line by :
vim /export/home/fpd/tmp/tmp_local_log/LocalLog_IPNode$node.log
Vim stands for "Vi Improved" and many options are only available in the latter.
To be sure you can do:
:help autocommand
It is always mentioned if the feature is vi or vim compatible.
I am trying to set permission for my file to be executed using the vim text editor. I have been using :chmod +x filename.sh but the error pops up that says it is not an editor command. I am even trying to set a path for the directory that my bash.exe and other files are, but I get a similar error. What can I do about this?
To run an external shell command, you need to use :!, not :.
:!chmod +x filename.sh
Also, you can use a % and it'll expand to the current filename:
:!chmod +x %
When using MSYS on a windows platform, I "set -o vi" to use the vi shell mode. Tab autocompletion for files and directories stops working. How to I renable this while remaining in vi shell mode?
Try:
bind -q complete
to see if it's set.
To set it at the Bash prompt:
bind '"\C-i":complete'
It should already be set by default, but it may be overridden in /etc/inputrc or ~/.inputrc possibly inside a $if mode=vi / $endif block. You can set for subsequent shell starts by adding this line to your ~/.inputrc file:
"\C-i": complete
For dir/file name completion try: ESC-\ or ESC-= or ESC-*
In my case (ubuntu 18.04) it doesn't work for commands.