{"id":51726,"date":"2023-05-30T10:09:41","date_gmt":"2023-05-30T02:09:41","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=51726"},"modified":"2023-05-30T10:09:41","modified_gmt":"2023-05-30T02:09:41","slug":"compatibility-mode-vim","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/compatibility-mode-vim.html","title":{"rendered":"Vim \u7f16\u8f91\u5668\u7684\u517c\u5bb9\u6a21\u5f0f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u76ee\u524d\uff0c\u5728\u6211\u4eec\u8bb2\u8ff0 Vim \u7684\u6559\u7a0b\u4e2d\uff0c\u8ba8\u8bba\u8fc7\u7f16\u8f91\u5668\u7684\u6a21\u5f0f\u884c\uff08<\/rp>Modeline<\/rt>\uff09<\/rp><\/ruby>\u529f\u80fd\u4ee5\u53ca\u600e\u6837\u7528\u63d2\u4ef6\u6765\u6269\u5c55 Vim \u7684\u529f\u80fd\u96c6\u3002\u53ef\u6b63\u5982\u6211\u4eec\u6240\u77e5\uff0cVim \u63d0\u4f9b\u4e86\u975e\u5e38\u591a\u7684\u5185\u7f6e\u529f\u80fd\uff1a\u56e0\u6b64\u5728\u672c\u6559\u7a0b\u4e2d\u66f4\u8fdb\u4e00\u6b65\uff0c\u6211\u4eec\u6765\u8c08\u8c08\u5728\u8be5\u7f16\u8f91\u5668\u542f\u52a8\u65f6\u7684\u53ef\u7528\u6a21\u5f0f\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"Vim<\/p>\n

\u4f46\u5728\u6211\u4eec\u5f00\u59cb\u4e4b\u524d\uff0c\u8bf7\u6ce8\u610f\u5728\u672c\u6559\u7a0b\u4e2d\u63d0\u53ca\u7684\u6240\u6709\u4f8b\u5b50\u3001\u547d\u4ee4\u53ca\u7528\u6cd5\u8bf4\u660e\u90fd\u662f\u5728 Ubuntu 14.04 \u4e0a\u6d4b\u8bd5\u7684\uff0c\u6211\u4eec\u6d4b\u8bd5\u7528\u7684 Vim \u7248\u672c\u662f 7.4 \u3002<\/p>\n

Vim \u4e2d\u7684\u517c\u5bb9\u6a21\u5f0f\u4e0e\u4e0d\u517c\u5bb9\u6a21\u5f0f<\/strong><\/div>\n

\u4e3a\u4e86\u66f4\u597d\u7406\u89e3\u4e0a\u8ff0\u7684 Vim \u6a21\u5f0f\uff0c\u4f60\u6709\u5fc5\u8981\u5148\u53bb\u4e86\u89e3\u4e0b\u6b64\u7f16\u8f91\u5668\u521d\u59cb\u5316\u8fc7\u7a0b\u7684\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\u3002<\/p>\n

\u7cfb\u7edf\u7ea7\u53ca\u672c\u5730 vimrc \u6587\u4ef6<\/strong><\/span><\/div>\n

\u5f53 Vim \u542f\u52a8\u65f6\uff0c\u7f16\u8f91\u5668\u4f1a\u53bb\u641c\u7d22\u4e00\u4e2a\u7cfb\u7edf\u7ea7\u7684 vimrc \u6587\u4ef6\u6765\u8fdb\u884c\u7cfb\u7edf\u8303\u56f4\u5185\u7684\u9ed8\u8ba4\u521d\u59cb\u5316\u5de5\u4f5c\u3002<\/p>\n

\u8fd9\u4e2a\u6587\u4ef6\u901a\u5e38\u5728\u4f60\u7cfb\u7edf\u91cc $VIM\/vimrc<\/span> \u7684\u8def\u5f84\u4e0b\uff0c\u5982\u679c\u6ca1\u5728\u90a3\u91cc\uff0c\u90a3\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728 Vim \u91cc\u9762\u8fd0\u884c :version<\/span>\u547d\u4ee4\u6765\u627e\u5230\u5b83\u7684\u6b63\u786e\u5b58\u653e\u4f4d\u7f6e\u3002\u6bd4\u5982\u8bf4\uff0c\u5728\u6211\u8fd9\u91cc\uff0c\u8fd9\u4e2a\u547d\u4ee4\u7684\u76f8\u5173\u90e8\u5206\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

...\r\n...\r\n...\r\nsystem vimrc file: \"$VIM\/vimrc\"\r\nuser vimrc file: \"$HOME\/.vimrc\"\r\n2nd user vimrc file: \"~\/.vim\/vimrc\"\r\nuser exrc file: \"$HOME\/.exrc\"\r\nfall-back for $VIM: \"\/usr\/share\/vim\"\r\n...\r\n...\r\n...\r\n<\/pre>\n

\u53ef\u4ee5\u770b\u5230\u90a3\u4e2a\u7cfb\u7edf vimrc \u6587\u4ef6\u786e\u5b9e\u4f4d\u4e8e $VIM\/vimrc<\/span> \uff0c\u4f46\u6211\u68c0\u67e5\u4e86\u6211\u673a\u5b50\u4e0a\u6ca1\u8bbe\u7f6e\u8fc7$VIM<\/span> \u73af\u5883\u53d8\u91cf\u3002\u6240\u4ee5\u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc - \u6b63\u5982\u4f60\u5728\u4e0a\u9762\u7684\u8f93\u51fa\u6240\u770b\u5230\u7684 - $VIM \u5728\u6211\u8fd9\u7684\u8def\u5f84\u662f\u00a0\/usr\/share\/vim<\/span>\uff0c\u662f\u4e00\u4e2a\u56de\u843d\u503c\uff08LCTT \u8bd1\u6ce8\uff1a\u5373\u5982\u679c\u524d\u9762\u5931\u8d25\u7684\u8bdd\uff0c\u6700\u7ec8\u91c7\u7528\u7684\u7ed3\u679c\uff09\u3002\u4e8e\u662f\u6211\u8bd5\u7740\u5728\u8fd9\u4e2a\u8def\u5f84\u5bfb\u627e vimrc \uff0c\u6211\u770b\u5230\u8fd9\u4e2a\u6587\u4ef6\u662f\u5b58\u5728\u7684\u3002\u5982\u4e0a\u5373\u662f\u6211\u7684\u7cfb\u7edf vimrc \u6587\u4ef6\uff0c\u5c31\u5982\u524d\u9762\u63d0\u8fc7\u7684\u90a3\u6837 - \u5b83\u5728 Vim \u542f\u52a8\u65f6\u4f1a\u88ab\u8bfb\u53d6\u3002<\/p>\n

\u5728\u8fd9\u4e2a\u7cfb\u7edf\u7ea7 vimrc \u6587\u4ef6\u88ab\u8bfb\u53d6\u89e3\u6790\u5b8c\u540e\uff0c\u7f16\u8f91\u5668\u4f1a\u67e5\u627e\u4e00\u4e2a\u7528\u6237\u7279\u5b9a\u7684\uff08\u6216\u8005\u8bf4\u672c\u5730\u7684\uff09vimrc \u6587\u4ef6\u3002\u8fd9\u4e2a\u672c\u5730 vimrc \u7684\u641c\u7d22\u987a\u5e8f\u662f\uff1a\u73af\u5883\u53d8\u91cf VIMINIT<\/span>\u3001$HOME\/.vimrc<\/span>\u3001\u73af\u5883\u53d8\u91cf EXINIT<\/span>\uff0c \u548c\u4e00\u4e2a\u53eb exrc<\/span>\u7684\u6587\u4ef6\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u4f1a\u5b58\u5728\u00a0$HOME\/.vimrc<\/span>\u6216 ~\/.vimrc<\/span>\u8fd9\u6837\u7684\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u53ef\u770b\u4f5c\u662f\u672c\u5730 vimrc\u3002<\/p>\n

\u6211\u4eec\u8c08\u8bba\u7684\u662f\u4ec0\u4e48\u517c\u5bb9\u6027<\/strong><\/span><\/div>\n

<\/p>\n

\u5c31\u50cf\u6211\u4eec\u8c08\u8bba Vim \u7684\u517c\u5bb9\u6027\u6a21\u5f0f\u548c\u4e0d\u517c\u5bb9\u6027\u6a21\u5f0f\u90a3\u6837\uff0c\u8fd9\u4e9b\u6a21\u5f0f\u7684\u5f00\u542f\u548c\u7981\u7528\u4f1a\u505a\u51fa\u4ec0\u4e48\u6837\u7684\u517c\u5bb9\u6027\u4e5f\u503c\u5f97\u4e86\u89e3\u3002\u8981\u4e86\u89e3\u8fd9\u4e9b\uff0c\u5148\u8981\u77e5\u9053 Vim \u662f V<\/strong>IM<\/strong>proved \u7684\u7f29\u5199\uff0c\u50cf\u8fd9\u4e2a\u5168\u540d\u6697\u793a\u7684\u90a3\u6837\uff0cVim \u7f16\u8f91\u5668\u662f Vi \u7f16\u8f91\u5668\u7684\u6539\u8fdb\u7248\u3002<\/p>\n

\u7ecf\u8fc7\u6539\u8fdb\u610f\u5473\u7740 Vim \u7684\u529f\u80fd\u96c6\u6bd4 Vi \u7684\u66f4\u5927\u3002<\/p>\n

\u5f53\u8c08\u8bba Vim \u7684\u517c\u5bb9\u548c\u4e0d\u517c\u5bb9\u6a21\u5f0f\u65f6\uff0c\u6211\u4eec\u6240\u8bf4\u7684\u517c\u5bb9\u6027\u662f\u6307 Vim \u517c\u5bb9 Vi\u3002\u5728\u517c\u5bb9\u6a21\u5f0f\u4e0b\u8fd0\u884c\u65f6\uff0cVim \u5927\u90e8\u5206\u589e\u5f3a\u53ca\u6539\u5584\u7684\u529f\u80fd\u5c31\u4e0d\u53ef\u7528\u4e86\u3002\u4e0d\u7ba1\u600e\u6837\uff0c\u8981\u8bb0\u4f4f\u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0cVim \u5e76\u4e0d\u80fd\u7b80\u5355\u7b49\u540c Vi - \u6b64\u6a21\u5f0f\u53ea\u662f\u8bbe\u5b9a\u4e00\u4e9b\u7c7b\u4f3c Vi \u7f16\u8f91\u5668\u5de5\u4f5c\u65b9\u5f0f\u7684\u9ed8\u8ba4\u9009\u9879\u3002<\/p>\n

\u4e0d\u517c\u5bb9\u6a21\u5f0f - \u4e0d\u7528\u591a\u8bf4 - \u4f7f\u5f97 Vim \u7528\u8d77\u6765\u8ddf Vi \u4e0d\u517c\u5bb9\uff0c\u4e5f\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u7528\u5230\u5b83\u7684\u6240\u6709\u589e\u5f3a\u3001\u6539\u5584\u53ca\u7279\u5f81\u3002<\/p>\n

\u600e\u4e48\u542f\u7528\/\u7981\u7528\u8fd9\u4e9b\u6a21\u5f0f\uff1f<\/strong><\/span><\/div>\n

\u5728 Vim \u4e2d\u5c1d\u8bd5\u8fd0\u884c :help compatible<\/span> \u547d\u4ee4\uff0c\u63a5\u7740\u4f60\u4f1a\u770b\u5230\u5982\u4e0b\u8bed\u6cd5\uff1a<\/p>\n

'compatible' 'cp' boolean (\u9ed8\u8ba4\u5f00\u542f \uff0c\u5f53 |vimrc| \u6216 |gvimrc| \u5b58\u5728\u65f6\u5173\u95ed)\r\n<\/pre>\n

\u63cf\u8ff0\u4e2d\u8bf4\u5230\u517c\u5bb9\u6a21\u5f0f\u9ed8\u8ba4\u5f00\u542f\u7684\uff0c\u4e0d\u8fc7\u5f53 vimrc \u6587\u4ef6\u5b58\u5728\u65f6\u4f1a\u5173\u95ed\u3002\u4f46\u8bf4\u7684\u662f\u54ea\u79cd vimrc \u6587\u4ef6\u5462\uff1f\u7b54\u6848\u662f\u672c\u5730 vimrc\u3002\u6df1\u5165\u7814\u7a76\u4e0b\u00a0:help compatible<\/span>\u00a0\u547d\u4ee4\u7ed9\u51fa\u7684\u8be6\u60c5\uff0c\u4f60\u4f1a\u53d1\u73b0\u4e0b\u9762\u5185\u5bb9\u8bf4\u5f97\u66f4\u6e05\u695a:
\n\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u610f\u5473\u7740\u5f53\u4e00\u4e2a |vimrc| \u6216 |gvimrc| \u6587\u4ef6\u5b58\u5728\u65f6\uff0cVim \u4f1a\u7528\u9ed8\u8ba4\u7684 Vim\uff0c\u5426\u5219\u5b83\u4f1a\u7528 Vi \u9ed8\u8ba4\u7684\u3002\uff08\u6ce8\uff1a\u5982\u679c\u7cfb\u7edf\u7ea7\u7684 vimrc \u6216 gvimrc \u6587\u4ef6\u4e2d\u5e26\u6709 |-u| \u53c2\u6570\uff0c\u5219\u4e0d\u4f1a\u8fd9\u6837\u3002\uff09\u3002
\n\u90a3\u4e48\u5728 Vim \u542f\u52a8\u65f6\uff0c\u5b9e\u9645\u4e0a\u8fdb\u884c\u7684\u52a8\u4f5c\u662f\uff0c\u9996\u5148\u4f1a\u89e3\u6790\u7cfb\u7edf vimrc \u6587\u4ef6 - \u5728\u8fd9\u65f6\u5904\u4e8e\u517c\u5bb9\u6027\u6a21\u5f0f\u9ed8\u8ba4\u5f00\u542f\u72b6\u6001\u3002\u73b0\u5728\uff0c\u65e0\u8bba\u4f55\u65f6\u53d1\u73b0\u4e00\u4e2a\u7528\u6237\uff08\u6216\u6210\u4e3a\u672c\u5730\uff09 vimrc \uff0c\u4e0d\u517c\u5bb9\u6a21\u5f0f\u90fd\u4f1a\u6253\u5f00\u3002:help compatible-default<\/span>\u547d\u4ee4\u8bf4\u7684\u5f88\u6e05\u695a\uff1a
\n\u5728 Vim \u542f\u52a8\u65f6\uff0c\u2018compatible\u2019\u9009\u9879\u662f\u6253\u5f00\u7684\u3002\u8fd9\u5c06\u5728 Vim \u5f00\u59cb\u521d\u59cb\u5316\u65f6\u5e94\u7528\u3002\u4f46\u662f\u4e00\u65e6\u4e4b\u540e\u53d1\u73b0\u7528\u6237\u7ea7 vimrc \u6587\u4ef6\uff0c\u6216\u5728\u5f53\u524d\u76ee\u5f55\u6709\u4e00\u4e2a vimrc \u6587\u4ef6\uff0c\u6291\u6216\u662f VIMINIT<\/span>\u73af\u5883\u53d8\u91cf\u5df2\u8bbe\u7f6e\uff0cVim \u5c31\u4f1a\u88ab\u8bbe\u4e3a\u4e0d\u517c\u5bb9\u6a21\u5f0f\u3002
\n\u5047\u5982\u4f60\u60f3\u65e0\u89c6\u9ed8\u8ba4\u7684\u884c\u4e3a\uff0c\u8981\u5728\u7f16\u8f91\u5668\u5f00\u59cb\u89e3\u6790\u7cfb\u7edf vimrc \u6587\u4ef6\u65f6\u6253\u5f00\u4e0d\u517c\u5bb9\u6a21\u5f0f\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u5982\u4e0b\u547d\u4ee4\u5230\u90a3\u4e2a\u6587\u4ef6\u7684\u5f00\u5934\u6765\u5b8c\u6210\u8fd9\u4e2a\u64cd\u4f5c\u3002<\/p>\n

:set nocompatible\r\n<\/pre>\n
\u5176\u4ed6\u6709\u7528\u7ec6\u8282<\/strong><\/span><\/div>\n

\u8fd9\u513f\u662f\u4e00\u4e9b\u5173\u4e8e\u8fd9\u4e9b\u6a21\u5f0f\u7684\u66f4\u6709\u7528\u7684\u7ec6\u8282\uff1a
\n\u73b0\u5728\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a .vimrc \u6587\u4ef6\u6765\u8bbe\u7f6e\u6216\u91cd\u7f6e\u517c\u5bb9\u6027\u4f1a\u6709\u4e00\u4e2a\u526f\u4f5c\u7528\uff1a\uff08\u952e\u76d8\uff09\u6620\u5c04\uff08Mapping<\/span>\uff09\u5728\u89e3\u91ca\u7684\u65f6\u5019\u4f1a\u6709\u51b2\u7a81\u3002\u8fd9\u4f7f\u5f97\u5728\u7528\u8bf8\u5982\u56de\u8f66\u63a7\u5236\u7b26 <CR><\/span>\u7b49\u60c5\u51b5\u65f6\u4f1a\u6709\u5f71\u54cd\u3002\u5982\u679c\u6620\u5c04\u5173\u7cfb\u4f9d\u8d56\u4e8e\u517c\u5bb9\u6027\u7684\u67d0\u4e2a\u7279\u5b9a\u503c\uff0c\u5728\u7ed9\u51fa\u6620\u5c04\u524d\u8bbe\u7f6e\u6216\u8005\u91cd\u7f6e\u5b83\u3002<\/p>\n

\u4e0a\u8ff0\u884c\u4e3a\u80fd\u591f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u80fd\u8986\u76d6\uff1a<\/p>\n