vimrc 需要修复/重写

vimrc needs fixing / rewriting

我需要帮助来尝试修复我的 .vimrc 文件,它在 .vimrc 中获取任何设置或安装插件 寻求帮助重写我的 vimrc

我安装 vim-plug by 运行ning

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

当我 运行 在 vim

:PlugInstall

没有要安装的插件 按 ENTER 或键入命令继续

在我的 vimrc 文件中

"-------------------------------------------------------------------------------
"plugins
"-------------------------------------------------------------------------------
set nocompatible              " be iMproved, required
call plug#begin('~/.vim/plugged')
"text 2 speech
Plug 'vim-scripts/speech.vim'
" repeat stuff
Plug 'tpope/vim-repeat'
" surround
Plug 'tpope/vim-surround'
" better comments
Plug 'tpope/vim-commentary'
" auto set indent settings
Plug 'tpope/vim-sleuth'
" text navigation
Plug 'justinmk/vim-sneak'
" better syntax support
Plug 'sheerun/vim-polyglot'
" adds colour to [['(', ')'], ['[', ']'], ['{', '}']]
Plug 'junegunn/rainbow_parentheses.vim'
" auto pairs for '(' '[' '{'
Plug 'jiangmiao/auto-pairs'
" closetags
Plug 'alvan/vim-closetag'
" intellisense
Plug 'neoclide/coc.nvim', {'branch': 'release'}
"ctrl-p fuzzy file search
Plug 'kien/ctrlp.vim'
" fzf
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
"displays a preview of colors with css
Plug 'ap/vim-css-color'
" see what keys do like in emacs
Plug 'liuchengxu/vim-which-key'
" snippets
Plug 'honza/vim-snippets'
Plug 'mattn/emmet-vim'
call plug#end()
" source coc config
source ~/.vim/coc.vim
"-------------------------------------------------------------------------------
" Automatic installation of vim-plug, if it's not available
" ------------------------------------------------------------------------------
if empty(glob('~/.vim/autoload/plug.vim'))
    silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs 
                \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    autocmd VimEnter * PlugInstall --sync | source ~/.vimrc
endif
"-------------------------------------------------------------------------------
" Automatically install missing plugins on startup
"-------------------------------------------------------------------------------
autocmd VimEnter *
    \  if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
  \|   PlugInstall --sync | q
  \| endif
"-------------------------------------------------------------------------------
"general setting
"-------------------------------------------------------------------------------
let mapleader=" "                                               " set the leader to space
syntax on                                                               " enables syntax highlighing
colorscheme novum                                               " sets colorscheme to novum (which was copyed from https://raw.githubusercontent.com/dylnmc/novum.vim/master/colors/novum.vim)
set encoding=utf-8                                          " the encoding displayed
set mouse=a                                                         " enable your mouse
set smartindent                                                 " makes indenting smart
set autoindent                                                  " good auto indent
set spell spelllang=en_uk                               " sets spellcheck to english uk
set wildmode=longest,list,full                  " autocompletion
let g:sneak#prompt = "sneak>"                       " sets sneak prompt
set clipboard=unnamedplus                               ""copy paste bet ween vim and everything else"
set clipboard+=unnamedplus                          ""copy paste bet ween vim and everything else"
set shiftwidth=2 autoindent smartindent tabstop=2 softtabstop=2 expandtab
"-------------------------------------------------------------------------------
" wsl yank support
"-------------------------------------------------------------------------------
let s:clip = '/mnt/c/windows/system32/clip.exe'  " change this path according to your mount point
if executable(s:clip)
    augroup wslyank
        autocmd!
        autocmd textyankpost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
    augroup end
endif
"-------------------------------------------------------------------------------
"keymapping
"-------------------------------------------------------------------------------
nnoremap <silent> <c-s> :w<CR>                   " alternate way to save
nnoremap <silent> <c-q> :wq!<CR>                 " alternate way to quit
nnoremap <silent> <tab> :bnext<CR>           " tab in general mode will move to text buffer
nnoremap <silent> <s-tab> :bprevious<CR> " shift-tab will go back" shift-tab will go back
nmap <tab> :tabnext<CR>                                  " simulate same tab behavior in vscode
nmap <s-tab> :tabprev<CR>                                " simulate same tab behavior in vscode
map <leader>o :!clear && shellcheck %<CR>" shell check
nnoremap <leader>r <nop>                                 " unmap text2speach speechtotext
nmap <c-/> <plug>commentaryline                  "vm-commentary keymapps like vscode
nmap <leader>. :tabnew<CR>                           " open a file in a new tab
nmap <leader>e :coccommand explorer<CR>  " opens coc-file explorer
"inoremap <silent> <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
"function
"-------------------------------------------------------------------------------
function! NumberToggle()                                 " the function toggles between absolute and hybrid line numbers
    if(&rnu == 1)
        set nornu                                                        " turn relative line numbers off
        set nu                                                           " turn absolute line numbers on
    else
        set nu rnu                                                   " turn hybrid line numbers on
    endif
endfunction
nnoremap <leader>n :call NumberToggle()<CR>
"--------------------------------------------------------------------------------
" Enable true color to make sure terminal themes are ingored
if exists('+termguicolors')
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
    set termguicolors
endif
"------------------------------------------------------------------------------
" Automatically deletes all trailing whitespace and newlines at end of file on save.
    autocmd BufWritePre * %s/\s\+$//e
    autocmd BufWritepre * %s/\n\+\%$//e
"-----------------------------------------------------------------------------

当我 运行 vim 我得到 vim~/.vimrc

Error detected while processing /home/bob/.vimrc:
line    5:
E488: Trailing characters
line    7:
E116: Invalid arguments for function plug#
line    9:
E116: Invalid arguments for function plug#
line   11:
E116: Invalid arguments for function plug#
line   13:
E116: Invalid arguments for function plug#
line   15:
E116: Invalid arguments for function plug#
line   17:
E116: Invalid arguments for function plug#
line   19:
E116: Invalid arguments for function plug#
line   21:
E116: Invalid arguments for function plug#
line   23:
E116: Invalid arguments for function plug#
line   25:
E116: Invalid arguments for function plug#
line   27:
E116: Invalid arguments for function plug#
line   29:
E116: Invalid arguments for function plug#
line   31:
E116: Invalid arguments for function plug#
line   32:
E116: Invalid arguments for function plug#
line   34:
E116: Invalid arguments for function plug#
line   36:
E116: Invalid arguments for function plug#
line   38:
E116: Invalid arguments for function plug#
line   39:
E116: Invalid arguments for function plug#
line   40:
E488: Trailing characters
line   42:
E484: Can't open file /home/bob/.vim/coc.vim^M
line   46:
E15: Invalid expression: empty(glob('~/.vim/autoload/plug.vim'))^M
line  122:
E171: Missing :endif
Press ENTER or type command to continue

vim --版本

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 18 2020 18:29:15)
Included patches: 1-1453
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl               +farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    +tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
+balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +timers
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          +toolbar
+cindent           +insert_expand     +path_extra        +user_commands
+clientserver      +job               +perl              +vertsplit
+clipboard         +jumplist          +persistent_undo   +virtualedit
+cmdline_compl     +keymap            +postscript        +visual
+cmdline_hist      +lambda            +printer           +visualextra
+cmdline_info      +langmap           +profile           +viminfo
+comments          +libcall           -python            +vreplace
+conceal           +linebreak         +python3           +wildignore
+cryptv            +lispindent        +quickfix          +wildmenu
+cscope            +listcmds          +reltime           +windows
+cursorbind        +localmap          +rightleft         +writebackup
+cursorshape       +lua               +ruby              +X11
+dialog_con_gui    +menu              +scrollbind        -xfontset
+diff              +mksession         +signs             +xim
+digraphs          +modify_fname      +smartindent       +xpm
+dnd               +mouse             +startuptime       +xsmp_interact
-ebcdic            +mouseshape        +statusline        +xterm_clipboard
+emacs_tags        +mouse_dec         -sun_workshop      -xterm_save
+eval              +mouse_gpm         +syntax
+ex_extra          -mouse_jsbterm     +tag_binary
+extra_search      +mouse_netterm     +tag_old_static

当我获取 .vimrc

.vimrc:1: command not found: -------------------------------------------------------------------------------^M\nplugins^M
.vimrc:3: command not found: -------------------------------------------------------------------------------^M\nset nocompatible
.vimrc:5: bad pattern: plug#begin(~/.vim/plugged)^M
.vimrc:6: no such file or directory: text 2 speech^M\nPlug 'vim-scripts/speech.vim'^M\n
.vimrc:9: command not found: Plug
.vimrc:10: no such file or directory:  surround^M\nPlug 'tpope/vim-surround'^M\n
.vimrc:13: command not found: Plug
.vimrc:14: no such file or directory:  auto set indent settings^M\nPlug 'tpope/vim-sleuth'^M\n
.vimrc:17: command not found: Plug
.vimrc:18: bad pattern: [[(,
.vimrc:21: command not found: Plug
.vimrc:22: no such file or directory:  auto pairs for '(' '[' '{'^M\nPlug 'jiangmiao/auto-pairs'^M\n
.vimrc:25: command not found: Plug
.vimrc:26: no such file or directory:  intellisense^M\nPlug 'neoclide/coc.nvim', {'branch': 'release'}^M\nctrl-p
.vimrc:29: command not found: Plug
.vimrc:30: no such file or directory:  fzf^M\nPlug 'junegunn/fzf', { 'do': { -> fzf#install() } }^M\nPlug 'junegunn/fzf.vim'^M\ndisplays
.vimrc:34: command not found: Plug
.vimrc:35: no such file or directory:  see what keys do like in emacs^M\nPlug 'liuchengxu/vim-which-key'^M\n
.vimrc:38: command not found: Plug
.vimrc:39: command not found: Plug
.vimrc:41: no such file or directory:  source coc config^M\nsource ~/.vim/coc.vim^M\n-------------------------------------------------------------------------------^M
.vimrc:44: command not found:  Automatic installation of vim-plug, if it's not available^M\n
.vimrc:88: parse error near `<'

我不使用 windows 所以我可能是错的。 尝试禁用 vimrc 末尾的最后两个 autocmd,它可能会在保存时弄乱文件,看起来这就是你的问题。

错误 ^M 字符在每一行的末尾,这意味着 vim 正在读取文件格式为 dos(windows)

要解决此问题,请将以下内容添加到您的 vimrc

fileformat=unix