All Questions
13,697
questions
36
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 ...
35
votes
4
answers
46k
views
Fully disable mouse in console vim
I saw completely disable mouse in console vim on Stack Overflow. It sounded like exactly what I wanted, but there the problem was related to Cygwin, so the title was a misnomer.
I want to know how ...
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 ...
34
votes
5
answers
10k
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 ...
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 ...
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 ...
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 ...
33
votes
7
answers
16k
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 ...
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 ...
33
votes
4
answers
10k
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 ...
33
votes
8
answers
16k
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 ...
33
votes
5
answers
9k
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 ...
33
votes
1
answer
12k
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 ...
33
votes
1
answer
10k
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 ...
33
votes
4
answers
40k
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 ...
32
votes
5
answers
14k
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 ?
32
votes
3
answers
5k
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?
32
votes
2
answers
12k
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-...
32
votes
1
answer
17k
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 ...
31
votes
7
answers
22k
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 ...
31
votes
2
answers
4k
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 ...
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'...
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.
31
votes
4
answers
1k
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.
...
31
votes
4
answers
12k
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 ...
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 ...
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 ...
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 ...
31
votes
3
answers
13k
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 ...
31
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:...
31
votes
5
answers
590
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 ...
30
votes
6
answers
14k
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 ...
30
votes
8
answers
10k
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?
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 (...
30
votes
2
answers
6k
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?
30
votes
7
answers
14k
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-...
30
votes
4
answers
11k
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 ...
30
votes
7
answers
28k
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 ...
30
votes
1
answer
10k
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>
...
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 ...
29
votes
6
answers
6k
views
What additional features do gVim and/or MacVim offer compared to Vim inside a terminal emulator?
I'm learning Vim by watching screencasts. And I'm wondering, why do a lot of
people use gVim or MacVim?
From what I can see, the GUI Vim version only have additional features that
involves using ...
29
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 ...
29
votes
9
answers
37k
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 (...
29
votes
3
answers
9k
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 -...
29
votes
6
answers
19k
views
Vim Code Completion for Python 3
I am running Debian Jessie and use the current vim-nox (with +python -python3). I am having a hard time trying to program in Python 3, as I struggle with Python 3 code completion.
YouCompleteMe doesn'...
29
votes
2
answers
14k
views
How do I get Vim to be able to run both python and python3 on a Linux system in the same session?
On Linux systems, packaged Vim typically has only one of either python or python3 enabled. It is possible for both to be enabled (using python/dyn and python3/dyn), but during a session, only one can ...
29
votes
5
answers
3k
views
How can I reformat a multi-line string in Vim when using the Python filetype?
Let's assume I am editing some Python code in Vim that looks a bit like:
myobj.myfunc("Some string parameter that goes on and on and on and on and sometimes doesn't"
"split ...
28
votes
2
answers
19k
views
File Type dependent key mapping
I'm trying to setup mappings for <C-]> that, depending on the buffer's file type, trigger different functions. For example, if I'm in a Javascript buffer, I want <C-]> to trigger :TernDef. ...
28
votes
6
answers
6k
views
How can I really have some fun in Vim? [closed]
I love Vim. I spend my whole life using it: At work I develop code with Vim, I edit config files with it, I write my emails with it. At home I write my todo lists and my buckets lists with it. On my ...
28
votes
3
answers
15k
views
Can the split separator in vim be less than a full column wide?
I use a tiling window manager (awesome) + a terminal multiplexer (tmux) + splits inside of vim. I have no window decorations at all, so there is no visual split between them at all if the content of ...