My vim autoindent a line when I close a brace, I want to get rid of this.
I tried :
set nocindent
set noautoindent
set nosmartindent
None of them works.
What I'm observing :
lets say I have this text :
- a
- b
- c
I want to add \color{A} in front of the letter "a". This is the result after typing \color{A}:
- \color{A}a
- b
- c
How can I prevent that line from getting indented?
Related
I need vim/Gvim to highlight a set of keywords each with mentioned color in all files (it may be a text file, c source file, or anything else).
For example TODO, FIXME are highlighted in C files. Like that, I want to highlight TODO and FIXME in all files each with different colors specified somewhere. This should happen as I open a vim file and do not require me to give a command for this to happen.
How can I achieve this?
Thanks in advance for the help.
Note this is not my answer. Points go to user Ralf, answer copied over from this stackexchange, adding it here for convenience. This is the best solution I could test (if what you want is add custom highlighted words for ALL syntaxes)
function! UpdateTodoKeywords(...)
let newKeywords = join(a:000, " ")
let synTodo = map(filter(split(execute("syntax list"), '\n') , { i,v -> match(v, '^\w*Todo\>') == 0}), {i,v -> substitute(v, ' .*$', '', '')})
for synGrp in synTodo
execute "syntax keyword " . synGrp . " contained " . newKeywords
endfor
endfunction
augroup now
autocmd!
autocmd Syntax * call UpdateTodoKeywords("NOTE", "NOTES")
augroup END
I've been wanted to do this for a while, sometimes when I have a file open I want to be able to highlight certain line numbers to a different color. For example, say my LineNr is blue, and my Current LineNr is red. Say I'm on line 25, is there anyway I can change the LineNr color of lines 28-30 to green WITHOUT leaving my current line?
As a quick answer, if you don't mind highlighting only by groups of at most 8 lignes at once, you can use the matchaddpos({group}, {pos}) function and create a command to apply a highlight group to a range of lines.
command! -range -nargs=1 -complete=highlight HiLine call matchaddpos(<f-args>, range(<line1>,<line2>))
Which you can use, for example to highlight as 'cursorline' :
:28,30HiLine CursorLine
Note that completion applies on the argument for highlight groups.
To remove the group(s) of previously highlighted lines you could remove thoses that contains a particular line. I can't find a simpler way than to go through all getmatches() dicts and matchdelete({id}) the ones that contains the line on one of their 'posX' key :
function! s:RemoveMatchOnLine(line) abort
for l:match in getmatches()
let l:matchlines = values(filter(copy(l:match), 'v:key =~# ''pos\d\+'''))
if index(l:matchlines, [a:line]) >= 0
call matchdelete(l:match['id'])
endif
endfor
endfunction
command! -nargs=? LoLine call <SID>RemoveMatchOnLine(<q-args> ? <q-args> : line('.'))
Now, you can :LoLine to undo the highlighting on lines near the current line, or you can give it an argument to specify another line, so you don't have to move your cursor there : :LoLine 28.
Finally, you can set mappings :
nnoremap <leader>hi :HiLine CursorLine<CR>
xnoremap <leader>hi :HiLine CursorLine<CR>
nnoremap <leader>hc :<c-u>execute 'LoLine ' . v:count<CR>
Typing [count]<leader>hi in normal mode will highlight count lines from the cursor. And [count]<leader>hc will remove the highlighting on the group of line count.
Addendum
We could work on larger ranges using matchadd({group}, {pattern}), using \%xl to match line x. Replace call matchaddpos(... by
execute 'call matchadd(<f-args>, ''\%'.<line1>.'l\(.*\n\)\+\%'.(<line2>+1).'l'')'
and line 2 and 3 of the function by
let l:a = matchlist(get(l:match,'pattern',''), '^\\%\(\d\+\)l.*\\%\(\d\+\)l$')
if !empty(l:a) && l:a[1] <= a:line && a:line <= l:a[2]
But for me it breaks on large ranges, I would prefer to have the first solution which seems more robust.
I often use gq$ to wrap a line in Vim.
For example, if I have set textwidth=80 as my only line in .vimrc, then
option1, option2, option3, option4, option5, option6, option7, option8, option9, option10, option11
wraps to
option1, option2, option3, option4, option5, option6, option7, option8, option9,
option10, option11
However, if I want to wrap a comma-delimited list (without spaces), this command does not work, because Vim considers this line as a single word:
option1,option2,option3,option4,option5,option6,option7,option8,option9,option10,option11
Whereas desired output is:
option1,option2,option3,option4,option5,option6,option7,option8,option9,
option10,option11
How can I allow Vim to wrap by splitting a line on commas? I didn't see anything immediately in :help fo-table that is relevant to my case.
One way to do it is to use Par. It's the best program for reflowing text hands down, but you have to really like abstractions to digest the manual. My cheat sheet for it:
set the environment variable PARINIT:
export PARINIT='grTbEiq B=.,!?_A_a Q=_s>:|'
in my vimrc:
set equalprg=par\ s0\ 72
set formatprg=par\ s0\ 72
function! s:FormatPar()
let old_format = &formatprg
let textwidth = &textwidth > 0 ? &textwidth : 72
let &formatprg = 'par s0 ' . textwidth . (v:count > 0 ? 'h1p' . v:count : '')
normal }{gq}
normal }
let &formatprg = old_format
endfunc
nnoremap <silent> <F2> :<C-u>silent! call <SID>FormatPar()<CR>
With that F2 re-formats the current paragraph, and using it with a count adds a hanging indent (that is 4F2 formats the paragraph with a hanging indent of 4).
It works very well for email messages, comments in code, and the like. It also has no problem with dealing with lists like above.
I finally and getting around to migrating from aterm to urxvt and have most things setup the way I want, but I still have a hanging issue with vim. When I issue a :vsplit command the text at the bottom of each window showing the filename is white on top of a (nearly) white background making it unreadable. In aterm this test was showing up as black on the while background.
What setting controls this? I've haven't noticed this problem in other places, but haven't really looked for it either.
Here are my .vimrc
" .vimrc
" See: http://vimdoc.sourceforge.net/htmldoc/options.html for details
" For multi-byte character support (CJK support, for example):
"set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,gb18030,latin1
set tabstop=4 " Number of spaces that a <Tab> in the file counts for.
set shiftwidth=4 " Number of spaces to use for each step of (auto)indent.
"set expandtab " Use the appropriate number of spaces to insert a <Tab>.
" Spaces are used in indents with the '>' and '<' commands
" and when 'autoindent' is on. To insert a real tab when
" 'expandtab' is on, use CTRL-V <Tab>.
"set smarttab " When on, a <Tab> in front of a line inserts blanks
" according to 'shiftwidth'. 'tabstop' is used in other
" places. A <BS> will delete a 'shiftwidth' worth of space
" at the start of the line.
set showcmd " Show (partial) command in status line.
set number " Show line numbers.
set showmatch " When a bracket is inserted, briefly jump to the matching
" one. The jump is only done if the match can be seen on the
" screen. The time to show the match can be set with
" 'matchtime'.
set hlsearch " When there is a previous search pattern, highlight all
" its matches.
set incsearch " While typing a search command, show immediately where the
" so far typed pattern matches.
set ignorecase " Ignore case in search patterns.
set smartcase " Override the 'ignorecase' option if the search pattern
" contains upper case characters.
set backspace=2 " Influences the working of <BS>, <Del>, CTRL-W
" and CTRL-U in Insert mode. This is a list of items,
" separated by commas. Each item allows a way to backspace
" over something.
set autoindent " Copy indent from current line when starting a new line
" (typing <CR> in Insert mode or when using the "o" or "O"
" command).
set textwidth=0 " Maximum width of text that is being inserted. A longer
" line will be broken after white space to get this width.
set formatoptions=c,q,r,t " This is a sequence of letters which describes how
" automatic formatting is to be done.
"
" letter meaning when present in 'formatoptions'
" ------ ---------------------------------------
" c Auto-wrap comments using textwidth, inserting
" the current comment leader automatically.
" q Allow formatting of comments with "gq".
" r Automatically insert the current comment leader
" after hitting <Enter> in Insert mode.
" t Auto-wrap text using textwidth (does not apply
" to comments)
set ruler " Show the line and column number of the cursor position,
" separated by a comma.
set background=dark " When set to "dark", Vim will try to use colors that look
" good on a dark background. When set to "light", Vim will
" try to use colors that look good on a light background.
" Any other value is illegal.
set mouse=a " Enable the use of the mouse.
set undofile
set undodir=$HOME/.vim/undodir
set undolevels=1000 "maximum number of changes that can be undone
set undoreload=10000 "maximum number lines to save for undo on a buffer reload
filetype plugin indent on
syntax on
let g:Imap_UsePlaceHolders = 0
let g:Tex_EnvironmentMaps = 0
let g:Tex_FontMaps = 0
let g:Tex_SectionMaps = 0
let g:Tex_SmartKeyBS = 0
let g:Tex_SmartKeyQuote = 0
let g:Tex_SmartKeySpace = 0
let g:Tex_SmartKeyDot = 0
let g:Tex_DefaultTargetFormat = 'pdf'
let g:Tex_MultipleCompileFormats = 'pdf dvi'
let g:Tex_EscapeChars = '\'
let g:tex_flavor = "latex"
" arduino syntax
autocmd! BufNewFile,BufRead *.pde setlocal ft=arduino
call pathogen#infect()
call pathogen#helptags()
and .Xresources
! urxvt settings
!--[Title]--!
!URxvt*title: urxvt
URxvt*termName: rxvt-256color
URxvt*termName: rxvt
URxvt*cursorBlink: true
URxvt*urgentOnBell: true
!--[URL Select]--!
URxvt.perl-ext-common: default,url-select
URxvt.keysym.M-u: perl:url-select:select_next
URxvt.urlLauncher: chromium
URxvt.underlineURLs: true
!--[Fonts]--!
URxvt.font: 9x15
!URxvt.font: -*-terminus-*-*-*-*-14-*-*-*-*-*-*-u
!URxvt.font: -*-droid sans mono-*-*-*-*-12-*-*-*-*-*-*-u
!URxvt.font: xft:terminus:pixelsize=10:antialias=true
!
URxvt.scrollBar: false
URxvt.skipBuiltinGlyphs: true
!--[Urxvt Options]--!
URxvt.boldMode: false
!URxvt.imLocale: en_US.UTF-8
URxvt.loginShell: true
URxvt.saveLines: 4096
!urxvt.geometry: 110x40
URxvt.borderless: true
!URxvt.xftAntialias: true
URxvt.jumpScroll: true
!URxvt.tintColor: white
URxvt.internalBorder: 0
URxvt.cursorBlink: false
URxvt.cursorColor: #dd9900
URxvt.cursorColor2: #000000
URxvt.background: #FFFFFF
URxvt.foreground: #ddccbb
URxvt.colorBD: #ffffff
URxvt.colorIT: #bbbbbb
URxvt.colorUL: #999999
URxvt.underlineColor: #999999
!Xcursor.theme: CG
!## teh transparency stuff
URxvt.inheritPixmap: true
URxvt.tintColor: white
URxvt.shading: 0
! xscreensaver ---------------------------------------------------------------
xscreensaver.Dialog.headingFont: -*-dina-bold-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.bodyFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.labelFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.unameFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.buttonFont: -*-dina-bold-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.dateFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.passwd.passwdFont: -*-dina-bold-r-*-*-10-*-*-*-*-*-*-*
!general dialog box (affects main hostname, username, password text)
xscreensaver.Dialog.foreground: #ffffff
xscreensaver.Dialog.background: #000000
xscreensaver.Dialog.topShadowColor: #000000
xscreensaver.Dialog.bottomShadowColor: #000000
xscreensaver.Dialog.Button.foreground: #666666
xscreensaver.Dialog.Button.background: #ffffff
!username/password input box and date text colour
xscreensaver.Dialog.text.foreground: #666666
xscreensaver.Dialog.text.background: #ffffff
xscreensaver.Dialog.internalBorderWidth:24
xscreensaver.Dialog.borderWidth: 20
xscreensaver.Dialog.shadowThickness: 2
!timeout bar (background is actually determined by Dialog.text.background)
xscreensaver.passwd.thermometer.foreground: #666666
xscreensaver.passwd.thermometer.background: #000000
xscreensaver.passwd.thermometer.width: 8
! terminal colors ------------------------------------------------------------
URxvt*background: #000000
URxvt*foreground: #bfbdc0
!black
URxvt*color0: #000000
URxvt*color8: #686773
!red
URxvt*color1: #cd0000
URxvt*color9: #ff0000
!green
URxvt*color2: #00cd00
URxvt*color10:#00ff00
!yellow
URxvt*color3: #cdcd00
URxvt*color11:#ffff00
!blue
URxvt*color4: #6767cd
URxvt*color12:#6767ff
!purple
URxvt*color5: #cd00cd
URxvt*color13:#ff00ff
!cyan
URxvt*color6: #00cdcd
URxvt*color14:#00ffff
!white
URxvt*color7: #faebd7
URxvt*color15:#ffffff
! attempt to get vim to read the colors correctly
URxvt.intensityStyles: false
:hi StatusLine
:help hl-StatusLine
(Response to comments.)
If you need more context, then scroll up to the top of the section (or :help highlight-default):
These are the default highlighting groups. These groups are used by the
'highlight' option default. Note that the highlighting depends on the value
of 'background'. You can see the current settings with the ":highlight"
command.
The line you describe, showing the file name, is the status line. (:help status-line and scroll up if you need more context.) The setting that controls the display of the status line is the StatusLine highlight group (not an option). You can inspect the current setting with :hi StatusLine, and you can change it with, for example.
:hi StatusLine term=bold cterm=bold
See :help :highlight for more options.
I'm using AppendModeline function to add a modeline to my vim files:
" Append modeline after last line in buffer.
" Use substitute() instead of printf() to handle '%%s' modeline in LaTeX
" files.
function! AppendModeline()
let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d :",
\ &tabstop, &shiftwidth, &textwidth)
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
call append(line("$"), l:modeline)
endfunction
But I want to extend it. It shall support adding the current value of expandtab.
Using &expandtab, I can get a numeric representation of the current value. But something like set et=0 isn't supported by vim. It has to be set [no]expandtab.
Do I really have to test for &expandtab and append expandtab or noexpandtab to l:modeline or is there a way to get a string representation of the current value?
set expandtab? shows [no]expandtab, but I don't know how to use this in a script (or if it's even possible).
Yes, you have to do this. With :redir it is possible to capture output, but :redir-based solution is at least four lines long with regex to grab the value. Using &et is much cleaner:
… printf("… %set …", …, &expandtab ? '' : 'no', …)
Note: %set is %s followed by et (short for expandtab). Word set here is just an accident.