Tag Info

Hot answers tagged

47

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 ...


26

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.


18

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 ...


16

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 your using Linux * is the x buffer (the last selected text) Then vim knows its a paste What happens otherwise is vim thinks you have typed the keys being pasted (which include the indentation combined with vim doing auto ...


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 ...


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

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 ...


3

Try this: :'<,'>s/445/53/e | s/444/53/e This works by concatenating Ex commands using the pipe (|) symbol and using the e substitution flag (see: :help :s_flags) to avoid raising an error when the pattern cannot be found.


3

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 ...


3

When you make an <A-x> mapping in Vim when x is a printable character (i.e., not a cursor or arrow key), it tells Vim to expect that character with the 8th/high bit set (aka, add 128 to the ASCII value). In your example, <A-h> means Vim will trigger the mapping when you type è. The ASCII value of h is 104 (binary 01101000) and when you set the ...


3

:%s/\${ARRAY1\[@\]}/$1/ worked for me. Apparently, you must escape [ and ] but not { and }. I always use / instead of : as seperation, but %s:\${ARRAY1\[@\]}:$1:g works as well.


3

Once in visual block mode with your lines selected try this: :'<,'>s/cron/at/g Vim has search and replace capability without the need to call an external command.


3

If you don't want to remember whether to put a \ before a non-alphanumeric character, put \v ("very magic") or \V ("very nonmagic") at the beginning of your search. If you use "very magic", any literal symbol will require a backslash. With "very nonmagic", all symbols will be literal unless they have a backslash.


2

.exrc is the configuration file for vi, whereas .vimrc is the config file for vim No. Vim will use the .vimrc file if present, otherwise the .exrc file if present Yes, unless you only put vi-compatible commands in there From the Vim help on exrc: c. Four places are searched for initializations. The first that exists is used, the others are ignored. ...


2

From the command line, observe that this succeeds: $ echo cron | sed s:cron:at: at But this doesn't: $ echo cron | sed s:cron:at:c sed: -e expression #1, char 11: unknown option to `s' c is not a sed option. The following, though, will work: :'<,'>! sed s:cron:at:g But, of course,there is no need to use sed to do such simple substitutions in ...


2

The value of $TERM must be screen-256color, so that Vim correctly detects the availability of 256 colors. (tmux reuses the terminal definitions of screen, as this tool implements similar multiplexing.) You either need to set the correct value for TERM inside tmux (sorry, I don't know how this is best done), or force 256 colors in your ~/.vimrc via set ...


2

If you need to enter non-ASCII text, try changing your mappings in vim from <A-x> to <Esc>x. If you enter only ASCII text, you may try launching urxvt with --meta8 option, and in vim set termencoding=latin1. You may also try other solutions from: http://vim.wikia.com/wiki/Get_Alt_key_to_work_in_terminal


2

vim and therefore vimdiff seem to assume that stdin is an tty. You can workaround this by something like this in your script: </dev/tty vimdiff "$file1" "$file2"


2

Try this way: :%s:\${ARRAY1\[@\]}:$1:g


2

Yes, this is inconsistent, but I also find the available choices convenient. It allows both for iterating back / forward one by one, as well as absolute addressing. Why is it that way? You could search through the vim_dev mailing list archives for messages when this feature had been proposed / a patch submitted, or ask there if anyone remembers the ...


2

Search for a plain & (unescaped) and you will match this character. If you want the & surrounded by whitespace (or rather alone at a word boundary) you'd type \<&\>. (Both of those regexps must be initiated by vim's search command /.) Note the difference: \ is the escape character for a special interpretation of the subsequent character, ...


2

The history is persisted in the viminfo file; you can configure what (and how many of them) is persisted via the 'viminfo' (and 'history') options. You can clear the history via the histdel() function, e.g. for searches: :call histdel('/') You can even delete just certain history ranges or matching lines. Alternatively, you could also just edit the ...


1

The first thing that is sourced when Vim starts up is its ~/.vimrc; after that, plugins are loaded according to the 'runtimepath' option. Therefore, to use a separate Vim environment, you just need to pass in a different .vimrc location (via -u /path/to/vimrc), and in there modify the 'runtimepath' accordingly (i.e. away from the default ~/.vim/ directory ...


1

Yes, you can do better: nnoremap <silent> gt @=":tabnext\n"<CR> Then 6gt will move 6 tabs ahead etc. Using the expression register = is a trick to make a map repeatable by a number prefix. On a side note: you can also do better by posting Vim-related questions to its own home. :)


1

Reading all subdirectories would be a costly operation, and slow down the opening of netrw considerably. As the tree display is just one (non-default) mode of several display modes, that's probably the reason why there's no such command. I tried something like this (triggering the <Enter> mapping on each directory line to open it): :global/^│ /exe ...


1

If you are running under X you can pull a couple different tricks. if you copy of vim is compiled with a gui adding -gf to vim may work for you. the g option enables the gui and the f option keeps it in the foreground. I have also been known to start vimdiff in its own xterm with xterm -e vimdiff "$@".


1

Try something like this: #! /bin/sh [ $# -eq 2 -a -d "$1" -a -d "$2" ] || exit 1 find "$1" -name .git -prune -o \( -type f -printf '%P\n' \) | \ while IFS= read -r f; do if [ -f "$2/$f" ] && ! diff -q -- "$1/$f" "$2/$f" >/dev/null; then vimdiff -- "$1/$f" "$2/$f" </dev/tty fi done The above assumes GNU ...


1

It seems you don't need to use sed or substitute at all. Just use the change (c) command. From the documentation: Visual-block change *v_b_c* All selected text in the block will be replaced by the same text string. When using "c" the selected text is deleted and Insert mode started. You can then enter text (without a line break). ...


1

The colorscheme also needs to support (high color) terminals. For the one referenced in your ~/.vimrc, wombat, this one only supports the GUI (there are only guifg= / guibg= attributes). There's a special version of wombat for 256-color xterm, here. Alternatives Plugins like CSApprox can take the GUI color definitions and convert them to a closely ...


1

The GPG man page has several options you're probably interested in, that you could work into your own personal decrypt-edit-encrypt script/function. Like: --passphrase-fd n - Read the passphrase from file descriptor n --passphrase-file file - Read the passphrase from file file... Obviously, a passphrase stored in a file is of questionable ...



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