All Questions

Filter by
Sorted by
Tagged with
35 votes
5 answers
17k views

Git Fugitive how to git add a visually selected chunk of code

I would like to know if i could select some code in visual mode and git add it ? I checked with fugitive.vim but i didn't find how to do it. Is it possible ? Or is there any other plugin to do it ?
albttx's user avatar
  • 1,175
35 votes
3 answers
80k views

How do I stop recording while in command line?

When I am recording a macro with q and I am done, I can type: q to stop recording if I am in normal or visual mode. <c-o>q to stop recording if I am in insert mode. .. How do I stop recording ...
iago-lito's user avatar
  • 1,112
35 votes
8 answers
3k views

How do I move vertically until reaching a non-whitespace character?

In a very long file with (accurately-) indented code, it may be helpful to move directly to a line of text above or below the cursor which delimits the indenting. (One way of doing this could be via ...
alxndr's user avatar
  • 1,346
35 votes
1 answer
13k views

Can I search for a Unicode combining character in Vim?

I have a file with the character ã (lowercase a + combining tilde). Encoding and fileencoding are both utf-8. ga shows <a> 97, hex 61, octal 141 <~> 771, Hex 0303, Octal 1403 (but ...
cxw's user avatar
  • 974
35 votes
1 answer
11k views

How do you open a new buffer in the current window?

I've got a few tabs open with different window setups. I'd like to open a new blank buffer in the current window, without having any more splits/windows or tabs Is there any way to do this? I know ...
JonnyRaa's user avatar
  • 1,191
35 votes
1 answer
19k views

What does z stand for in vim?

I was looking up at tips on screen shifting and came across the following tips: zz = shift current line to middle of screen zt = shift current line to top of screen zb = shift current line to bottom ...
James Franco's user avatar
  • 1,091
35 votes
4 answers
46k views

When to use :grep and :vimgrep in vim?

In vim :make makes it easy to build and fix errors, and :grep and :vimgrep behaves like :make. But why do you need these two commands? Why not just search for the pattern and just press n? What are ...
Qian's user avatar
  • 453
34 votes
5 answers
3k views

Is there a text object for the entire buffer?

I often find myself typing commands like gg"+yG or ggdG and would like a more efficient way to do this without having to move the cursor twice. Is there any command that I can use e.g. y[movement] to ...
Random832's user avatar
  • 1,202
34 votes
5 answers
11k views

What is the easiest way to insert Unicode characters into a document?

When writing documents occasionally I want to insert Unicode characters into the text. Sometimes I know the character code and sometimes I look it up on the web. Currently I go to insert mode and ...
Martin York's user avatar
  • 6,492
34 votes
2 answers
21k views

Execute current buffer as bash script from vim

I use vim for bash scripting, and sometimes I write a one-time script. Usually, I don't want to create a new file, make it executable, execute it and then remove it. For instance I open vim and type ...
St.Antario's user avatar
  • 1,107
34 votes
5 answers
3k views

Performing certain operations without clearing register

Frequently, in configuration files I might copy and paste a block of lines, then I want to make small changes to that block. After pasting, I use x to delete characters that I want to remove, then ...
durron597's user avatar
  • 2,141
34 votes
5 answers
3k views

How to replace a word with a yanked word in normal mode?

When I have to replace a word with another word I yank before, I usually use a workflow which seems unnatural to me: Let's say I have this text: foo bar buzz And I want to yank foo and replace bar ...
statox's user avatar
  • 49.6k
34 votes
5 answers
10k views

How to use an external command in Vim to modify selected words and lines?

Something I've found useful in other editors is the ability to: take the selected text run an external command and pass the selection to its stdin take the external commands stdout and replace the ...
ideasman42's user avatar
  • 3,713
33 votes
6 answers
15k views

How to reverse the order of lines?

How can I reverse the order of lines so that the first line appears at the end and the last line appears first? (Could be all the lines in a buffer, an address range, or a linewise visual mode ...
200_success's user avatar
  • 9,489
33 votes
7 answers
17k views

Can I join lines with a comma (or another character)?

I know I can join lines in Vim with J and several variants thereof (gJ, etc.); J will "Remove the indent and insert up to two spaces". But is there also a straightforward way to insert another ...
Martin Tournoij's user avatar
33 votes
4 answers
78k views

Remap Esc key in Vim

Is it possible to remap the Esc key to another key in Vim? When I'm using Vim in a full screen VMware vSphere web client console window and I press the Esc key to exit edit mode, it also takes me out ...
Beam Davis's user avatar
33 votes
5 answers
25k views

Biggest differences between Vim and vi

Today, I decided to try vi instead of Vim; I wanted to see how different it is. I didn't notice much differences at all. The biggest thing I noticed was how vi didn't say -- INSERT -- when I went ...
xenia's user avatar
  • 451
33 votes
4 answers
11k views

Delete from cursor till nth occurence of character x

I know that I can delete from the cursor till and including the first occurence of a character x with d/x<CR> or with v/x<CR>d if I want to see the selection first and then delete. How can ...
user2609980's user avatar
33 votes
4 answers
15k views

Math calculations in Vim?

I saw someone insert the result of an expression in vim, but I don't remember how it was done. For example, say I want to calculate and insert the result of 7 * 7, is there a calculator that I can use ...
Philip Kirkbride's user avatar
33 votes
3 answers
6k views

How to apply a setting in all open tabs and windows?

Is there an option to apply a setting in all tabs and windows, e.g. apply :set number to all open tabs?
vfclists's user avatar
  • 887
33 votes
8 answers
18k views

Faster way to move a block of text

Here's how I usually copy a block of text or code: Select the block with Visual mode (V) and delete it with d; or if it's just a single line, just use dd. Go to where I want the text to be, I am too ...
Martin Tournoij's user avatar
33 votes
5 answers
624 views

How can I treat LaTeX quotes as a text object?

Quotation marks in LaTeX are different than in normal text, in that they're formatted ``like this'' (or `like this' for single quotes). This makes it difficult to navigate through them in Vim. I ...
Doorknob's user avatar
  • 15.1k
32 votes
8 answers
27k views

How to go to previous open buffer from Vim command line?

I am trying to write a Vim function which should make the window go to the previous open buffer. How can I do it from the command line? My first idea was to find out some Ctrl-O command line ...
ephemerr's user avatar
  • 813
32 votes
2 answers
13k views

Why is Vim for Debian compiled without clipboard?

I'm curious as to why the default Debian package for vim (the one you normally get by sudo apt-get install vim) isn't compiled with clipboard support? Neither the regular -clipboard or -Xterm-...
Gustav Blomqvist's user avatar
32 votes
3 answers
14k views

Undo in insert mode

Is there a command to undo the last operation performed while in insert mode? I just pasted text from the wrong register using <C-r>, and I have two options: Delete by hand what I just pasted ...
mrzool's user avatar
  • 1,012
32 votes
2 answers
5k views

What's the difference between "quit" and "abort"?

When I try to open a file from multiple vim instances, I get an error with several options: Swap file "~/.vim/tmp/file.swp" already exists! [O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:...
Kevin's user avatar
  • 621
31 votes
8 answers
11k views

How to generate random numbers?

I would like to generate one or few random numbers separated by new line. How this can be done?
kenorb's user avatar
  • 18.3k
31 votes
2 answers
7k views

What is the mnemonic for Ctrl-Y (in normal mode)?

I know "expose one more line" for Ctrl-E, but why use Ctrl-Y to expose one more line at the top? Is there an easy mnemonic for this that I'm missing?
Wildcard's user avatar
  • 4,389
31 votes
5 answers
7k views

Delete until the right end of the current inner block

Let's say that I have a code like this (| represents the cursor position): func1(x|, func2(), y); I would like to get: func1(x|); Is there a way to delete the code from the position of the cursor ...
Mateusz Piotrowski's user avatar
31 votes
2 answers
5k views

Is lookaround possible in vim's regex system?

I have encountered many situations in vim where it would be useful to have lookaround statements. I have tried using the standard lookaround syntax ((?=), (?!) etc ..), but it appears vim does not ...
EvergreenTree's user avatar
31 votes
3 answers
10k views

How can I redefine plugin key mappings?

I have installed a plugin that doesn't provide a mechanism to disable the key mappings it defines. I want to redefine one of the mappings (<leader>cc) defined by the plugin for my own pursope, I'...
toro2k's user avatar
  • 4,862
31 votes
3 answers
9k views

How to create my own autocomplete function?

How do I create my own list of auto-completion for certain filetypes? For example I would like css and html to autocomplete from the list of css classes in FontAwesome.
firedev's user avatar
  • 2,382
31 votes
9 answers
39k views

arrow keys don't work in insert mode

When I hit the arrow keys in insert mode I get characters instead of navigation: I'd like to be able to use the arrow keys to navigate. Things I've tried I have set nocompatible in my ~/.vimrc (...
minseong's user avatar
  • 2,291
31 votes
4 answers
2k views

Why can ci" be outside of quoted area and ci( only works inside parentheses?

When using ci" the cursor does not have to reside in the double quoted area. |String somestring = "some text"; Assuming the pipe is the cursor position, ci" will make it jump to the quoted area. ...
Reaver's user avatar
  • 603
31 votes
4 answers
7k views

How do I deal with very long lines in text (500+ characters)?

For some text formats, line breaks matter. For example, I often use Vim to write MediaWiki documents, where you can't just put a linebreak anywhere (unlike Markdown). So I'm forced to write lines ...
Martin Tournoij's user avatar
31 votes
3 answers
6k views

Learning Vim after vimtutor

What should the next steps to learning Vim be, after completing vimtutor? I've watched videos on YouTube, read tutorials online and questions/answers on SE, and am busy reading Practical Vim. Are ...
SabreWolfy's user avatar
31 votes
2 answers
6k views

Swap function arguments

When refactoring code it would be useful to be able to swap function arguments. Changing for eg: func(foo[0], bar(), baz.spam) into func(baz.spam, foo[0], bar()) Is there some way to swap ...
ideasman42's user avatar
  • 3,713
30 votes
5 answers
15k views

How do I close Vim externally?

Let's say I have a X11 server that's hanging, keeping me from saving the work from the XTerm Vim session that X11 server controls. (Not GVim, just regular Vim-in-XTerm.) Is there a way that I could (...
DevSolar's user avatar
  • 789
30 votes
7 answers
15k views

Easiest way to switch git branches

Right now I'm using fugitive to manage almost everything git related, but I can't find a good workflow to quickly visualize and switch between available branches. I can do :Git checkout <branch-...
Sergio D. Márquez's user avatar
30 votes
4 answers
12k views

How to show search results for all open buffers

One thing I often do (but rely on the command line to do) is searching/grepping in multiple files. Is there a way to display search results for all the open buffers? Ideally, I'd like to have a new ...
Roflo's user avatar
  • 767
30 votes
3 answers
21k views

What is the purpose of `s`?

What is the intended use case for the s command in normal mode? I've been looking at it for some time, inadvertently pressing s, but can't find any use case that would make sense for me.
Dumitru's user avatar
  • 780
30 votes
7 answers
31k views

How can I get Vim to show documentation of a C/C++ function?

Most editors have a feature like when you press some keys by placing caret over a function, it pops the documentation of that function along with number and type of arguments that function takes. I ...
sherelock's user avatar
  • 401
30 votes
2 answers
3k views

How can I perform a search when vim displays content using "more" pager?

I want to see the value of a variable, so I run the command :let Vim displays the results of this command using the --more-- pager. How can I search this for a phrase, e.g. html? I've looked the ...
the_velour_fog's user avatar
30 votes
3 answers
10k views

What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?

I've gone through the autocmd.txt help, but the information about this is scattered and not always present (eg. with BufRead). Could someone who understands this well list the order of these events -...
Sundar R's user avatar
  • 751
30 votes
1 answer
11k views

Understanding CTRL-U combination

In this answer I faced the CTRL-U used in function call after : and before the actual function name. :nnoremap <buffer> <cr> :<C-U>call append('.', repeat([''],v:count1))<cr> ...
user3663882's user avatar
30 votes
1 answer
7k views

How can I get both splits to scroll left or right at the same time?

I want to open up two different parts of a document in horizontal splits (using :sp) and scroll both of them left and right together. For vertical scrolling, you would use scrollbind. However, I'm not ...
Christopher Bottoms's user avatar
29 votes
5 answers
14k views

Can I do an interactive :substitute (search & replace)?

Sometimes I use :s with a complicated regexp which may or may not be correct, or I'm not sure if I want to replace all matches. Is there any way I can tell Vim to confirm every match it finds before ...
Martin Tournoij's user avatar
29 votes
4 answers
24k views

Multiple cursors at desired location

I'm using vim-multiple-cursors plugin. I would like to put cursors exactly where I want. For example ([x] are the cursor positions): Lorem ipsum dolor sit amet[1], consectetur adipiscing elit, sed ...
tomasyany's user avatar
  • 444
29 votes
6 answers
16k views

What are practical uses of the client-server mode?

I know that Vim allows a client server mode (:h clientserver): it is possible to turn it into a server which will get some commands and execute them and as a client which will send the commands to the ...
statox's user avatar
  • 49.6k
29 votes
2 answers
14k views

VIM swap-file best practices?

Everytime I cut out of a session in vim by losing my connection I'm rather filled with dred (and yet I continue to use vim...what a masochistist I must be) because when I open my files again a pile ...
leeand00's user avatar
  • 3,479

15 30 50 per page