Can someone help fix my vimrc config? - linux

set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent
syntax on
set listchars=tab:>-
set listchars+=trail:.
set ignorecase
set smartcase
map <C-t><up> :tabr<cr>
map <C-t><down> :tabl<cr>
map <C-t><left> :tabp<cr>
map <C-t><right> :tabn<cr>
map <F1> <Esc>
imap <F1> <Esc>
set pastetoggle=<F5>
This is my vimrc. I want to fix it so that it doesn't show >---- >---- when other people tab. Thank.

Remove these lines:
set listchars=tab:>-,trail:~
set listchars=tab:>-

set list
is doing this. You can
:set nolist
if it is bothering you but I recommend keeping it for python files (you might be coding in python looking at that autocommand). ie. ... Learn to love it. create a mapping if it is a regular issue.
Also there is
:retab
to remove tabs if you have an expandtab setting.

Related

Vimrc: how to replace tabs with two spaces?

This is weird that I used to make it work with my vimrc setting to replace every tab with two spaces, but it doesn't work now.
My old setting was like this:
syntax on
filetype on
set softtabstop=2
set shiftwidth=2
set tabstop=2
set expandtab
set smartindent
But it suddenly didn't work so I have tried this:
syntax on
filetype plugin indent on
set softtabstop=2
set shiftwidth=2
set tabstop=2
set expandtab
set smartindent
with no success(it forces 4 spaces).
How can I make it work to replace tabs with 2 spaces?
Just do this much
syntax on
filetype plugin indent on
set smarttab
set shiftwidth=2
set tabstop=2
set shiftround
" converting tabs to space before writing hte a file
set expandtab
autocmd! bufwritepre * set expandtab | retab! 2

Autoindenting not working in vim?

I am currently using vim and wish to autoindent every time I need to (such as after a brace in javascript or after a colon in Python). For some reason, I tried autoindent and smartindent, but every new line gave me 2 tabs instead of one. Why is it doing this? I thought it would only insert one tab.
My current ~/.vimrc file has:
set ts=4
set autoindent
set smartindent
filetype plugin indent on
you need to set up as well:
:set shiftwidth=4 softtabstop=4
tabstop is only for the number of columns a real "\t" tab takes:
:he shiftwidth
Number of spaces to use for each step of (auto)indent. Used for
|'cindent'|, |>>|, |<<|, etc.
When zero the 'ts' value will be used.
:he softtabstop
Number of spaces that a <Tab> counts for while performing editing
operations, like inserting a <Tab> or using <BS>. It "feels" like
<Tab>s are being inserted, while in fact a mix of spaces and <Tab>s is
used.
whereas tabstop:
:he tabstop
Number of spaces that a <Tab> in the file counts for. Also see
|:retab| command, and 'softtabstop' option.
As a bonus, here's a few mappings I've set up for that, when I need to work on projects that do not use my favorite default of expand tabs with 4 spaces indent:
nmap <Leader>t2 :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
nmap <Leader>t4 :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
nmap <Leader>t8 :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
nmap <Leader>T2 :set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2<CR>
nmap <Leader>T4 :set noexpandtab tabstop=4 softtabstop=4 shiftwidth=4<CR>
nmap <Leader>T8 :set noexpandtab tabstop=8 softtabstop=8 shiftwidth=8<CR>
I use like this in my .vimrc
filetype plugin indent on
set smartindent
set autoindent
set shiftwidth=4
set expandtab
set tabstop=4
set softtabstop=4
The expandtab will replace the tabs with spaces, I think this will be perfect for coding.

When I press enter and create a new line in vim while editing CSS, it gives me two tabs instead of just one

I debated with myself whether to post it on SuperUser but I did it here.
When I have this in CSS, editing it in VIM:
#container {
then I press Return at the bracket to give me a new line, it sends the cursor two tabs to the left on the next line:
#container {
|
Instead of like this, how I want it.
#container {
|
how could I edit the .vimrc file to give me only one new tab on the next line instead of two?
My .vimrc file.
set ts=4
imap <C-Return> <CR><CR><C-o>k<Tab>
set cindent
set nocompatible
filetype indent plugin on
syntax on
set hidden
set wildmenu
set showcmd
set hlsearch
set ignorecase
set smartcase
set backspace=indent,eol,start
set autoindent
set nostartofline
set ruler
set laststatus=2
set confirm
set visualbell
set t_vb=
set mouse=a
set cmdheight=2
set number
set notimeout ttimeout ttimeoutlen=200
set pastetoggle=<F11>
set shiftwidth=2
set tabstop=1
map Y y$
nnoremap <C-L> :nohl<CR><C-L>
Thanks.
I believe your issue is that your shiftwidth is twice your tabstop. You are also setting tabstop twice, once at the top to 4 and again at the bottom to 1.
Try setting shiftwidth to the same at tabstop, there really aren't many cases that you'd want these two to be different.

Vim ignores window splitting settings in netrw

I would prefer if vim opens new windows on the right old window (when using vsplit) and under old window (when using split).
I read that I should set splitright and set splitbelow to my .vimrc. I added also g:netrw_altv=1 and g:netrw_alto=1. This settings doesn't work in netrw browser when I hit v button or type :vsplit file.txt.
My .vimrc:
syntax enable
set splitright
set splitbelow
let g:netrw_altv=1
let g:netrw_alto=1
set background=dar
colorscheme solarized
let g:solarized_termtrans=1
set t_Co=256
set expandtab
set tabstop=4
set shiftwidth=4
set smartindent
set smarttab
set gfn=Inconsolata\ Medium\ 11
set hls
set showmatch
set smartcase
set wildmenu
map <F2> :retab <CR> :wq! <CR>
In my case it was a bug in netrw. Updating it solved it.
http://www.vim.org/scripts/script.php?script_id=1075
Strange, as :vsp opens a new split on the right, and :sp on the bottom even without the options in my machine. You might want to take a look at this thread: http://tech.groups.yahoo.com/group/vim/message/51334

How to set up vim allowing to use tabs and 4spaces

I want normally always use four spaces to indent code.
Unfortunately for example Makefiles enforce the use of tabs as separator.
My idea now was to set the tab key to four spaces and some extra key (e.g. tab + shift) for the real tabs.
How do I set something like this up?
Currently my ~/.vimrc looks like:
syntax on
:set tabstop=4
:set cindent
:set autoindent
You may prefer something like this as well:
set expandtab
autocmd FileType make setlocal noexpandtab
This will always convert tabs to spaces, except when you are editing Makefiles.
Ctrl+V Tab will insert a literal tab, even if expandtab is set. If you prefer, you can map this to Shift+Tab with :inoremap <s-tab> <c-v><tab>.
You need to use shiftwidth, e.g.,
:set shiftwidth=4
:set expandtab
You may also need to use this command to convert existing tabs to spaces:
:retab
:filetype plugin on should be enough to have the tab key always insert real tabs in makefiles, using file type detection.
See :help vimrc-filetype.
While I generally prefer to convert everything to spaces, I have a specific command in my .vimrc to prevent doing so in makefiles. First I activate expandtab and set shiftwidth, but then I turn off expandtab for makefiles. Order is important here.
set shiftwidth=4
set expandtab
if has('autocmd')
autocmd FileType make set noexpandtab
endif
I also recommend the following, as they are somewhat related and possibly helpful:
set softtabstop=4
set shiftwidth=4
set smarttab
set autoindent

Resources