Hatena::Groupvim

vim and plasticity

 | 

2009-06-17

Command-line mode

05:05

現ファイル名が%で表されることは知っていたけど、

:!javac %

それだけでは不便なので、もっと細かく指定出来ないものかと思っていた。

やっと発見。


6. Ex special characters				*cmdline-special*


In Ex commands, at places where a file name can be used, the following
characters have a special meaning.  These can also be used in the expression
function expand() |expand()|.
	%	Is replaced with the current file name.		  *:_%* *c_%*
	#	Is replaced with the alternate file name.	  *:_#* *c_#*
	#n	(where n is a number) is replaced with the file name of
		buffer n.  "#0" is the same as "#".
	##	Is replaced with all names in the argument list	  *:_##* *c_##*
		concatenated, separated by spaces.  Each space in a name
		is preceded with a backslash.
	#<n	(where n is a number > 0) is replaced with old	  *:_#<* *c_#<*
		file name n.  See |:oldfiles| or |v:oldfiles| to get the
		number.							*E809*
		{only when compiled with the +eval and +viminfo features}

ファイル名関連の取得修飾子。長いので抜粋。

							 *filename-modifiers*
	 *:_%:* *::8* *::p* *::.* *::~* *::h* *::t* *::r* *::e* *::s* *::gs*
The file name modifiers can be used after "%", "#", "#n", "<cfile>", "<sfile>",
"<afile>" or "<abuf>".  They are also used with the |fnamemodify()| function.
These are not available when Vim has been compiled without the |+modify_fname|
feature.
These modifiers can be given, in this order:
	:p	Make file name a full path.  Must be the first modifier.  Also
		changes "~/" (and "~user/" for Unix and VMS) to the path for
		the home directory.  If the name is a directory a path
		separator is added at the end.  For a file name that does not
		exist and does not have an absolute path the result is
		unpredictable.

	:h	Head of the file name (the last component and any separators
		removed).  Cannot be used with :e, :r or :t.
		Can be repeated to remove several components at the end.
		When the file name ends in a path separator, only the path
		separator is removed.  Thus ":p:h" on a directory name results
		on the directory name itself (without trailing slash).
		When the file name is an absolute path (starts with "/" for
		Unix; "x:\" for MS-DOS, WIN32, OS/2; "drive:" for Amiga), that
		part is not removed.  When there is no head (path is relative
		to current directory) the result is empty.
	:t	Tail of the file name (last component of the name).  Must
		precede any :r or :e.
	:r	Root of the file name (the last extension removed).  When
		there is only an extension (file name that starts with '.',
		e.g., ".vimrc"), it is not removed.  Can be repeated to remove
		several extensions (last one first).
	:e	Extension of the file name.  Only makes sense when used alone.
		When there is no extension the result is empty.
		When there is only an extension (file name that starts with
		'.'), the result is empty.  Can be repeated to include more
		extensions.  If there are not enough extensions (but at least
		one) as much as possible are included.

簡単なまとめ:

%:p が現bufferのfullPath。

%:h がHeader。file名抜かしたpath。

%:t がTail。Header以外。

%:t:r がRoot拡張子無しのfile名。

%:t:e がExtension。拡張子


拡張子を取り去るにはもっと簡単な方法が。

					*extension-removal* *:_%<*
If a "<" is appended to "%", "#", "#n" or "CTRL-V p" the extension of the file
name is removed (everything after and including the last '.' in the file
name).  This is included for backwards compatibility with version 3.0, the
":r" form is preferred.  Examples: >

よってjava fileをvim上でcompile,runするには

:!javac %; java %<

とすれば良いと。で適当にどこかのキーにMapすればいいと。


:au BufNewFile,BufRead *.java noremap <leader><leader> :!javac %; java %<<cr>

こんな感じか。


追記:

~/.vimrcに以下を追加して、

filetype plugin on

~/.vim/ftplugin/java.vimに以下を書いた。

nnoremap <buffer> <leader><leader> :<c-u>!javac %; java %<lt><cr>

もうfiletype-detectされてるため、autocmdはいらないようだ。c.vimとcpp.vimも作って試してみた。

参考:help filetypes


新しいfiletype作るなら

:help new-filetype

を参考にすると。

ヘルプ強い。

StitchesStitches2011/07/09 21:11These topics are so cofunsing but this helped me get the job done.

uvxenwtuvxenwt2011/07/10 00:245cnnWn <a href="http://veoutzanwfee.com/">veoutzanwfee</a>

jnxvmhvslkojnxvmhvslko2011/07/10 20:30CvbbSy , [url=http://mmhpnqhmsxvk.com/]mmhpnqhmsxvk[/url], [link=http://ahtezymyylxy.com/]ahtezymyylxy[/link], http://arivdxtdetii.com/

ipwdofcdfbipwdofcdfb2011/07/11 20:23SecTcO <a href="http://jcmlvsnfzpoe.com/">jcmlvsnfzpoe</a>

paljtydtaxrpaljtydtaxr2011/07/12 22:448CaEIS , [url=http://yiowgcntnemt.com/]yiowgcntnemt[/url], [link=http://aivyeqzrfzps.com/]aivyeqzrfzps[/link], http://awysqhficrfm.com/

pfizer viagrapfizer viagra2016/09/15 04:13
You've gotten good knowlwdge on this website. weferhervvbt

golistergolister2017/02/02 18:39
I could subscribe.

 |