Tag Info

Hot answers tagged

26

In addition to uprego's answer, you can press Ctrl+G (in normal mode) to get the current buffer's name as well as the total number of lines in it and your current position within it. Update As per rxdazn's comment, you can press 1 before Ctrl+G to get the full file path. If you press 2, you get the full file path and the buffer number you currently have ...


16

Create a custom mapping for frequenly used tasks. If you quit vim often, create a mapping with few key strokes, e.g. nnoremap <leader><leader> :xa<cr> If the <leader> is set to comma using let mapleader = "," hitting comma twice is a quick way of quitting vim and saving your changes. If you want to save one more key stroke when you ...


16

You can edit remotely with a local vim or gvim. :e scp://me@someplace.else/~/myfiles/whatever.file scp is a secure copy protocol. It authenticates the same way as ssh, so your ssh key needs to be available, etc. There are various other protocols supported (see :help netrw-externapp) but scp is probably the easiest if you are already using ssh to the ...


14

Vim was not designed for large files. It has certain features which drastically slow down the user experience. For instance, it loads the file into memory which basically limits to edit files smaller than your memory size. Furthermore, features such as syntax highlighting, swap file and undo are very inefficient with large files and slow thing down even ...


13

When you make no changes to the actual content of the file, you can simply quit with :q. However if you make edits, vim will not allow a simple quit because you may not want to abandon those changes (especially if you've been in vim for a long time editing and use :q by accident). The :q! in this case is a force the quit operation (override the warning). You ...


13

ZZ in normal mode saves the current file if modified and exits or closes the current window/tab (same as :x but not :wq which writes the file even if it hasn't been modified). To exit unconditionally after having written all the modified files in all windows, tabs and hidden buffers, you need :xa (it still won't exit if some files can't be written for a ...


12

You can add this to your .vimrcfile, or temporarily while in vim. vimrc - set laststatus=2 in vim - :set laststatus=2 To get the full path you can add this command, again to either your .vimrc or while in vim. vimrc - set statusline+=%F in vim - :set statusline+=%F Examples normal mode ...


11

There are many color schemes which are usually distributed together with vim. You can select them with the :color command. You can see the available color schemes in vim's colors folder, for example in my case: $ ls /usr/share/vim/vim73/colors/ blue.vim darkblue.vim default.vim delek.vim desert.vim elflord.vim evening.vim koehler.vim morning.vim ...


11

Visual Block Mode First, move the cursor to the first char of the first line in block code you want to comment, then type: CTRL + V then vim will go in to VISUAL BLOCK mode. Use j to move the cursor down until you reach the last line of your code block. Then type: Shift + I now vim go to INSERT mode and the cursor is at the first char of the firts ...


10

You can use: :6,8s/^#// But much easier is to use Block Visual selection mode: Go to beginning of line 6, press Ctrl-v, go down to line 8 and press x. There is also "The NERD Commenter" plugin.


10

If you start screen in a maximized xterm (Alt-Enter in xterm) as: screen -c this-file Where this-file contains: focusminsize 75 25 split -v focus only split -v split -v focus You'll get a center region of width 75.


10

zt puts current line to top of screen z. puts current line to center of screen zb puts current line to bottom of screen More info about scrolling at http://vimdoc.sourceforge.net/htmldoc/scroll.html or in vim type :help scroll-cursor


10

You may find q: useful. It opens the command-line window. The command-line window looks like this: I tried to make an animation of its usage: Also see c_CTRL-F, which opens the command-line window from command mode. You can also re-run the last command from normal mode by typing @:.


9

Beside the paste option mentioned by Mat, you can also directly access the X clipboard from VIM: "*p to insert the X11 selection "+p to insert the X11 clipboard You need a VIM version with X11 support (in Debian and its derivatives you need to install the vim-gtk or vim-gnome package). For more information, see the documentation (:help x11-selection).


8

sudoedit allows you to edit a file with an editor running on your own user id. It copies the file to a temporary file which your editor can then write into. As soon as the editor is closed, the edited file is copied back. There is no built-in possibility to automatically write changes back while the editor is still running. So you need either run the ...


8

According to this cheat sheet it would seem to come down to punctuation. w jump by start of words (punctuation considered words) W jump by words (spaces separate words) e jump to end of words (punctuation considered words) E jump to end of words (no punctuation) Example demo using w            ...


7

You should add it to your shell’s configuration file. For Bash, this is ~/.bashrc or ~/.bash_profile. You should also set $VISUAL, as some programs (correctly) use that instead of $EDITOR. Additionally, unless you know why, you should set it to vim instead of vi. TL;DR, add the following to your shell configuration (probably ~/.bashrc): export VISUAL=vim ...


7

In Virtual-Replace-Mode the Buffer is harder fixed to its origin position. 1. Hello World ^ Cursor 2. I like cheese 3. And beer When entering normal replace mode and hitting Internet<CR>And others the new buffer will be like this: 1. Hello Internet 2. And others 3. I like cheese 4. And beer When doing the same in Virtual-Replace the ...


7

less doesn't support syntax highlighting. vim, like all vi clones has a read-only mode called view which you can use to just view files. it supports all features of vim including syntax highlighting. e.g. view filename.py the main difference between view and vi is that view doesn't "lock" the file you're viewing by creating a .swp file.


7

The default directory (/var/tmp) for the vi editing buffer needs space equal to roughly twice the size of the file with which you are working, because vi uses the extra lines for buffer manipulation. If the /var/tmp directory does not have enough space for the editing buffer (e.g., you are working with a large file, or the system is running out of space ...


7

So any way to provide a different vimrc file ( maybe at command line, giving it as parameter each time as vim --vimrc=somefile file-to-open) ? Yes, use the -u parameter: vim -u ~/.my-custom-vimrc From man vim: -u {vimrc} Use the commands in the file {vimrc} for initializations. All the other initializations are skipped. Use ...


7

See the manpage: -u {vimrc} Use the commands in the file {vimrc} for initializations. All the other initializations are skipped. Use this to edit a special kind of files. It can also be used to skip all initializations by giving the name "NONE". See ":help initialization" within vim for more details.


6

Because Vim is invoked from inside the pipeline, the stdin is connected to the previous pipeline's output, not the terminal. As an interactive command, Vim needs to receive its input from the terminal. Better avoid the pipe, e.g. via $ vim $(grep -rl test .) or from inside Vim: :args `grep -rl test .`


6

In "vi" mode you can edit/navigate on the current shell prompt like a line in the vi editor. You can look at it like a one-line text file. Analogously in "emacs" mode you can edit/navigate the current command line using (some) of Emacs' shortcuts. Example For example in vi-mode you can do something like (in bash): $ set -o vi $ ls hello world <ESC> ...


6

Method #1: vim I believe you can do what you want with the following keyboard commands in vim, as follows. NOTE: =, the indent command can take motions. So: gg to get the start of the file = to indent G to the end of the file Putting it all together: gg=G. Method #2: without vim This isn't a vim solution but I came across this Perl script titled ...


6

You can do it manually with this command: :hi Comment guifg=#ABCDEF Where ABCDEF is an appropriate color hex code. To make it permanent, you will need to add these lines to your ~/.vimrc file (using green as an example): syntax on :highlight Comment ctermfg=green


6

Can you not use this ssh option instead to keep the connections from disconnecting? Try this option in your ~/.ssh/config file: ServerAliveInterval=15 excerpt from man ssh_config ServerAliveInterval Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted ...


6

You can use a .vimrc file in your $HOME to load commands whenever you start vim. vim $HOME/.vimrc Just put your command as one line; commands in the .vimrc are used in ex-mode, so you don't need to put the colon at the beginning (so use colorscheme toto rather than :colorscheme toto). You can find plenty of example .vimrcs online with lots of neat tricks ...


6

Ranges: You can do it with the following command: :66,70s/^/# for comment, and for uncomment: :66,70s/^#/ obviously, here we're commenting lines from 66 to 70 (inclusive). Hope this helps. Regards.


5

TTY framebuffer console has no way to have more than 8-16 colors without kernel hacking, see this quote: "Although the Linux frame-buffer supports 256 (or more) colors, the Linux console driver does not; therefore, console applications are still limited to 16 colors on the Linux console, frame-buffer or not." So you can have no more than 16 or 8 colors. ...



Only top voted, non community-wiki answers of a minimum length are eligible