i want to create a shortcut to run typescript in vim how can i access the filename in .vimrc
i want to run short scripts.
nmap <leader>r:! ts-node current-file<return>
First try %
, as this gets substituted by the file name (as explained in :help:!
):
nmap <Leader>r :! ts-node %<CR>
But if the file name contains whitespaces or special characters, you might see some errors. In that case, you need to escape the file name as follows:
nmap <Leader>r :execute '!ts-node ' . shellescape(expand("%"))<CR>
You're strongly adviced to read :h cmdline.txt
, section 6 :h cmdline-special
from top down to bottom.
nnoremap <leader>r :!ts-node %:S<CR>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.