I mostly use vim from the terminal by vi command.
I want to create and save a file named something like getting started.txt (there is space between two words). I tried two methods:
:sav getting started.txt
but I got an error : E172: Only one file name allowed
:sav "getting started.txt"
This time I got : E471: Argument required
How can I achieve what I want?
Leading (before the filename) and trailing (after the filename) spaces in file or folder names also aren't allowed. If you're using Office 2010, you can't use "&" in file and folder names. These names aren't allowed for files or folders: .
Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.
There are two main ways to handle such files or directories; one uses escape characters, i.e., backslash (\<space>), and the second is using apostrophes or quotation marks. Using backslash can be confusing; it's easy and better to use quotation marks or apostrophes.
To save a file, you must first be in Command mode. Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit. To the non-vi initiated, write means save, and quit means exit vi.
Escape the space character:
:sav getting\ started.txt
Commenter @ib mentions fnameescape
, here's how you can use it:
:save
and a space.fnameescape("Your spacey, special character'y file name")
. Tab expansion works, so you can probably do fn
Tabe
Tab.Poster iler.ml suggests a function to do this easily (I've modified his code slightly). Put this in your .vimrc:
" :W and :Save will escape a file name and write it
command! -bang -nargs=* W :call W(<q-bang>, <q-args>)
command! -bang -nargs=* Save :call Save(<q-bang>, <q-args>)
function! W(bang, filename)
:exe "w".a:bang." ". fnameescape(a:filename)
endfu
function! Save(bang, filename)
:exe "save".a:bang." ". fnameescape(a:filename)
endfu
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With