Hot answers tagged

56

There're two reasons: Auto insert comment Auto indenting For pasting in vim while auto-indent is enabled, you must change to paste mode by typing: :set paste Then you can change to insert mode and paste your code. After pasting is done, type: :set nopaste to turn off paste mode. Since this is a common and frequent action, vim offers toggling paste ...


31

You can do that via scp like this: vim scp://user@myserver[:port]//path/to/file.txt Notice the two slashes // between server and path, which is needed to correctly resolve the absolute path. [:port]is optional. This is handled by vim's netrw.vim standard plugin. Several other protocols are supported.


27

Oddly enough, \n in vim for replacement does not mean newline, but null. ASCII nul is ^@ (control@). Historically, vi replaces ^M (controlM) as the line-ending, which is the newline. vim added an extension \r (like the C language) to mean the same as ^M, but the developers chose to make \n mean null when replacing text. This is inconsistent with its use ...


25

You could do this by mounting the remote folder as a file-system using sshfs. To do this, first some pre-requisites: sudo apt-get install sshfs #for Debian based OS, use yum or zypper depending on your OS sudo adduser <username> fuse Now, do the mounting process: mkdir ~/remoteserv sshfs -o idmap=user ...


21

Use the \c escape sequence: /foo\c See also: http://stackoverflow.com/questions/2287440/how-to-do-case-insensitive-search-in-vim


19

zsh like most modern shells have a choice between two different keyboard mappings for command-line editing: a vi one and an emacs one. In some shells (like tcsh or readline-based ones like bash), the emacs one is the default and probably the one you expect. With zsh, you get emacs mode by default unless $EDITOR or $VISUAL contains vi (if you're a ...


19

Use the vim paste. What you want is to paste what is on the clipboard buffer "+p This selects the + and pastes it in place. If you're using Linux, * is the X/middle-click buffer (the last selected text). Then vim knows it's a paste. Otherwise vim thinks you have typed the keys being pasted and does its own auto-indentation (on top of your copied ...


19

It's possible to do this without a plugin using the w command, so the buffer contents can be used in a shell command: :w !diff -au "%" - > changes.patch (% is substituted with the path of the file being edited, - reads the buffer from stdin)


13

In vi or vim you can ignore case by :set ic, and all subsequent searches will consider the setting until you reset it by :set noic. In less there are options -i and -I to ignore case.


11

Because the way you define it py is a shell alias, and Vim doesn't know (nor care) about shell aliases. Use an environment variable instead, perhaps like this: $ PY=/opt/python3.4/bin/python3 $ export PY then in Vim: ... exec '!time ' . fnameescape($PY) . ' %' ... Edit: Added fnameescape(). It's needed if $PY contains characters that have a special ...


11

Just because you ran vi demo.c does not mean a file demo.c was created. It isn't created until you write the buffer to disk for the first time. Simply write the buffer to disk before compiling: :w This is confirmed by the message [No write since last change] you see. This message means the buffer changed (in that you created the buffer called demo.c) ...


9

You could also set your default text editor by using the following command. sudo update-alternatives --config editor


7

GNU screen supports the xterm alternate-screen feature using the altscreen setting in your .screenrc file. According to the manual: — Command: altscreen state (none) If set to on, "alternate screen" support is enabled in virtual terminals, just like in xterm. Initial setting is ‘off’. A quick check shows that screen is actually simulating the ...


7

The problem with Ctrl-Z When you suspend a process with Ctrl-Z, the process gets a SIGTSTP signal, and all execution will stop (i.e., no more CPU cycles), until a SIGCONT signal comes along. You will not be able to send vim any commands or input while it is suspended. In other words, don't use Ctrl-Z. Use vim --remote When starting your vim session for ...


7

How about :%s/\n\s\+/\t/gc That will find any newline character that is followed by white space and replace all of it with a tab thereby combining your lines.


7

Use :q!. :!q tells vim to execute a command called q in your example. See also :help ! and :help quit for details


6

With a large enough value of 'undolevel', Vim should be able to undo the whole day's changes. If you quit Vim in between, you also need to enable persistent undo by setting the 'undofile' option. Vim captures not just a sequential list of commands for undo, but actually a tree of all changes. It also has several commands around undo (cp. :help ...


6

The indexed color palette has the actual rendering open to interpretation - on actual hardware, there were different standards (especially brown vs. dark yellow, brown is more useful and nicer to look at). Just check out this: https://en.wikipedia.org/wiki/Color_Graphics_Adapter On terminal emulators, it depends on the configuration. Most emulators have a ...


6

Going to the help on navigation (:h navigation): Cursor motions cursor-motions navigation These commands move the cursor position. If the new position is off of the screen, the screen is scrolled to show the cursor (see also 'scrolljump' and 'scrolloff' options). 1. Motions and operators operator 2. Left-right ...


6

Try this: %s/$/^V^M/ (where ^V is Ctrl-V and ^M is Ctrl-M - when you type ^V it will print a ^ char then backspace over it and then when you type the ^M it will appear as ^M ... the Ctrl-V is the standard tty literal next character - run the command stty -a to show your tty's special chars).


5

Vimscript is evaluated exactly like the Ex commands typed in the : command-line. There were no variables in ex, so there's no way to specify them. When typing a command interactively, you'd probably use <C-R>= to insert variable contents: :sleep <C-R>=timetowait<CR>m<CR> ... but in a script, :execute must be used. All the literal ...


5

The built-in spellfile.vim script will attempt to download missing spell files from http://ftp.vim.org/vim/runtime/spell. In general, spell checking is not supported for East Asian languages like Chinese and Japanese, because individual words are not separated by whitespace, so a different algorithm would be needed. You probably want to :set ...


5

For yanks, Vim supports setting both unnamed and unnamedplus: :set clipboard=unnamed,unnamedplus From :help clipboard-unnamedplus: When "unnamed" is also included to the option, yank operations (but not delete, change or put) will additionally copy the text into register '*'.


5

As @lcd047 told you, aliases are not available to vim. They are also, by the way, not available to shell scripts either, unless you activate the expand_aliases option. Anyway, another choice would be to create a link instead of an alias: sudo ln -s /opt/python3.4/bin/python3 /usr/bin/py That will create a link at /usr/bin/py which points to ...


5

The tabs were inserted because you have autoindent turned on and you can disable that behavior by turning off autoindent (:set noai) before you paste into terminal. The commented lines are produced by auto commenting and can be disabled by turning that off. Alternative to those you should get the desired behavior using the toggles :set paste, pasting ...


5

Depending on what you mean when you say you do not have the rights to edit the Vim settings, there may be a way of using Vim on the server in the way you want anyway. If you can't change your user .vimrc (because you're logging in as a shared user, for example) but you can still create files, create it as a file called, say, Loom.vimrc and then call Vim ...


5

Means folk can leverage this to get a root shell, thereby bypassing your security, eg :!/bin/sh from within vim. Or :r /etc/shadow and :w /etc/shadow. And so on...


5

Vim has a built-in help. You can read the section about the argument list with the command :help argument-list and get a list of all the commands. :argadd filename to add a file to the argument list. :argedit filename to add a file and start editing it. For buffers and windows, you can read all about them in :h buffers : Summary: - A ...


5

muru and others are looking at this in terms of the programmability and configurability of vim itself; other comment-answerers are looking at SSH. But there is a third, quite different, answer. You have a keyboard layout that supports dead keys. In your layout, ~ is such a dead key, possibly mapped to the conventional U+0303 "combining tilde" ...


5

The vim command line switch -c will execute vim commands. You can pass multiple commands and passing the two following commands will start help, in only one window vim -c help -c only



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