I want to source a vim file in vimrc file.
I wrote code in vim file.
set makeprg=javac %
and vim said he doesn't know that option.
how do i write code that javac current file?
what I want to do is compiling current file in vim while coding..
On the command-line a space is used to separate 2 arguments. So, when you execute:
set makeprg=javac %
The :set command assigns the value javac to the option 'makeprg', then it tries to enable the option '%', which doesn't exist, hence the error.
If you want the space to be included inside the value of the 'makeprg' option, you need to escape it:
set makeprg=javac\ %
Related
It's often that I get paths in the format <path>:<line>:<column> (from text matches such as grep or errors on code).
When I double click, it matches the whole string, including line and column, then I usually remove the column, and replace :line with +line to match vi parameter.
Therefore, I'd like having a hack to rapidly open vim at the right point just with a paste. Is there any config on vim level or alias I could use?!
Thanks
There are plugins that trap the BufNewFile,BufRead events, parse out the file name and number(s), and redirect to the corresponding file:
file-file is the minimalistic original plugin
vim-fetch supports multiple ways of specifying the number(s), overloads some mappings (like gf), and even offers a :Fetch command
Use the quickfix list instead:
Vim has a startup option -q to read a quickfix file. So we have
options (depending on your shell): cmd > results ; vim -q results
Or my favorite: vim -q <(cmd)
I have the tagbar plugin working perfectly in vim but no tags are displayed in neovim.
When I use TagbarDebug from within both, I can see that the ctags output is fine when run from vim, but from neovim, tagbardebug.log.ctags_out just has the following line:
^[[31;01m'^[[39;00m^[[31;01m/usr/local/bin/ctags-f---format=2--excmd=pattern--fields=nksSaf--extra=--file-scope=yes--sort=no--append=no-V--language-force=python--python-kinds=icfmv/var/folders/_z/tz5sb8jd6mj41gj2gn8qvhhr0000gn/T/nvimoU8Oxr/1.py^[[39;00m^[[31;01m'^[[39;00m
From tagbardebug.log, I can see that ctags is called slightly differently between the two. From within vim, the log has:
Calling shell to execute: "('/usr/local/bin/ctags' '-f' '-' '--format=2' '--excmd=pattern' '--fields=nksSaf' '--extra=' '--file-scope=yes' '--sort=no' '--append=no' '-V' '--language-force=python' '--python-kinds=icfmv' '/var/folders/_z/tz5sb8jd6mj41gj2gn8qvhhr0000gn/T/v0jhgoR/4.py') >/var/folders/_z/tz5sb8jd6mj41gj2gn8qvhhr0000gn/T/v0jhgoR/5 2>&1"
but from neovim, the equivalent line is:
Executing command: "'/Users/owen/miniconda3/bin/xonsh' '-c' ''/usr/local/bin/ctags' '-f' '-' '--format=2' '--excmd=pattern' '--fields=nksSaf' '--extra=' '--file-scope=yes' '--sort=no' '--append=no' '-V' '--language-force=python' '--python-kinds=icfmv' '/var/folders/_z/tz5..."
The difference appears to be how ctags is being called - vim calls it directly but neovim calls the shell executable and passes the -c argument. However, if I run the command used by neovim from the command line, it works fine.
I've tried setting tagbar_ctags_bin, but that made no difference.
Any clues as to where else I need to dig?
My guess is that xonsh makes some assumptions about being connected to a terminal, which is true in terminal Vim but not gVim nor Neovim (which invokes commands using pipes).
Try setting shell* options to their default values:
:set shell& shellcmdflag& shellpipe& shellquote& shellredir& shellxquote& shellxescape&
(Or simply remove the lines in your config that set those options.)
The difference appears to be how ctags is being called - vim calls it directly but neovim calls the shell executable and passes the -c argument
No, that's just a difference in log output. Vim also uses the 'shell' option and 'shellcmdflag' options (which is hinted by its log message: Calling shell to execute...).
I am working in a library that has its own Makefile, so I am using my own Makefile called my_makefile and use make -f my_makefile
My problem is how to tell Vim that my_makefile is an actual Makefile and use color scheme that it use for a Makefile.
It is hard to read it now.
How about the
:set syntax=make
command
You could also use Modelines, which are comments in either the first 5 or last 5 lines of a file that vim reads, and are used to set the filetype. For example, in a makefile, it would be:
# vim: filetype=make
I also have found another way! You can use "my_makefile.mk" and vim automatically know it is a MakeFile and you do not need to change .vimrc either.
I frequently use Vim to parse and clean up data exported from other sources. Often, I find myself running a sequence of substitute commands. I'd like to save those commands to some kind of script file, then run it on the current buffer.
An example of the commands found in sample script could be:
:%s/pattern1/pattern2/g
:%s/pattern3/pattern4/g
:v/pattern5/d
... etc
If the script were in the same directory as the current buffer file (or maybe in the .vim folder), how could I load and run these commands as if I were typing them in manually?
If you have a Vim window open and want to execute VimL on a buffer, you can do:
:source /path/to/vim/file/name.vim
Put your commands in script.vim:
:%s/pattern1/pattern2/g
:%s/pattern3/pattern4/g
:v/pattern5/d
Use it like this:
$ vim filetocleanup -s script.vim
See :help -s.
Is it possible to configure VIM in a such way that if I type
vim filename:123:89
it opens file filename goes to line 123 and column 89?
If not through VIM maybe with a hack for the shell?
You can install the file-line plugin to open a file to the line and column specified after the filename. (github mirror)
From the Readme on github
When you open a file:line, for instance when coping and pasting from
an error from your compiler vim tries to open a file with a colon in
its name.
Examples:
vim index.html:20
vim app/models/user.rb:1337
With this little script in your plugins folder if the stuff after the colon is a number and a file exists with the name especified before the colon vim will open this file and take you to the line you wished in the first place.
I'm not sure how to skip to the column, but I've wanted the same feature for ages, so I just hacked up the "jump to line" functionality. In your .bashrc, set
VIM=$(which vim)
function vim {
local args
IFS=':' read -a args <<< "$1"
"$VIM" "${args[0]}" +0"${args[1]}"
}
This splits the argument to Vim by :, then constructs a command line of the form
vim <filename> +0<line>
The +0 is a hack to make sure the default line number is zero.
(If you're not using Bash, you can adapt this into a script and put it in your path, or translate it to your favorite shell language. To edit filename:with:colons, use $VIM.)
I've been using the file-line plugin, but it has a few open issues, and breaks some other vim plugins. So I went fishing for a better solution. Here it is:
function vim() {
local first="$1"
case $first in
*:*)
shift
command vim ${first%%:*} +0${first##*:} $#
;;
*)
command vim $#
;;
esac
}
Limitations:
bash only
Only parses first argument, whereas vim +X parses the first file argument. A more complex version could easily be made with proper command line parsing.
Advantages:
doesn't break other vim plugins
you could easily use $EDITOR and use this with emacs for instance.
compared to Fred's answer it doesn't use IFS/read to parse the argument but uses bash parameter expansion.
also sends in the remaining argument, which might occasionally be necessary.