vim配置日志
其他vim的配置项目
vim化做sublime
https://github.com/fatih/subvim
https://github.com/grigio/vim-sublime
字体
vim-plug
vim-plug是增强版的vundle,新支持:并行、动态加载插件,节约内存
教程:https://vim.ink/vim-plug.html
https://github.com/junegunn/vim-plug/wiki/tutorial
安装
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
配置插件
call plug#begin('~/.vim/plugged')
Plug 'junegunn/vim-easy-align'
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug '~/my-prototype-plugin'
call plug#end()
在Vim命令行模式下,使用命令 :PlugInstall
可安装vim配置文件中所有配置的vim插件;也可以使用 PlugInstall [name ...]
来指定安装某一个或某几个vim插件。
vim 插件
https://segmentfault.com/a/1190000014560645
好几种插件:https://www.zlovezl.cn/articles/vim-plugins-cannot-live-without/
https://www.jianshu.com/p/923aec861af3
全局搜索插件
快速grep工具目前有ack, ag, rg, pt, sift, ucg等。
搜索全局模糊搜索
目前LeaderF
最快最准确,依赖python(2019-5评)
在grep结果的基础上再通过模糊匹配的方式进行二次过滤
速度,准确度:ctrlp
< LeaderF
ctrlp
:快速打开文件或定位某个buffer、最近使用的文件(mru)、tags(包括函数、类、变量等);已经过时了(2019-5评)
LeaderF
:快速打开文件或定位某个buffer、最近使用的文件(mru)、tags(包括函数、类、变量等)、命令历史、文件中的某一行、vim的help、marks等等+跳转
fzf
:后端是fzf,需要另外安装
skim
文件内容搜索+跳转
速度:vimgrep
(vim自带的全局搜搜) <ack.vim
插件 <ag.vim
插件
ctrlsf
插件:支持 ack/ag/pt/rg 四种搜索后端,支持跳转,支持异步搜索(即搜索时不影响当前编辑)
推荐rg
- 速度和准确率: ack, pt < ag < rg (命令行下最快的文件内容搜索)
- rg支持Unicode,跨linux/windows/mac平台
2019年01月15日
vim有很多著名的grep插件,我使用过的有ack.vim,ag.vim和ctrlsf.vim,它们应该也是目前用户最多的几个了。
ack.vim
起步比较早,早期后端grep工具是ack,后来也支持ag(the_silver_searcher),pt(the_platinum_searcher),rg(ripgrep)等工具了。它是一个比较传统的grep插件,不支持异步,要等到grep结束后才能显示结果,在大的项目中grep会卡好一阵子。它貌似也不再维护,我N久前提交的pull request还挂在那,它最近的代码更新在11个月前。
ag.vim
它其实是抄袭ack.vim,没错,是抄袭。在早期ack.vim还不支持ag时,它的作者在ack.vim代码的基础上稍微改了改,支持了ag。后来被ack.vim的作者给怼了,就放弃了对ag.vim的维护。目前功能上小于ack.vim。
ctrlsf.vim
这是国人开发的一个插件, 后端grep工具支持ack/ag/pt/rg,同时也支持异步,不过需要Vim 8.0.1039+或者NeoVim才支持异步。这个插件很好用,在我开发Leaderf rg之前一直使用的是它。
作者:Sainnhepark
链接:https://www.zhihu.com/question/23590572/answer/546352496
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
异步Fuzzy Finder:
vim的fuzzy finder可不是只能像命令行里的fzf那样简单地fuzzy match,下面推荐的几个fuzzy finder插件你可以用它来:搜索字符串,对grep结果进行过滤(不需要其它grep插件了),浏览和跳转tags(不需要tagbar了),浏览、跳转以及管理buffer、files,跳转最近使用的文件(MRU),搜索历史剪切板内容,切换color scheme,甚至浏览你的github星标版本库。denite.nvim
最高的可定制度,最高的可扩展性,最多的source,也最不好上手。依赖python。fzf.vim
开箱即用,新手友好,无需太多配置,source也足够多。但它实际上fzf的一个vim前端,并不是一个典型的vim插件,你需要安装fzf才能使用,不过也正是因为如此,它用起来非常丝滑。另外它缺乏官方文档,可定制度也较差。不依赖python。LeaderF
开箱即用,新手友好,无需太多配置。它的算法非常厉害(个人觉得只有fzy能和它比),另外它也提供了很多非常实用的选项(比如正则过滤),但是source相比前两者较少。依赖python。2018.12.20
最近的一个32万行代码的模糊匹配测试中,对下面几个模糊匹配工具进行了测试:
leaderf, fzf, skim, ctrlp的默认matcher, denite的默认matcher,cpsm(denite和ctrlp的matcher之一), fruzzy(denite和ctrlp的matcher之一)
按匹配精准度和匹配速度来衡量它们的性能的话,leaderf的表现是最好的。
Note: leaderf的关键部分是用c写的另外,关于ctrlp。ctrlp已经有了异步模式,但是它的性能和leaderf, fzf不在一个档次,并且群里有大佬说它的异步还有很多bug。
如果你的vim没有python支持,个人推荐用fzf
搜索后端的安装/卸载方法
ag (又名 the_silver_searcher)
# mac 安装 ag
brew install the_silver_searcher
# mac 卸载 ag
brew uninstall the_silver_searcher
ack
# mac 安装 ack
brew install ack
# mac 卸载 ack
brew uninstall ack
rg
参加 安装rg的方法
- mac
# mac 安装 rg
brew install ripgrep
# mac 卸载 rg
brew uninstall ripgrep
-
Unbuntu
sudo apt install ripgrep
若报错曰apt没有找到ripgrep包
则先执行
sudo add-apt-repository ppa:x4121/ripgrep sudo apt-get update sudo apt install ripgrep
-
Debian 及其派生( 如 Ubuntu)
https://gist.github.com/kostaz/6e0cf1eee35a34cd6589ec15b58e682c
https://segmentfault.com/a/1190000016170184
curl -LO https://github.com/BurntSushi/ripgrep/releases/download/11.0.1/ripgrep_11.0.1_amd64.deb
sudo dpkg -i ripgrep_11.0.1_amd64.deb
上述release最新版本见https://github.com/BurntSushi/ripgrep/releases
LeaderF
https://zhuanlan.zhihu.com/p/53680291
https://github.com/Yggdroot/LeaderF
使用教程http://www.manongjc.com/article/94716.html
gtags功能:https://learnku.com/articles/28249
- MAC上面使用homebrew安装gtags
brew install global
1. LeaderF 介绍
LeaderF 是一个问世很长时间的 Vim 插件了,可是我直到最近才发现它,大有相见恨晚之感。它的基本功能是提供了文件、buffers、mrus(most recently used)、tags 的检索,速度很快且是异步查找。检索过程中支持正则表达式、模糊匹配,并可以实时的过滤结果。
LeaderF 是用 Python 实现的,因此需要 Vim 支持 Python Feature。可以通过 vim –version 来查看是否支持 Python。
3. 常用功能
- 检索文件:
<leader>f
- 检索 buffer:
<leader>b
- 在 LeaderF 运行起来以后(在正常检索的模式下),可以执行下面的一些操作:
<C-C>, <ESC> : 退出 LeaderF.
<C-R> : 在模糊匹配和正则式匹配之间切换
<C-F> : 在全路径搜索和名字搜索之间切换
<Tab> : 在检索模式和选择模式之间切换
<C-J>, <C-K> : 在结果列表里选择
<C-X> : 在水平窗口打开
<C-]> : 在垂直窗口打开
<C-T> : 在新标签打开
<C-P> : 预览结果
- 在 LeaderF 检索文件的模式下,如果按 Tab 进入选择列表之后,会有其他的快捷键,可以通过 F1 来查看。
- 集成 ripgrep 进行检索是 LeaderF 很强大的一个功能,rg 是异步的,比 vimgrep 要好很多。而且,对结果可以进行二次过滤:
:LeaderfRgRecall 显示上次 rg 的结果
:Leaderf rg 实时检索
:Leaderf rg [option] 后面的 [option] 和 rg 的语法保持一致
4. 参考资料
- 可以在 vim 中使用 :help LeaderF 来查看其帮助文档。
- LeaderF rg 介绍
- ripgrep
- rg 路径匹配语法:
Standard Unix-style glob syntax is supported:
? matches any single character. (If the literal_separator option is enabled, then ? can never match a path separator.)
* matches zero or more characters. (If the literal_separator option is enabled, then * can never match a path separator.)
** recursively matches directories but are only legal in three situations. First, if the glob starts with **/, then it matches all directories. For example, **/foo matches foo and bar/foo but not foo/bar. Secondly, if the glob ends with /**, then it matches all sub-entries. For example, foo/** matches foo/a and foo/a/b, but not foo. Thirdly, if the glob contains /**/ anywhere within the pattern, then it matches zero or more directories. Using ** anywhere else is illegal (N.B. the glob ** is allowed and means "match everything").
{a,b} matches a or b where a and b are arbitrary glob patterns. (N.B. Nesting {...} is not currently allowed.)
[ab] matches a or b where a and b are characters. Use [!ab] to match any character except for a and b.
Metacharacters such as * and ? can be escaped with character class notation. e.g., [*] matches *.
git插件
Vim Gitgutter
http://developer.51cto.com/art/201902/592448.htm
Vim Gitgutter 插件对使用 Git 作为版本控制工具的人来说非常有用。它会在 Vim 的行号列旁显示 git diff
的差异标记。假设你有如下已提交过的代码:
另外,Vim Gitgutter 允许你用 [c
和 ]c
在多个有修改的块之间跳转,甚至可以用 Leader+hs
来暂存某个变更集。
Fugitive.vim 教程
http://vimcasts.org/episodes/fugitive-vim-working-with-the-git-index/
Vim Fugitive 是另一个将 Git 工作流集成到 Vim 中的超棒插件。它对 Git 做了一些封装,可以让你在 Vim 里直接执行 Git 命令并将结果集成在 Vim 界面里。这个插件有超多的特性,更多信息请访问它的 GitHub 项目页面。
这里有一个使用 Vim Fugitive 的基础 Git 工作流示例。设想我们已经对下面的 Go 代码做出修改,你可以用 :Gblame
调用 git blame
来查看每行最后的提交信息:
nerdtree-git-plugin
在目录树中显示 git 状态,依赖于 The NERD Tree
可改变显示符号:
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ "Unknown" : "?"
\ }
Surround
使用教程 https://gist.github.com/wilon/ac1fc66f4a79e7b0c161c80877c75c94
YCM编译报错
Your C++ compiler does NOT fully support C++17.
Ubuntu18, 2020-11-30, 编译ycm (哈希 4496153, 2020-11-27) 时报错如下,
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:232 (message):
Your C++ compiler does NOT fully support C++17.
-- Configuring incomplete, errors occurred!
See also "/tmp/ycm_build__rb87zu9/CMakeFiles/CMakeOutput.log".
ERROR: the build failed.
NOTE: it is *highly* unlikely that this is a bug but rather
that this is a problem with the configuration of your system
or a missing dependency. Please carefully read CONTRIBUTING.md
and if you're sure that it is a bug, please raise an issue on the
issue tracker, including the entire output of this script
and the invocation line used to run it.
原因: gcc和g++版本太低, 对策: 升级到至少8.0以上
which gcc; ls -l $(which gcc)
which g++; ls -l $(which g++)
/usr/bin/gcc
lrwxrwxrwx 1 root root 21 Nov 30 20:23 /usr/bin/gcc -> /etc/bin/gcc-7
/usr/bin/g++
lrwxrwxrwx 1 root root 21 Nov 30 20:23 /usr/bin/g++ -> /etc/bin/gcc-7
gcc –version
g++ –version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright © 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.g+±7 (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright © 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
安装高版本的gcc和g++
sudo apt-get install gcc-8 g++-8
更换gcc和g++的链接
linux 软件版本切换命令 update-alternatives 使用心得
ubuntu系统使用update-alternatives 管理多版本gcc/g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 50 --slave /usr/bin/g++ g++ /usr/bin/g++-8
而后 /usr/bin/gcc -> /etc/alternatives/gcc -> /usr/bin/gcc-8, /usr/bin/g++ -> /etc/alternatives/g++ -> /usr/bin/g+±8
编译ycm能成功
报错cregex" does not appear to contain CMakeLists.txt.
编译ycm时报错如下,但依旧可以使用ycm,可以无需按tab就显示自动补全下拉菜单
Searching Python 3.7 libraries...
Found Python library: /home/haoyu/ENV/localENV/anaconda3/lib/libpython3.7m.so
Found Python headers folder: /home/haoyu/ENV/localENV/anaconda3/include/python3.7m
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonLibs: /home/haoyu/ENV/localENV/anaconda3/lib/libpython3.7m.so (found suitable version "3.7.3", minimum required is "3.5")
-- NOT using libclang, no semantic completion for C/C++/ObjC will be available
-- NOT using clang-tidy for static analysis.
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/ycm_build_mdfikwuq
Scanning dependencies of target BoostParts
[ 2%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/unique_path.cpp.o
[ 4%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/path_traits.cpp.o
[ 7%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/portability.cpp.o
[ 9%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/operations.cpp.o
[ 11%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/windows_file_codecvt.cpp.o
[ 14%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/codecvt_error_category.cpp.o
[ 16%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/utf8_codecvt_facet.cpp.o
[ 19%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/path.cpp.o
[ 21%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/static_mutex.cpp.o
[ 23%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex_traits_defaults.cpp.o
[ 26%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex_debug.cpp.o
[ 30%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/posix_api.cpp.o
[ 30%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/cregex.cpp.o
[ 33%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/cpp_regex_traits.cpp.o
[ 35%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/winstances.cpp.o
[ 38%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/instances.cpp.o
[ 40%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/usinstances.cpp.o
[ 42%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/c_regex_traits.cpp.o
[ 45%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/wc_regex_traits.cpp.o
[ 47%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex_raw_buffer.cpp.o
[ 50%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/fileiter.cpp.o
[ 52%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex.cpp.o
[ 54%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/icu.cpp.o
[ 57%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/wide_posix_api.cpp.o
[ 59%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/w32_regex_traits.cpp.o
[ 61%] Linking CXX static library libBoostParts.a
[ 61%] Built target BoostParts
Scanning dependencies of target ycm_core
[ 64%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Word.cpp.o
[ 66%] Building CXX object ycm/CMakeFiles/ycm_core.dir/PythonSupport.cpp.o
[ 71%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePoint.cpp.o
[ 71%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Character.cpp.o
[ 73%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Candidate.cpp.o
[ 76%] Building CXX object ycm/CMakeFiles/ycm_core.dir/versioning.cpp.o
[ 78%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePointRepository.cpp.o
[ 80%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierCompleter.cpp.o
[ 83%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CandidateRepository.cpp.o
[ 85%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Utils.cpp.o
[ 88%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ycm_core.cpp.o
[ 90%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierDatabase.cpp.o
[ 92%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CharacterRepository.cpp.o
[ 95%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierUtils.cpp.o
[ 97%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Result.cpp.o
[100%] Linking CXX shared library /home/haoyu/ENV/localENV/app_config/vim_plug/YouCompleteMe/third_party/ycmd/ycm_core.so
[100%] Built target ycm_core
CMake Error: The source directory "/home/haoyu/ENV/localENV/app_config/vim_plug/YouCompleteMe/third_party/ycmd/third_party/cregex" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
ERROR: the build failed.
NOTE: it is *highly* unlikely that this is a bug but rather
that this is a problem with the configuration of your system
or a missing dependency. Please carefully read CONTRIBUTING.md
and if you're sure that it is a bug, please raise an issue on the
issue tracker, including the entire output of this script
and the invocation line used to run it.
这是因为子模块third_party/ycmd/third_party/cregex
被改动了,里面没有包含CMakeLists.txt.
,故而无法编译。
对策:重新git clone
cregex
cd ~/.vim/plugged/YouCompleteMe
rm -rf third_party/ycmd/third_party/cregex
git clone https://github.com/ycm-core/regex.git third_party/ycmd/third_party/cregex
其中https://github.com/ycm-core/regex.git
取自 ~/.vim/vim_plug/YouCompleteMe/third_party/ycmd/.gitmodules
中的third_party/cregex
对应的url。
而后手动编译ycm会成功
./install.py
报错 Unexpected exit code -11
vim开启立即底栏报错
The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). Unexpected exit code -11. Type ':YcmToggleLogs ycmd_50129_stderr_riih2wlh.log' to check the logs.
且无法使用ycm,这是因为conda安装的python 常常不兼容 YCM所用的预编译 libclang
对策:
- 在
YouCompleteMe/
下,用非conda的python进行手动编译
[非conda的python] install.py
# 如 /usr/bin/python install.py # mac系统自带的python2
# 或 /usr/local/bin/python3 install.py # 2020年2月开始, YCM已经报警, 即将不支持python2编译, 故用此python3
此python3此homebrew所装
/usr/local/bin/python3
->
/usr/local/Cellar/python/3.7.3/bin/python3
->
/usr/local/Frameworks/Python.framework/Versions/3.7/bin/python3
->
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/bin/python3
->
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/bin/python3.7
->
其中 /usr/local/Frameworks/Python.framework/Versions
-> /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7
- 若必想用conda的python来编辑,则需在
.ycm_extra_conf.py
中任意处添加以下代码,来指定interpreter_path
为conda的python,如
def Settings(**kwargs):
return {
'interpreter_path': '/path/to/anaconda/python'
}
而后在./install.py
以编译。
详见 the Python Semantic Completion section
YouCompleteMe 插件 MacOS 安装
https://www.jianshu.com/p/edc4bbed92ca
brew install cmake
然后在 /.vimrc
文件中加入
Plug 'Valloric/YouCompleteMe', {'do':'python3 install.py'}
手动编译ycm
- mac上
brew install cmake
./install.py
- linux上
sudo apt-get install cmake
sudo apt-get install build-essential
sudo apt-get install python python-dev
apt-get install llvm-3.9 clang-3.9 libclang-3.9-dev libboost-all-dev # 如果不需要 C 家族的语义化补全,则可跳过这一步
./install.py
python3 ./install.py
报错CMake Error; cmake:61 (message):
环境
时间:2019-12-7
系统环境
- 服务器:实验室集群的
cpu3
- 系统:Ubuntu 14.04.6 LTS
- cmake:
/usr/bin/cmake -v
cmake version 2.8.12.2 - gcc:
/usr/bin/gcc -v
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4) - g++:
/usr/bin/g++ -v
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4) apt list --installed build-essential
: build-essential/trusty,now 11.6ubuntu6 amd64 [installed]apt list --installed python
: python/trusty,now 2.7.5-5ubuntu3 amd64 [installed], Python 2.7.6apt list --installed python-dev
python-dev/trusty,now 2.7.5-5ubuntu3 amd64 [installed]
conda环境:在base
环境,仅安装了python
- python:
/home/haoyu/ENV/localENV/anaconda3/bin/python -v
: Python 3.7.3
报错
在base
环境,执行~/.vim/plugged/YouCompleteMe/install.pys
手动编译ycm失败,报错如下
Searching Python 3.6 libraries...
Found Python library: /home/haoyu/ENV/localENV/anaconda3/lib/libpython3.6m.so
Found Python headers folder: /home/haoyu/ENV/localENV/anaconda3/include/python3.6m
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/bin/cc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /tmp/ycm_build_i9zudbsb/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec2070396260/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec2070396260.dir/build.make
CMakeFiles/cmTryCompileExec2070396260.dir/build
make[1]: Entering directory `/tmp/ycm_build_i9zudbsb/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/tmp/ycm_build_i9zudbsb/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object
CMakeFiles/cmTryCompileExec2070396260.dir/testCCompiler.c.o
/usr/bin/cc -o CMakeFiles/cmTryCompileExec2070396260.dir/testCCompiler.c.o
-c /tmp/ycm_build_i9zudbsb/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec2070396260
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec2070396260.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTryCompileExec2070396260.dir/testCCompiler.c.o -o
cmTryCompileExec2070396260 -rdynamic
/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o:
unrecognized relocation (\0x2a) in section `.init'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
make[1]: Leaving directory `/tmp/ycm_build_i9zudbsb/CMakeFiles/CMakeTmp'
make[1]: *** [cmTryCompileExec2070396260] Error 1
make: *** [cmTryCompileExec2070396260/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:26 (project)
-- Configuring incomplete, errors occurred!
See also "/tmp/ycm_build_i9zudbsb/CMakeFiles/CMakeOutput.log".
See also "/tmp/ycm_build_i9zudbsb/CMakeFiles/CMakeError.log".
ERROR: the build failed.
NOTE: it is *highly* unlikely that this is a bug but rather
that this is a problem with the configuration of your system
or a missing dependency. Please carefully read CONTRIBUTING.md
and if you're sure that it is a bug, please raise an issue on the
issue tracker, including the entire output of this script
and the invocation line used to run it.
这是因为,系统自带的gcc
损坏。在没有sudo权限、或不想改动系统gcc
的情况下,建议采用此策略。
对策:创conda环境编译ycm
此策略不仅能解决上述报错,还能应对各种ycm编译失败的问题。
创建conda环境用于编译ycm
创建build_ycm环境
conda create -n build_ycm python=3.8.0
进入build_ycm环境
conda activate build_ycm
conda install -c anaconda cmake
此命令的源的cmake会更新,我当时装的是cmake 3.14.0
执行which cmake
会返回/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/cmake
conda安装g++及gcc - for linux 64位
conda install -c anaconda gxx_linux-64
此命令的源的gcc/g会更新,我当时装的是gcc 7.3.0/g 7.3.0
此时,虽然which gcc或g++
返回的是/usr/bin/gcc或g++
,但在编译时却实际用conda的gcc与g++(位于/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-gcc或g++
)
开启conda的gcc和g++
根据参考,需要执行以下代码,但我实际操作中发现这一步可以不用
退出然后重新进入build_ycm环境,以开启conda的gcc和g++
conda deactivate
export CONDA_BUILD=1
conda activate build_ycm
会输出
INFO: activate-binutils_linux-64.sh made the following environmental changes:
+ADDR2LINE=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-addr2line
+AR=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-ar
+AS=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-as
+CXXFILT=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-c++filt
+ELFEDIT=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-elfedit
+GPROF=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-gprof
+HOST=x86_64-conda_cos6-linux-gnu
+LD_GOLD=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-ld.gold
+LD=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-ld
+NM=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-nm
+OBJCOPY=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-objcopy
+OBJDUMP=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-objdump
+RANLIB=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-ranlib
+READELF=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-readelf
+SIZE=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-size
+STRINGS=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-strings
+STRIP=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-strip
INFO: activate-gcc_linux-64.sh made the following environmental changes:
+CC=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-cc
+CFLAGS=-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix
+CMAKE_PREFIX_PATH=::/x86_64-conda_cos6-linux-gnu/sysroot/usr
+_CONDA_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_x86_64_conda_cos6_linux_gnu
+CPPFLAGS=-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -I/include
+CPP=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-cpp
+DEBUG_CFLAGS=-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-all -fno-plt -Og -g -Wall -Wextra -fvar-tracking-assignments -ffunction-sections -pipe -I/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix
+DEBUG_CPPFLAGS=-D_DEBUG -D_FORTIFY_SOURCE=2 -Og -I/include
+GCC_AR=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-gcc-ar
+GCC=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-gcc
+GCC_NM=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-gcc-nm
+GCC_RANLIB=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-gcc-ranlib
+LDFLAGS=-Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/lib -Wl,-rpath-link,/lib -L/lib
INFO: activate-gxx_linux-64.sh made the following environmental changes:
+CXXFLAGS=-fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix
+CXX=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-c++
+DEBUG_CXXFLAGS=-fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-all -fno-plt -Og -g -Wall -Wextra -fvar-tracking-assignments -ffunction-sections -pipe -I/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix
+GXX=/home/haoyu/ENV/localENV/anaconda3/envs/build_ycm/bin/x86_64-conda_cos6-linux-gnu-g++
此时which gcc或g++
依旧返回的是/usr/bin/gcc或g++
,
编译ycm
开始编译
cd ~/.vim/plugged/YouCompleteMe
./install.py
测试
然后回到conda的base环境
conda decativate
安装neovim
pip install neovim
测试neovim上是否能使用ycm
neovim <test-file.sh>
输入一些内容,看看是否能不按tab就自动补全,若能则ycm编译成功。我通过上法成功了。
升级vim
vim版本太老会出现的问题
开启vim
时报错
- Python (2.7.1+ or 3.4+)
YouCompleteMe unavailable: requires Vim compiled with Python (2.7.1+ or 3.4+) support.
UltiSnips requires py >= 2.7 or py3
是因为当前用的(n)vim版本不支持python2与python3。
vim的判断方法:执行vim --version
,显示有-python
和 -python3
(减号表示不支持,加号表示支持), 则皆不支持。
- Python (3.6.0+)
YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support.
是因为当前用的(n)vim版本不支持python3 (>=3.6.0)。
vim的判断方法:执行vim --version
,显示有 -python3
(减号表示不支持,加号表示支持), 则不支持。
- 对策
需要安装新版本的vim来解决此问题。
mac上的nvim:
brew upgrade nvim
utf8不支持
若vim没有python2,python3,clipboard, 有conceal,并不会出现utf8不支持,应当是其他原因造成的
conda安装vim
conda install -c conda-forge vim
安装vim-gnome
安装vim-gnome
sudo apt-get install vim-gnome
在服务器sshost2
上装好后,有python3, clipboard, conceal,无python2,上述一切问题没有
./configure --with-gui=gtk2 # or gnome
make -j 4
sudo make install
conda安装neovim
我用conda安装neovim的方法
conda install -c conda-forge neovim
find anaconda3 -name neovim
Supertab
Ultisnip
默认加载代码段的文件夹:UltiSnips,即.vim下任意名为UltiSnips的文件夹下任意层的.snippets文件:
用户自定义的代码段在 ~/.vim/UltiSnips
vim-snippets 的在.vim/plugged/{vim-snippets, UltiSnips}
手动添加其他目录
let g:UltiSnipsSnippetDirectories = ['其他代码段目录', 'UltiSnips' ]
snippet写法,在~/.vim/UltiSnips/语言.snippets
中,添加一段
snippet 关键词 “提示” 设定
内容
endsnippet
设定(更多详见:help ultisnip
)
b 代表只有关键词出现在行首的时候,才可以被展开
A 代表自动展开
w 代表可以展开这个 “词”,具体 “词” 的定义可以查看 :help iskeyword。直观感觉就是,这个关键词是单独的,和其他文字分开的。比如前后都是空格。
i 代表可以忽略前后字节,直接展开关键词。(这个设定比 w 要更松)
ctrlsf
:CtrlSF
[-I不分大小写|-S分大小写|default=smart]
[-R正则表达式|default=literally]
[-W整词|default=非整词]
"PATTERN"
[搜索哪些文件的通配符,默认为所有可见文件(夹)|{*,.*}所有文件|*.py 所有可见.py文件|% 当前文件]
(不支持搜索所有打开的文件)
-R
- Use regular expression pattern.-I
,-S
- Search case-insensitively (-I
) or case-sensitively (-S
).-C
,-A
,-B
- Specify how many context lines to be printed, identical to their counterparts in Ag/Ack.-W
- Only match whole words.
vim-which-key 按键提示
https://segmentfault.com/a/1190000016661599
surround 括号匹配修改
vim-multiple-cursors 多行编辑插件
https://zhuanlan.zhihu.com/p/23262156
vim-airline/vim-airline 标签页和下方状态栏
vim-airline/vim-airline-themes 标签页和下方状态栏配色
ctrlP
ctrlp:http://zuyunfei.com/2013/08/26/vim-plugin-ctrlp/
提供的命令http://blog.collin2.xyz/index.php/archives/99/
教程
进入ctrlp模式
:CtrlP
或者CtrlP [起始目录]
: 在查找文件模式下调用CtrlP:CtrlPBuffer
或:CtrlPMRU
: 在查找缓冲区调用CtrlP或者查找MRU文件模式
进入ctrlp模式后
模式
<S-Left>
、<S-right>
: 左、右移动切换模式(文件 file/最近打开的文件 MRU/ctrlp打开的历史 buff)<c-f>
: 开关到仅文件名搜索而不是完整路径搜索<c-r>
: 开关切换到正则表达式模式
选择
Up
、Down
: 在文件列表中上下移动<c-z>
: 勾选/勾除记多个文件
更新
<F5>
: 清除当前目录的缓存以获取新文件,删除已删除的文件并应用新的忽略选项<F7>
:- MRU下直接按它清空所有文件
- MRU下先
<c-z>
勾选文件在按它清之 - buffer下按它清除所在行的文件
<c-z>
,<c-s-z>
: 撤销、重做于ctrlp中
打开命令
<cr>
、<c-t>
、<c-v>
、<c-h>
: 开在本窗口(现在的文件就关了)、新Tab、横分屏、竖分屏<c-o>
:打开,ctrlp会问你用上述哪种方法打开
输入路径
<s-tab>
:开关输入栏tab
: 自动补全left
、right
:在自己输入的path中左右移动光标<c-\>
:输入栏在光标处插入内容,会弹出选项,问从系统剪切板插入啥..
回车,上走一级目录,n个.
后回车,上走n-1个目录- 标记文件后,输
:number
,不回车,按打开命令,会打开并跳到指定行数 - 输入[父目录/父目录/]新文件名,
<c-n>
,创建一个新文件及其父目录 - 默认是绝对路径,相对路径请用
./
开头 - 但貌似不能创建文件夹
- 对比文件:勾选多个文件
- 输入
:diffthis
,不回车,按打开命令(通常竖分屏) /或按<c-o>
来竖分屏 - 或直接输入
<C-d>
,竖分屏
文档:https://github.com/hyliang96/ctrlp.vim/blob/master/doc/ctrlp.cnx
帮助
:help ctrlp-options
: 获取帮助文档:help ctrlp-mappings
:按键帮助:help ctrlp-commands
:获取ctrlp命令的帮助
默认快捷键
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<bs>', '<c-]>'],
\ 'PrtDelete()': ['<del>'],
\ 'PrtDeleteWord()': ['<c-w>'],
\ 'PrtClear()': ['<c-u>'],
\ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtSelectMove("t")': ['<Home>', '<kHome>'],
\ 'PrtSelectMove("b")': ['<End>', '<kEnd>'],
\ 'PrtSelectMove("u")': ['<PageUp>', '<kPageUp>'],
\ 'PrtSelectMove("d")': ['<PageDown>', '<kPageDown>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
\ 'ToggleFocus()': ['<s-tab>'],
\ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("c")': ['<MiddleMouse>', '<insert>'],
\ 'PrtInsert()': ['<c-\>'],
\ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteEnt()': ['<F7>'],
\ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }
vim基础知识
vim快捷键设置
https://www.jianshu.com/p/2c9a85277d49
vim基础操作
http://vim.wikia.com/wiki/All_the_right_moves
按键
冲突的
enter=ctrl+m
tab=ctrl+i
ctrl+tab!=ctrl+i
Ctrl+3=ESC
delete=ctrl+d
解决方案
https://stackoverflow.com/questions/14641942/how-to-unmap-tab-and-do-not-make-ctrl-i-invalid-in-vim
需要你的终端发送不同的 termcap code
https://stackoverflow.com/questions/3985341/how-do-vims-control-o-and-control-i-work
:h jumplist
ctrl+o:去上次光标位置,会跨越文件
ctrl+i:去下次光标位置,会跨越文件
alt+键的映射
mac的解决方案
https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim
alt+键,shift+alt+键 皆可用,不会混
依赖于英文输入法
我使用的是ABC英文输入法
- 其alt+键对应特殊字符的映射最通用
- 按 ^ ~ 等键不会滞留等待输入下一个键
而美式键盘(国际)
会滞留,例如,输入^ 会显示^
并滞留
- 若再输
a
,则出来$\hat{a}$ - 若再输空格,才出^
ABC(国际)
输入alt+z/^ 等键会出现滞留间,例如输入alt+^ 会显示^
并滞留
- 若再输
a
,则出来$\hat{a}$ - 若再输空格,才出^
可用的快捷键
可用且不不同
<Home>
=Fn+Left
, End
=Fn+Right
,S-Home/End
, C-Home/End
,,S-C-Home/End
, S-C-Home/End
,
<PageUp/PageDown>`=`Fn+Up/Down
F1` `<S-F1>` `<C-F1>` `<C-S-F1>
被占用的
S-PageUp/PageDown
=(似乎)C-PageUp/PageDown
开/关下小栏
不可用的
待办
- insert 模式下,在行尾ctrl+v插入,再ctrl+z撤销,则会前移一格
- insert 模式下,在行中ctrl+v插入或输入一段文字,再ctrl+z撤销,再重做ctrl+r,则光标相比于撤销后未动,而没有回到撤销前的光标位置
- insert paste 模式下,ctrl+s出现^S,而没有保存
- 实现在insert模式,输入tab,若在单词尾,则自动补全,否则输入tab
- insert paste 模式下,按tab键,会出tab;换行后自动缩进也出tab
- insert 模式,行首输入
\
,会出现【三个缩进】\
,但在行中不会有这个问题 - 用
inoremap \ <space><backspace>\
能解决,需对文件做二分法来找出原因 - 用
inoremap \ <任意其他字符><backspace>\
不能解决
vim-multiple-cursors 多行编辑插件
进入vim-multiple-cursors的visual、normal模式
- bug:先ctrl+d选定一个词,在S-d选所有相同词时,会出现bug
shift+左
Fn+右
输入后不立即奏效,需再输入一个键才左移一词或右移到行尾
但shift+右
Fn+左
输入后立即奏效
S-C-Up/Down
能用- 在insert模式上述都能用
提示栏
- 底栏不显示现在在vim-multiple-cursors的visual或normal状态,但现实在insert状态
各模式
- ctrl+b不能退出,esc才能退出
vim的常用函数
- 行号
line('.')
- 下一个空白行的行号
search("^$") - 1
- getline(start, end),获得字符串
- 判断是否在行尾
- n、v模式:
virtcol(".") == virtcol("$")-1
- i模式:
virtcol(".") == virtcol("$")
- virtcol显示的是字符宽度,而非bite数
call feedkeys("\<C-x>xxx\<Esc>")
- 必需首字母大写
- 必需双引号
:h terminal-key-codes
查看key code,例如
t_%i <S-Right> shift arrow right *t_%i* *'t_%i'*
t_#4 <S-Left> shift arrow left *t_#4* *'t_#4'*
显示时,输入:echo "\<S-Left>"
,输出<80>#4
- 在终端,输入
cat -v
或sed -n l
或按ctrl+v
然后输入组合键,会显示快捷键的键码 - 在vim ,输入
:echo getchar()
回车,然后输入快捷键,会显示在vim下的编码。 - 如按PageUp,显示
<80>kP
,其含义是unicode为 \u80-k-P,即getchar()=~'^[\u80]kP$'
为真 - 按S-PageUp,显示
<80><fc>^D<80><fd>^D
,其含义是unicode为\u90-\ufc-^D-\u80-\ufd-^D
,即getchar()=~"^[\\u80][\\ufc]\<C-D>[\\u80][\\ufd]\<C-D>$"
为真
转义字符
- 单引号不转义,双引号转义。转义字符如下
- 第一类:
\\
表示\
,\n
换行,\t
tab - 第二类:按键:
\<C-Up>
,\<up>
- 第三类:正则表达式中的转义字符,单引号内写作
\某
,双引号内写作\\某
- 正则表达式的转义:
\(
表示(
,\)
表示)
,\|
表示|
即“或”\a
表示字母,即[a-zA-Z]
,\d
表示数字,即[0-9]
例如match('asd','\(\a\|\d\)')
返回0,match('213','\(\a\|\d\)')
返回0,match('-+\','\(\a\|\d\)')
返回-1
-
正则表达式中的
[
]
+
*
皆不需要前加\
-
例如
-
正则表达式转义字符,单引号内写作
\某
,双引号内写作\\某
如 '\(\a\|\d\)'
等价于 "\\(\\a\\|\\d\\)"
- 第一、二类转义字符,只能用双引号;第三类转义字符,单双引号皆可用。
系统剪切板
https://www.zhihu.com/question/19863631
http://os.51cto.com/art/201808/580326.htm?mobile
cd /home/$USER
git clone https://github.com/vim/vim.git
cd vim/src
md /home/$USER/ENV/vim
./configure --prefix=/home/$USER/ENV/vim
make
make install
- 删减vimrc中被注释掉的
- 剪切板:http://os.51cto.com/art/201808/580326.htm?mobile
- https://vi.stackexchange.com/questions/84/how-can-i-copy-text-to-the-system-clipboard-from-vim
- xclip源代码:https://github.com/astrand/xclip
./configure # --prefix=/home/$USER/ENV/xclip
make
make install prefix=/home/$USER/ENV/xclip
- 如果要使用Xclip,请粘贴以下行:
alias pbcopy='xclip -selection clipboard' alias pbpaste='xclip -selection clipboard -o'
如果要使用xsel,请在?/.bashrc文件中粘贴以下行:
alias pbcopy='xsel --clipboard --input' alias pbpaste='xsel --clipboard --output'
然后保存并关闭.bashrc文件。
- 安装xclip
sudo apt-get install xclip
:call system('xclip -selection clipboard', @")
:call system('xclip -selection clipboard -o', @")
https://coderwall.com/p/hmki3q/vim-copy-paste
https://github.com/erickzanardo/vim-xclip
- clip:conda install
http://procrastinatingdev.com/clip/
conda install -c travis clip
- xsel
make:https://gist.github.com/houtianze/7ba320bc250589fdd35ad4082e52133f
yum install -y automake autoconf git libtool
curl -OL http://www.vergenet.net/~conrad/software/xsel/download/xsel-1.2.0.tar.gz
tar -xzf xsel-1.2.0.tar.gz
cd xsel-1.2.0
# ./autogen.sh --prefix=/home/$USER/ENV/xsel
./configure --prefix=/home/$USER/ENV/xsel
make
make check
sudo make install
# make distclean
function! ClipboardOrXclip(command, register)
if a:register !~ '[+*]' || has('xterm_clipboard') || has('gui_running')
" Just return the original command if the clipboard is accessible
" or it's not a register that should be handled by xsel
return a:command
endif
if a:register == '+'
return "<Esc>:r !xsel -bo<CR>"
else
return "<Esc>:r !xsel -po<CR>"
endif
endfunction
nnoremap <silent> <expr> p ClipboardOrXclip('p', v:register)
- conda装vim 8.0
https://anaconda.org/conda-forge/vim
conda install -c conda-forge vim
bug
已经解决
-
多光标的各个模式都不支持 S-down,可能是键盘翻译不成功
-
但都支持pageup, pagedown,S-UP
-
原因是,mc中的map没有区分noremap和map,因此全都是可以反复翻译的,S-Down会映射为$ctrl-d,而ctrl-d是添加搜索下一个关键词
-
按S-C-Up,需要等待输入下一个键才执行,找出何处在等待输入空
-
在insert模式
-
在文件头,按S+left,S+up,会切换到normal模式:这是因为
inoremap <S-Left> <esc>gEa
执行到一半,发现gE
无法执行,就卡在n模式了。故应当修改为inoremap <S-Left> <left><c-o>gE<right>
,使得执行到一半,就回到v模式。 -
所有imap,inoremap都不要写
<esc>...i或a
,要写<c-o>
,则可避免上述问题 -
按left, up, S+C+up、PageUp,Home不会
-
在insert模式下,按ctrl+z撤销,与vimrc中更精细的undo不兼容
-
多光标的visual模式下,pagedown按过一次后,再按则只能向下移动一行;normal和插入模式则正常
-
多光标的各个模式不支持alt+up/down,但都支持alt+m
-
air-line 的tab标头,在关闭tab后,还会留着一个空壳标头
未解决
- vim双击或v+移动 选中后,翻页时会推着光标走,从而选区变大,这是因为vim不支持off-screen cursor
- 精细的撤销:backspace和del连续按,
- 第一次按backspace或del,则标记一个节点
- backsapce删到一个空格,则标记一个节点
待办
-
写翻墙服务器的一键安装脚本
-
把翻墙服务器的aliases写成专门的一个脚本,然后在~/.alias里source它
-
将系统安装脚本,输出写到log
-
比较实验室、笔记本、开发服务器上的共享dot文件的异同,将开发服务器没有添加得到开发服务器上面
-
将serverENV和shareENV装到实验室服务器上,并完善其自动安装脚本
安装方法
安装方法
- 备份
把目录清空
rm /home/$USER/backup_before_install -rf
mkdir /home/$USER/backup_before_install
mv /home/$USER/{*,.*} /home/$USER/backup_before_install
或者全部清空【危险】
rm /home/$USER/* -rf
rm /home/$USER/.* -rf
重新登录,进入bash
- 安装
cd /home/$USER
git clone https://github.com/hyliang96/system-template.git
cp /home/$USER/system-template/{*,.*} /home/$USER -r
rm /home/$USER/system-template -rf
bash /home/$USER/init_script/install_sys.sh
再次登录则是zsh,并开机安装zsh
- ssh设置
- 笔记本上
ssh-copy-id -i ~/.ssh/<私钥名>(如id_rsa) <服务器别名>
- 安装软件
bash /home/$USER/init_script/cpu_software.sh
或
bash /home/$USER/init_script/gpu_software.sh
- 修改系统时间
- 个人用户修改
获得修改指令
tzselect
一路选择地区,得到返回export TZ='Asia/Shanghai'
append this to ~/.env
export TZ='Asia/Shanghai'
- 系统修改
date -R # 再次查看时间
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date -R # 再次查看时间,确认已经修改为北京时间
sudo hwclock --systohc # 修改硬件CMOS的时间,如果没有这一步的话,后面时间还是不准
- 服务器上
当确认服务器运行正常,将其.ssh/id_ras.pub
公钥添加到github上,则可以同步shareENV、serverENV
详解
- 自动脚本
git clone https://github.com/hyliang96/shareENV.git /home/$USER/ENV/shareENV
git clone https://github.com/hyliang96/serverENV.git /home/$USER/ENV/serverENV
zsh
zsh是为了用antigen自动安装zsh的插件
用git@github.com则会permission denied,用https://github.com/hyliang96则需要输入密码
之后脚本中
cd $shareENV
git remote set-url origin git@github.com:hyliang96/shareENV
cd $serverENV
git remote set-url origin git@github.com:hyliang96/serverENV
- zsh compinit: insecure directories and files, run compaudit for list.
- 法一:保留原来的.antigen,但将
.antigen/init.zsh
中的hyliang
改为$USER
,会出现bug
/home/test/ENV/CONF/.antigen/init.zsh:source:74: no such file or directory: /home/test/ENV/CONF/.antigen/bundles/rupa/z/z.sh
/home/test/ENV/CONF/.antigen/init.zsh:source:75: no such file or directory: /home/test/ENV/CONF/.antigen/bundles/zsh-users/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
/home/test/ENV/CONF/.antigen/init.zsh:source:76: no such file or directory: /home/test/ENV/CONF/.antigen/bundles/zsh-users/zsh-completions/zsh-completions.plugin.zsh
/home/test/ENV/CONF/.antigen/init.zsh:source:77: no such file or directory: /home/test/ENV/CONF/.antigen/bundles/willghatch/zsh-cdr/cdr.plugin.zsh
/home/test/ENV/CONF/.antigen/init.zsh:source:79: no such file or directory: /home/test/ENV/CONF/.antigen/bundles/zsh-users/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh
- 法二:重新安装后的zsh,没有git提示(使用之)
需要
rm ~/.antigen/bundles/robbyrussell/oh-my-zsh/themes/{agnoster.zsh-theme,agnoster.zsh-theme.antigen-compat}
ln -s $shareENV/shell_config/{agnoster.zsh-theme,agnoster.zsh-theme.antigen-compat} ~/.antigen/bundles/robbyrussell/oh-my-zsh/themes
~/.antigen/bundles/robbyrussell/oh-my-zsh/themes/my_agnoster.zsh-theme
~/.antigen/bundles/robbyrussell/oh-my-zsh/themes/my_agnoster.zsh-theme.antigen-compat
看看如何将其利用我的github,能独立安装antigen安装,并能用我的更换配色
- autojump不安全
zsh compinit: insecure directories and files, run compaudit for list.
Ignore insecure directories and files and continue [y] or abort compinit [n]? ncompinit: initialization aborted
_antigen_compinit:1: command not found: compdef
重装autojump
cd $my
git clone git://github.com/joelthelion/autojump.git
cd autojump
./install.py
cd ..
rm autojump -rf
- 更换链接
bash init_script/add_link.sh
安装完后不要在git pull,不然会把链接换回去
- 安装vim 插件,会启动vim,可能需要后台运行,运行完自动关闭
vim +PlugInstall +qall
- 更换zsh
chsh -s `which zsh`
退出重新登录,看看各个东西能不能用