Bad indentation vim from the clipboard - vim

Update: thank all of you, I fixed it.
We have to use this in the .vimrc file.
set pastetoggle=<F2>
I'm still new using vim, when I try to paste something from the clipboard, vim does a bad indentation.
Example:
VIM:
line
line
line
Original:
line
line
line
Now, its important to say that I'm using the new terminal in windows, using powershell.
Thank you.

you can try to enable the paste option:
set paste

Depending on which OS and which terminal emulator you are in, you might be able to use bracketed paste mode. Bracketed paste is available by default in vim since version 8.
I had an issue setting it up on my system and here is a setup that user938271 suggested me on vi.stackexchange. Add this to your ~/.vimrc:
" Activate bracketed paste in tmux
if &term =~ "screen"
let &t_BE = "\e[?2004h"
let &t_BD = "\e[?2004l"
exec "set t_PS=\e[200~"
exec "set t_PE=\e[201~"
endif
Replace "screen" by the output of:
echo $TERM
from your terminal.

It is also important to set the filetype beforehand because of the level of indentation and its rules change for different file types. For example:
:setf java
or
:setf c

Related

terminal Vim strikethrough

I'm trying to render strikethrough for markdown files in terminal vim. However, with the current plug-ins and colorscheme it either colors the text or underlines it. I'm nit-picky and I'd like the rendering of strikethrough.
Running :so $VIMRUNTIME/syntax/hitest.vim in a markdown file rightly shows the highlights including the underline/coloring, but also the groupname which is htmlStrike.
So I try adding the following to my init.vim(having read :h attr-list):
function s:ApplyStrikethrough()
highlight htmlStrike cterm=strikethrough
endfunction
autocmd FileType md call s:ApplyStrikethrough()
I've also tried the above without the autocmd, e.g. just highlight htmlStrike cterm=strikethrough. I've also tried highlight htmlStrike gui=strikethrough guisp='Red'. All I can accomplish is having no highlight at all...
I know my terminal (Kitty) is capable of rendering strikethrough, having run echo -e "\e[9mstrikethrough\e[0m".
OS: Manjaro Linux x86_64
WM: i3
shell: zsh 5.7.1
Vim: NVIM v0.4.3
Term: kitty 0.15.1
Any help is greatly appreciated, thank you!
I just ran into the same problem, and found a solution for normal vim after a while of researching.
I have put the following in my .vimrc
if &term =~ 'xterm\|kitty\|alacritty\|tmux'
let &t_Ts = "\e[9m" " Strikethrough
let &t_Te = "\e[29m"
let &t_Cs = "\e[4:3m" " Undercurl
let &t_Ce = "\e[4:0m"
endif
This will enable strikethrough and undercurl for xterm, kitty, alacritty and tmux terminals (identified by the TERM environment variable). Ideally the if-test should perhaps rely on the smxx, rmxx (standard) and So (kitty extension) capabilities from the terminfo database, but I don't know how to query it from a vim script.
This can be tested by for instance formatting the status line, or with the highlight group htmlStrike as in the question.
:hi StatusLine cterm=strikethrough`.
The trick for undercurl is mentioned in :help undercurl. :help terminal-output-codes lists the terminal codes vim knows about, which also reveals strikethrough. Note that the escape code for strikethrough is defined in ECMA-48 (called "Crossed-out"), while undercurl is defined by Kitty in its protocol extensions.
A quick note on neovim: For me, strikethrough worked out of the box with neovim, but undercurl fell back to normal underline. I have not investigated this beyond noting that neovim does not have the terminal-output-codes help topic.

SPF VIM syntax on by default

I just installed spf13 vim on my machine with CentOS. One thing I noticed is that I was not able to set "syntax on" by default.
The difference are the parenthesis color and the GLOB color. The default color is very light on my monitor, so really want to set syntax on by default.
I am not sure what went wrong. Here is my ~/.vimrc.local
filetype plugin on
syntax on
Setting up vim defaults can be funky on new installs.
First, confirm that the rc is being sourced.
Place the line echom "file is sourced on startup" into your .vimrc.
Open a new instance of vim. Type :messages then <return>. If you don't see that line, the file isn't being sourced.
To find out where vim is looking for your .vimrc:
Enter the command :echo $HOME. The folder it outputs is a good place to try putting a .vimrc or .vimrc.local file. Try both of those.
Also try :e $MYVIMRC, which might find the file you need to edit anyway.
Finally, make sure to put set nocompatible in your rc.

How to turn on syntax highlighting in VIM 7.3 OSX

System = OSX 10.9.4
I am trying to turn on syntax highlighting in vim while using the terminal. However, I am unable to get it to work properly.
Things I've tried:
located the vimrc file and added the following code:
set ai " auto indenting
set history=100 " keep 100 lines of history
set ruler " show the cursor position
syntax on " syntax highlighting
set hlsearch " highlight the last searched term
filetype plugin on " use the file type plugins
Located vimrc under directory:
cd /usr/share/vim/
The interesting thing is that once I add the code to the vimrc using vim, followed by exiting (x), and re-opening the file again, syntax is correctly highlighted in the vimrc.
However, when I try to make a new vim file called "test", copy the same code, save and exit. Re-open it, the syntax is not highlighted at all.
It appears that syntax highlighting only works when I open the actually vimrc file---and not when I try to create a new one or open another file that should have syntax highlighting.
I've also tried to create a .vimrc (exact copy) under the ~/ (directory). No success.
Made a new file called "test" and tried turning it on while active as well:
vim test
"then within vim"
:syntax on
I am really confused as to why this partially works.
Any help is much appreciated.
Cheers!
p.s. I have followed these instructions as well from: http://geekology.co.za/article/2009/03/how-to-enable-syntax-highlighting-and-other-options-in-vim
*I am aware of macvim, but would like a solution for the native vim in terminal. Thanks.
NEVER do anything in $VIM as it will work only by luck, cause unexpected behaviors and likely be overwritten next time Vim is updated.
What you have put in /usr/share/vim/vimrc should be in ~/.vimrc.
filetype on and syntax on are the bare minimum you need in your ~/.vimrc for syntax highlighting to work.
$ vim ~/.vimrc gives you syntax highlighting because the file is recognized by Vim as a vim file. Filetype detection is mostly dependent on file extensions so you can't expect any syntax highlighting in a file called test.
$ vim test.py, on the other hand, should give you syntax highlighting.
If the filetype is not detected, you can force it with :set filetype=python.
You most probably want to enable indentation along with syntax highlighting, so add these to lines to ~/.vimrc
filetype plugin indent on
syntax on
Steps with screenshots can be found here
http://osxandiosdaily.com/how-to-enable-vim-syntax-highlighting-on-mac-osx/
Inside of your file, enter command mode and enter the command
:syntax on

Pasting to vim from clipboard cuts off first few lines

I'm using vim in terminal on OSX with a blank .vimrc file. I try to paste the following from my clipboard:
#!/bin/bash
set -e
set -o pipefail
npm run precommit
using
:set paste
but in vim, what's pasted (using cmd-v) is
et -e
set -o pipefail
npm run precommit
Anybody know what's wrong?
You have to enter into insert mode before you can edit the file, you can do this by pressing the i key.
If you're using vim on OSX, you can add the following to your .vimrc:
set clipboard+=unnamed
Once you have done this, vim will use the system clipboard to read from by default for pasting. This means that, instead of having to enter insert mode first you can simply use p to paste. It also means that if you yank within vim, it's available to paste elsewhere.
I haven't tested this on any other OS, so if anyone has please feel free to add a comment...
I had the same problem, the trick was to reset my terminal by typing 'reset' before running vim.

How to set default vim colorscheme

The latest upgrade of Ubuntu made my vim colorscheme unusable. I know how to set it manually (:colo evening, for example), but I want to set the default for all vim sessions. I see reference in other places to .vimrc, but the right location and syntax have eluded me thus far.
Put a colorscheme directive in your .vimrc file, for example:
colorscheme morning
See here: http://vim.wikia.com/wiki/Change_the_color_scheme
Your .vimrc file goes in your $HOME directory. In *nix, cd ~; vim .vimrc. The commands in the .vimrc are the same as you type in ex-mode in vim, only without the leading colon, so colo evening would suffice. Comments in the .vimrc are indicated with a leading double-quote.
To see an example vimrc, open $VIMRUNTIME/vimrc_example.vim from within vim
:e $VIMRUNTIME/vimrc_example.vim
It's as simple as adding a line to your ~/.vimrc:
colorscheme color_scheme_name
You can try too to put this into your ~/.vimrc file:
colorscheme Solarized
What was asked for was to set:
the 'default', not some other color profile, and
'for all vim sessions', not simply for the current user.
The default colorscheme, "for all vim sessions", is not set simply by adding a line to your ~/.vimrc, as all of the other answers here say, nor is the default set without the word 'default' being there.
So all of the other answers here, so far, get both of these wrong. (lol, how did that happen?)
The correct answer is:
Add a line to your system vim setup file in /etc/vim/ that says
colorscheme default
or using the abbreviation
colo default
but not capitalized as
colo Default
(I suggest using the full, un-abbreviated term 'colorscheme', so that when you look at this years later you'll be able to more easily figure out what that darn thing does. I would also put a comment above it like "Use default colors for vim".)
To append that correctly, first look at your /etc/vim/vimrc file.
At the bottom of mine, I see these lines which include /etc/vim/vimrc.local:
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
So you can append this line to either of these two files.
I think the best solution is to append your line to /etc/vim/vimrc.local like this:
colorscheme default
You can easily do that in bash with this line:
$ echo -e "\"Use default colors for vim:\ncolorscheme default" \
| sudo tee -a /etc/vim/vimrc.local
#
# NOTE: This doesn't work:
#
# $ sudo echo 'colorscheme default' >> /etc/vim/vimrc.local
#
# It's the same general idea, and simpler, but because sudo doesn't
# know how to handle pipes, it fails with a `Permission denied` error.
Also check that you have permission to globally read this file:
sudo chmod 644 /etc/vim/vimrc.local
With $ tail /etc/vim/vimrc.local you should now see these lines:
"Use default colors for vim:
colorscheme default
You can just use the one-liner
echo colorscheme koehler >> ~/.vimrc
and replace koehler with any other available colorscheme. Imho, all of them are better than default.
Once you’ve decided to change vim color scheme that you like, you’ll need to configure vim configuration file ~/.vimrc.
For e.g. to use the elflord color scheme just add these lines to your ~/.vimrc file:
colo elflord
For other names of color schemes you can look in /usr/share/vim/vimNN/colors
where NN - version of VIM.
Ubuntu 17.10 default doesn't have the ~/.vimrc file, we need create it and put the setting colorscheme color_scheme_name in it.
By the way, colorscheme desert is good scheme to choose.
Copy downloaded color schemes to ~/.vim/colors/Your_Color_Scheme.
Then write
colo Your_Color_Scheme
or
colorscheme Your_Color_Scheme
into your ~/.vimrc.
See this link for holokai
OS: Redhat enterprise edition
colo schema_name works fine if you are facing problems with colorscheme.

Resources