简体   繁体   中英

Broken 'ls' bash command after source ~/.vimrc

I recently sourced my .vimrc that contained this function:

 33 function! InsertTabWrapper()
 34   let col = col('.') - 1
 35   if !col || getline('.')[col - 1] !~ '\k'
 36     return "\<tab>"
 37   else
 38     return "\<c-p>"
 39   endif
 40 endfunction
 41 inoremap <tab> <c-r>=InsertTabWrapper()<cr>
 42 inoremap <s-tab> <c-n>

I then from the command line did

source ~/.vimrc

Now whenever I run

$ls

I see snippets of that function in the output.

$ ls
?  else? ??return <c-p
?  endif?endfunction?inoremap <tab> <c-r>=InsertTabWrapper()<cr>?inoremap <s-tab> <c-n>??
Applications
Desktop
Documents

I haven't been able to find anyway to clear this up. Thanks!

Bash can't read Vim syntax, I guess it will trip over the lines ( function , let , if ) and pick up the first > as file IO redirection. And those are actually two files in your directory it has created, with weird characters in their names.

This is supported by the fact that the output begins after the first > and goes onto a new line after the second > , and those two characters are missing in the output.

ie ls is working fine and they really do exist as files. Can you delete them? Do you have another way to browse files? (a Gui, FileZilla over SFTP, WinSCP, etc?). You could try rm *return* and rm *endfunction* , or (carefully) use rm -i * which will prompt y/n to delete each file, and only say y if those files appear.

(but I might be wrong and that's not what happened at all. If I try to source your file code, I don't get broken ls or spurious files in the folder).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM