vim

Odd behavior of backspace in Vim (SSH to Linux from Mac)

南楼画角 提交于 2019-12-20 14:21:51
问题 I didn't change any setting of my Vim, but today the Backspace gets some crazy behavior. Every time when I hit it, it does not delete a character, but prints ^? . Anyone knows what is going on? 回答1: Not sure why it would randomly start doing this based on the information you gave, but trying adding this line to your .vimrc set backspace=start,eol,indent 回答2: The problem comes from the communication between Mac Terminal the Linux Terminal. Go to the Mac Terminal -> Preferences -> Advanced tab,

Vim formatting using gg=G with xml

可紊 提交于 2019-12-20 13:59:09
问题 I have a correctly formatted xml file, and following the command given as an answer here: How can I autoformat/indent C code in vim? I am trying to auto indent my file to display correct nesting. Before I tried to use this command I set the file type to xml using :set ft=xml as the file I started with has an extension of .mm , and also :set nowrap . Here is my ~/.vimrc file: syntax on set history=1000 set smartindent set tabstop=2 set shiftwidth=2 set expandtab How come when I issue gg=G , I

Vim formatting using gg=G with xml

独自空忆成欢 提交于 2019-12-20 13:59:07
问题 I have a correctly formatted xml file, and following the command given as an answer here: How can I autoformat/indent C code in vim? I am trying to auto indent my file to display correct nesting. Before I tried to use this command I set the file type to xml using :set ft=xml as the file I started with has an extension of .mm , and also :set nowrap . Here is my ~/.vimrc file: syntax on set history=1000 set smartindent set tabstop=2 set shiftwidth=2 set expandtab How come when I issue gg=G , I

Native Vim Random number script

夙愿已清 提交于 2019-12-20 12:42:51
问题 I know that there are various ways to get random numbers, eg, from the shell. However, I'm running vim on an android phone with very little compiled in. Also, it does not have to be rigorously random. The point is, what's an interesting, or concise, or fast (that is, with vim native functions), or short way to get a sequence of reasonably good random numbers in Vim? 回答1: Try something like function Rand() return str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:]) endfunction . I know no

How to paste something between html tags in Vim?

我的未来我决定 提交于 2019-12-20 12:37:16
问题 Pressing p pastes things bellow the current line, dit deletes things inside html tags. How do I paste something inside html tags? Nor here <p>I want to paste something here</p> Not here 回答1: The result of pressing P and p depends on what you have in the selected register at the time. If you delete or yank one or more entire lines (e.g. with dd , Y or Vd commands), then pressing P will insert the contents of your register on the line above the current line, whereas p will insert on the line

How do I get Ctrl-Backspace to delete a word in vim within gnome-terminal?

ε祈祈猫儿з 提交于 2019-12-20 12:34:46
问题 I'd like Ctrl-Backspace to delete the current word in vim insert mode. From within xterm I can pull this off via :inoremap <C-H> <C-W> but in gnome-terminal I cannot figure out a way to make it happen. When in vim insert mode, if I type control-v and then press backspace, I get ^H in xterm, and ^? in gnome-terminal. Unfortunately, :inoremap <C-?> <C-W> doesn't do the trick in gnome-terminal; control-backspace just erases a single character no matter what. Regarding ASCII codes: Gnome-terminal

To append a match efficiently in Vim :g/---/s/---/X/

℡╲_俬逩灬. 提交于 2019-12-20 12:31:47
问题 How can you refer to the match in the command g in Vim? I would like to put X after the match without replacing the match. For instance, in the following command without writing the create_title twice. :g/create_title/s/create_title/X/ You should get create_titleX by running the command to create_tile 回答1: I'm not sure why you need the g portion of the command - the substitute will only act on matching lines. Here's what you're looking for: :%s/create_title/&X/ The & represents the entire

Bash's vim mode, not vi

大憨熊 提交于 2019-12-20 12:10:50
问题 I was fascinated when I discovered vi-like bash's editing mode. One can easily toggle it by issuing set -o vi command. But is there any way to toggle vim-like mode? I mean when you are in a vi-like mode you can press v key and edit your commands in a fully functional vi editor's window but I would like to know how to force bash to start vim editor instead of vi because of the perks vim provides us (visual selection, additional commands etc)? 回答1: If you set EDITOR variable, in bash you can

Can I make vim respect my .gitignore files?

纵饮孤独 提交于 2019-12-20 12:00:10
问题 I was wondering if there is a way to get vim to read .gitignore files and use them to determine options not to present when auto-completing filenames. For example, working in python, I'd like to not see .pyc files offered for editing. I think vim has its own mechanism for this, I was wondering how to load information from .gitignore into it. 回答1: As suggested by @dwc, here's a vim script: let filename = '.gitignore' if filereadable(filename) let igstring = '' for oline in readfile(filename)

Regex to insert space in vim

ぃ、小莉子 提交于 2019-12-20 11:59:08
问题 I am a regex supernoob (just reading my first articles about them), and at the same time working towards stronger use of vim. I would like to use a regex to search for all instances of a colon : that are not followed by a space and insert one space between those colons and any character after them. If I start with: foo:bar I would like to end with foo: bar I got as far as %s/:[a-z] but now I don't know what do for the next part of the %s statement. Also, how do I change the :[a-z] statement