vim

How can I duplicate lines matching a pattern, and modify the second line, all in one command?

末鹿安然 提交于 2019-12-21 02:51:06
问题 I'm trying to add an attribute to a java class, using VIM as the editor. Therefore I thought I could use a command to ease my work with all the boilerplate code. Eg: All lines containing "atributeA", like this one this.attributeA=attributeA //basic constructor should turn into this.attributeA=attributeA //basic constructor this.attributeB=attributeB //basic constructor Is it possible? 回答1: Having the solution be a one-liner as a requirement seems a little odd, since you can assign any

Change the mapping of F5 on the basis of specific file type

≯℡__Kan透↙ 提交于 2019-12-21 02:41:18
问题 The current mapping of my F5 key is: imap <F5> <esc>:w\|!python %<CR> Now I want that if I'm editing any python file (it will be better if it also recognizes file other than standard .py format like .pyd etc) then this mapping works as it is. But, if I edit a Java file it is mapped to something like: imap <F5> <esc>:w\|!javac %<CR> And when I'm editing any .c or .cpp file then F5 is mapped to this: imap <F5> <esc>:w\|!make %<CR> I have no idea how to proceed. 回答1: There are problems with both

How to filter visual selection?

懵懂的女人 提交于 2019-12-21 02:00:35
问题 Suppose we have some nice bunch of text: Hello world and we select the world in visual mode. Then we could filter the visual selection using a shiny command like this one: :'<,'>!echo foobar However, that would replace the entire line with foobar instead of just the world . Why is this, and how can we just replace the world ? 回答1: The :! filter command always works on entire lines (this is as old as the original vi , embedding Ex commands that start with : ), and the '<,'> range also only

Make 'n' always search forwards, regardless of whether / or ? was used for searching

旧城冷巷雨未停 提交于 2019-12-21 00:27:11
问题 I almost always search in Vim with / , and then continue searching forwards with n and backwards with N . Sometimes, however, I use ? to jump to an item just a few lines above the line I'm currently at, and in that case, if I want to search the same item forwards, I have to use N instead of n , an annoying mental speed bump. So my question is: is it possible to make n always go forwards, and N backwards? P.S. Documentation seems to hint that it's not possible, since n simply "Repeats the

SecureCRT/PUTTY中使用VIM中文乱码问题

非 Y 不嫁゛ 提交于 2019-12-21 00:00:41
如果使用SSH终端SecureCRT (PUTTY也一样)程序连接linux服务器,对于服务器返回的中文字符默认情况会显示乱码,解决方法很简单,打开会话选项对话框,找到外观,把字符编码改成你服务器上使用的编码方式即可,一般为UTF-8。 不过,我这里遇到了点问题是关于一个UTF-8的文档,使用cat可以正常显示中文,使用vim打开却显示为乱码,看来肯定是vim的问题了。 经过查找和尝试,设置一下vim的内部编码格式得到解决: 设置后: 另,转一篇关于vim编码的文章 原文: http://edyfox.codecarver.org/html/vim_fileencodings_detection.html 在 Vim 中, 有四个与编码有关的选项, 它们是: fileencodings 、 fileencoding 、 encoding 和 termencoding 。 在实际使用中, 任何一个选项出现错误, 都会导致出现乱码。 因此, 每一个 Vim 用户都应该明确这四个选项的含义。 下面, 我们详细介绍一下这四个选项的含义和作用。 1 encoding encoding 是 Vim 内部使用的字符编码方式。 当我们设置了 encoding 之后, Vim 内部所有的 buffer、 寄存器、 脚本中的字符串等, 全都使用这个编码。 Vim 在工作的时候,

Better autocomplete in VIM

邮差的信 提交于 2019-12-20 20:37:49
问题 All, I have been working with vim for some time now, and love everything about it - there is only one thing I really miss from IDEs like RubyMine, and that is advanced autocompletion. For reference, here is my standard VIM setup: https://github.com/wrwright/.vim I have tried ctags with omnicomplete + supertab, and the one major element I miss is the ability to bring up a context sensitive list of attributes/constants/methods. For example, as I learn RubyMotion, I'd love to have some help

Better autocomplete in VIM

扶醉桌前 提交于 2019-12-20 20:37:23
问题 All, I have been working with vim for some time now, and love everything about it - there is only one thing I really miss from IDEs like RubyMine, and that is advanced autocompletion. For reference, here is my standard VIM setup: https://github.com/wrwright/.vim I have tried ctags with omnicomplete + supertab, and the one major element I miss is the ability to bring up a context sensitive list of attributes/constants/methods. For example, as I learn RubyMotion, I'd love to have some help

Vim: Use + as default register only for yank command

限于喜欢 提交于 2019-12-20 20:17:14
问题 I'd like to use + register (system clipboard) only for yank command (that is, don't overwrite this register on dd or other commands). :set clipboard+=unnamed won't work, because it introduces dd overwriting described above. 回答1: You can overwrite the default yank commands so that they default to the system clipboard, unless another register is explicitly given: :nnoremap <expr> y (v:register ==# '"' ? '"+' : '') . 'y' :nnoremap <expr> yy (v:register ==# '"' ? '"+' : '') . 'yy' :nnoremap <expr

Open file from NERDtree in specific window (or last active)

久未见 提交于 2019-12-20 20:00:39
问题 In VIM I've got 4 windows opened and a NERD tree like this: So, whenever I try to open the file from NERD, it's opened in first buffer (topleft pos). Sometimes in other buffers. Is there a way to open a file in bottom right position ? Mb there are workarounds ? Maybe I can force NERDtree to open file in last active window ? At the moment, it doesn't work this way :( UPD: It looks like the problem is in hidden buffers. When the buffer was opened in one window, and then replaced by another - if

How to syntax-highlight a part of file in a different syntax?

China☆狼群 提交于 2019-12-20 19:57:15
问题 I installed bnf.vim (highlights BNF grammar files). Suppose I have a comment in my code: /* <BNF> <S> := <A> | h <A> := a | b | c | . </BNF> */ Can Vim be somehow programmed to highlight that comment in BNF syntax, despite the filetype of the whole file? 回答1: You can use my SyntaxRange plugin for that. Either explicitly assign the range, e.g. :10,20SyntaxInclude bnf or automatically based on the delimiting patterns: :call SyntaxRange#Include('<BNF>', '</BNF>', 'bnf') 回答2: for many file types