vim

How can I manually enter tabs (possibly .vimrc file)?

余生颓废 提交于 2019-12-24 08:57:08
问题 Whenever I try to enter tabs in vim, it just enters 4 spaces. I am currently writing a makefile so I need to be able to enter literal tabs. Any ideas? 回答1: Remove set expandtab from (or use set noexpandtab in) your .vimrc. To insert a literal tab when expandtab is on, you can use Ctrl+v Tab (or Ctrl+q Tab on windows with the default settings) 回答2: in your .vimrc you want set noexpandtab 回答3: To the best of my knowledge, expandtab is automatically reset for Makefile :verbose set et? shows

Make VIM function return text without indent

放肆的年华 提交于 2019-12-24 08:55:42
问题 I guess this question could be taken in two ways... (Generic) - is there a way to specify settings 'local' to a function ( setlocal changes seem to persist after the function call)... (Specific) - I have a function which gets called from an imap mapping (which takes a user input to pass into the function. The function works perfectly if I run set paste or set noai | set nosi either just before running my shortcut, or added into the function itself. The problem is, whichever way I do it, those

Vim folding every line ending in { but not classes

扶醉桌前 提交于 2019-12-24 08:51:16
问题 I intend to fold all the lines ending in { but not classes. So far I have came up with this command : :%g/.\{-}\(class\)\@!.*{$/normal! zf% But this would match also the lines containing class . 回答1: There are several problems: From :help /\@! : "You can't use "\@!" to look for a non-match before the matching position". Use \@<! , include the possible characters in between in there, and drop the useless (because it's not anchored) non-greedy first match. The :global command places the cursor

How to focus a particular window?

久未见 提交于 2019-12-24 08:48:23
问题 I use NERDTree plugin, and I want to create a mapping that focuses NERDTree window and enters search mode (to easily select files, of course). The difficult part here is focusing NERDTree window. I want the mapping to work from any window - even from the NERDTree window itself. So how can I focus that window using vimscript? I found out that NERDTree's buffer has name "NERD_tree_1" (if only one NERDTree buffer exists, but that's enough for me). Can I somehow use it to focus a window

Remapping tab completions in vim

旧城冷巷雨未停 提交于 2019-12-24 08:28:42
问题 I've got a crazy little challenge. I'd like to remap tab and shift + tab to the basic tab completions in vim. Here's where I started: set completeopt= inoremap <tab> <C-n> inoremap <S-tab> <C-p> That didn't have any effect at all, and I also realized it might be messing up my snippets plugin. I went googling around and found this: http://vim.wikia.com/wiki/Smart_mapping_for_tab_completion, but had little luck implementing any of the suggestions. I'd like to map to tab and to shift + tab,

What is the return value for visual block mode in vimscript?

余生长醉 提交于 2019-12-24 08:11:13
问题 I'm trying to display the current mode of vim on the status line by mapping the return value of mode function by using a dictionary: let g:modeMap={ \ 'n' : 'Normal', \ 'i' : 'Insert', \ 'R' : 'Replace', ... \ 'v' : 'Visual', \ 'V' : 'Visual Line', \ '\<C-V>' : 'Visual Block' \} set laststatus=2 set statusline=%{g:modeMap[mode()]} It works well for almost all modes, however it throws the following error message in case of switching to visual block mode: E716: Key not present in Dictionary: ^V

Vim copy a block and paste it to multiple lines

▼魔方 西西 提交于 2019-12-24 07:56:40
问题 I know I can yy on line 1 and then visual select lines 4 and 5 2p (Vim copy one line and paste it to multiple lines). 1 COPY THIS 2 3 4 HERE 5 HERE So I get: 1 COPY THIS 2 3 4 COPY THIS 5 COPY THIS But instead, let's say I would like just COPY. If I visual block select COPY and then 2p on lines 4 and 5 visual selected 1 COPY THIS 2 3 4 COPYCOPY 5 How do I paste 1x at each line? Like: 1 COPY THIS 2 3 4 COPY 5 COPY 回答1: You can modify the register " (unnamed) to contain a newline, but at this

How to insert text in vimscript

爱⌒轻易说出口 提交于 2019-12-24 07:27:27
问题 I have the simplest requirement in a vimscript. I've been searching on Google for quite some time e.g. 1 2 3. I just want to insert a line of text! Suppose I have a file with lines: aaa bbb ddd eee And I just want to add the missing line ccc after the line bbb . I have the beginnings of a vimscript function: function! addLine() normal /bbb " MISSING LINE wq! endfunction What should the missing line be? Note that I want to then call this script on a bunch of files using using vim -c 'call

Identifying Identical Blocks of Code

痴心易碎 提交于 2019-12-24 07:16:04
问题 Say I have multiple blocks of the following code in a file (spaces is irrelavent): sdgfsdg dfg dfgdfgf ddfg dfgdfgdfg dfgfdg How do you find/highlight all the occurrences? What I ideally want to do is to visually select the code block and then press search to find all occurrences. 回答1: The text being searched for is stored in the / register. You can't yank or delete directly into this register, but you can assign to it using `let'. Try this: Use visual mode to highlight the code you want to

Jump to function definition in vim, without using plugins or ctags

好久不见. 提交于 2019-12-24 06:36:12
问题 is it possible to jump to function definitions in vim without using plugins or ctags? and if so, how? a related question: Jump to function definition in vim 回答1: Were it possible, why would anybody write a plug-in or use ctags ? So let us assume that it is not. You can use # and * to search backwards and forwards (respectively) for the word under your cursor in the current buffer. Or you can use :vimgrep and CTRL-R CTRL-W to search for the word under the cursor in a given path. Of course