vim

In vim, why is 'j' used for down and 'k' for up?

天大地大妈咪最大 提交于 2019-12-20 10:22:11
问题 I've been using vim for many years and have never really thought about it. A friend of mine asked why that is, noting that in our culture, left would usually map to up while right would map to down, making the vim keys backwards. I understand that they are on the home row, meaning that you do not have to move your fingers anywhere to hit them, but that's a different point altogether. Basically, my question is: does anyone know why these keys were given their present purposes? It would be

设置vim语法高亮显示和自动缩进

这一生的挚爱 提交于 2019-12-20 10:17:58
设置 vim 语法高亮显示和自动缩进 1 、配置文件的位置 在目录 /etc/ 下面,有个名为 vimrc 的文件,这是系统中公共的 vim 配置文件,对所有用户都有效。而在每个用户的主目录下,都可以自己建立私有的配置文件,命名为: “ . vimrc ” 。例如, /root 目录下,通常已经存在一个 . vimrc 文件。 2 、设置语法高亮显示 1) 打开 vimrc ,添加以下语句来使得语法高亮显示: syntax on 2) 如果此时语法还是没有高亮显示,那么在 /etc 目录下的 profile 文件中添加以下语句: export TERM=xterm-color 3 、设置 Windows 风格的 C/C++ 自动缩进(添加以下 set 语句到 vimrc 中) 1 ) 设置(软)制表符宽度为 4 : set tabstop=4 set softtabstop=4 2 ) 设置缩进的空格数为 4 set shiftwidth=4 3 ) 设置自动缩进 : 即每行的缩进值与上一行相等;使用 noautoindent 取消设置: set autoindent 4 ) 设置 使用 C/C++ 语言的自动缩进方式: set cindent 5 )设置 C/C++ 语言的具体缩进方式(以我的 windows 风格为例): set cinoptions={0,1s,t0,n-2

Move adjacent tab to split?

て烟熏妆下的殇ゞ 提交于 2019-12-20 10:17:45
问题 Is there an easy way to move an adjacent tab in Vim to current window as a split? While looking around I reached a mailing list discussion where someone said it's the reverse of the operation Ctrl + W , T without providing the solution. 回答1: I am providing two solutions, the first one I checked myself and I can guarantee it's working. The second, I am trying soon. First solution: install this plugin http://www.vim.org/scripts/script.php?script_id=1961 by simply creating the folder ~/.vim

Shortcut for switching back to last window in Vim?

醉酒当歌 提交于 2019-12-20 10:13:40
问题 Ctrl w 1 w switches to the first window. If currently I frequently edit in two of several windows, a shortcut for switching back to the last active window would be perfect. Is there such a shortcut? 回答1: did you try <c-w><c-p> ? from help: CTRL-W p *CTRL-W_p* *CTRL-W_CTRL-P* CTRL-W CTRL-P Go to previous (last accessed) window. *CTRL-W_P* *E441* CTRL-W P Go to preview window. When there is no preview window this is an error. {not available when compiled without the |+quickfix| feature} 回答2: As

How to use vim (key-bindings) with Visual Studio Code vim extension

假装没事ソ 提交于 2019-12-20 09:49:21
问题 I just started using Visual Studio Code and think it's really great. Also installed the vim extension, but I'm struggling with mapping esc to a another key. Normally I have this: :imap jj <Esc> And I can see that VS Code has a keybindings.json file. I tried this: [{ "key": "jj", "command": "vim.Esc", "when": "editorTextFocus" }] Also there is a settings.json file, so I tried: { "vim.keyboardLayout": "en-US (QWERTY)", "vim.insertModeKeyBindings": { "j": "vim.Esc" } } Also did not work. So does

git rebase --editor=/something/other/than/vim? (for easier squashing)

五迷三道 提交于 2019-12-20 09:46:34
问题 I happily use vim as my default editor for commits, and do not wish to change it. However, when it comes to rebasing, I find myself squashing dozens and dozens of commits which I find much easier with an interactive editor like Textwrangler (substituting "pick" with "squash" in all but the top commit). Is there any way to specify an alternate editor for a one-off rebase command? I know in vim I can do: :%s/pick/squash/ but that has its own minor annoyances. EDIT - as stated in the comments,

How do I toggle between a Vertical and a Horizontal split in vimdiff?

 ̄綄美尐妖づ 提交于 2019-12-20 09:46:33
问题 I already know how to use the diffopt variable to start diff mode with horizontal/vertical splits but not how to toggle between the two when I already have two files open for comparison. I tried the accepted answer found in this older post, but to no avail. The Ctrl+W commands didn't work for me. Perhaps because I'm running gVim in Windows-friendly mode? 回答1: The following command will change a vertical split into a horizontal split: ctrl + w then J To change back to a vertical split use

Vim's :open does not tab complete, what does?

我们两清 提交于 2019-12-20 09:45:07
问题 Instead of tab completed file or directory names, I see ^I :open ./lib/^I^I^I Is there another command that would offer tab completion, or perhaps another solution? I'm considering replacing the following mapping with something that would use buffers, but want to keep tab completion. map <C-O> :tabnew ./ 回答1: That might be because :open is not the command you're looking for. Try :edit or :e for short. Also try :help :open and :help :e to see, what the commands do. :e has tab completion. 回答2:

VIM: Use python3 interpreter in python-mode

女生的网名这么多〃 提交于 2019-12-20 09:44:53
问题 I have recently switched to vim and configured it for Python-programming using this tutorial. Before, I have made sure that vim supports python3 (vim --version shows +python/dyn and +python3/dyn) using this article. But when executing a file from python-mode, still the python2.7 interpreter is chosen. How can I configure vim (or the python-mode) to run files on the python3 interpreter? My OS is Ubuntu 14.04 x64. Thanks in advance! 回答1: Try adding this to your .vimrc file let g:pymode_python =

Selecting resulting files from grep in vim

旧巷老猫 提交于 2019-12-20 09:40:37
问题 After I run a grep search in vim with :grep, I get a list of files. Is there a way to select one of those files and open it in a new tab at that particular line? 回答1: For achieving what you want you have to open the quickfix/error window after calling grep: :copen I have a script that makes it for me every time i use grep. 回答2: Just for completeness, as well as the :copen command, there's also :cw , which only opens the "quickfix" window if there are entries (so if your grep has no results,