On 09/12/12 03:56, eNG1Ne wrote:
> "can I use system and user variables in vim" … specifically, can
> I include the system date in the text in such away that it
> updates when I open the file, and can I include the filename in
> the text.
While I'm not sure what "system and user variables" you'd be using,
you *can* call functions in mappings to insert various things
including the current date/time and the filename. If you want to do
it automatically, you can hook up with an autocmd, something like
:autocmd FileReadPost *.globspec $put=strftime('%c')
:autocmd FileReadPost *.globspec $put=expand('%')
or if you want to replace existing code that can be identified,
something like (untested)
function! UpdateStamps()
%s/\$Date: \zs.*\ze \$/\=strftime('%c')/e
%s/\$Name: \zs.*\ze \$/\=expand('%')/e
endfunction
autocmd FileReadPost *.globspec call UpdateStamps()
which should roughly find things like "ident" strings.
Alternatively, you can wire it to a mapping for manual inclusion:
:nnoremap <f4> o<c-r>=strftime('%c')<cr><esc>
:inoremap <f4> <c-r>=strftime('%c')<cr>
:nnoremap <f5> o<c-r>=expand('%')<cr><esc>
:inoremap <f5> <cr>=expand('%')<cr>
To learn more, you can read at
:help quote=
:h autocmd
:h strftime()
:h expand()
:h map.txt
:h :put
:h sub-replace-special
-tim
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Wednesday, September 12, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment