Questions tagged [vimrc]
Vim reads initialization commands from a file called vimrc on startup. This can be used to set settings, define functions, execute autocommands, and more.
1,372
questions
1
vote
1answer
37 views
Silent mapping that automatically redraws — no messages or blank screen
I would like to open a url in vim. Using gx from netrw has been problematic, so I created the following simple mapping:
nnoremap <leader>k !open <C-R><C-F><CR>
This gets the ...
4
votes
1answer
96 views
Getting gx to open a url
I have gx which works with opening files. However, when I try and open a url, it always tries using wget:
[No write since last change]
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0....
0
votes
1answer
11 views
vim plugin changes rust files to use a ts of 4 rather than 2
Let's say I have a simple file,
echo -n "\tTABBED ONCE" > foo.rs
And then I have in my .vimrc the following,
set ts=2
call plug#begin('~/.vim/plugged')
call plug#end()
How come I open that file ...
1
vote
1answer
42 views
Where to put a vim function
I have created a helper function that will insert a number of blank lines and a keyboard shortcut of T to execute it. This way I can do something like 5T to insert five blank lines with the cursor ...
0
votes
0answers
14 views
Entering 'Ex' mode [duplicate]
I've come across the following a few times accidentally (I think when pressing capital Q):
Entering Ex mode. Type "visual" to go to Normal mode.
It seems that Ex mode works almost identically to :...
0
votes
1answer
80 views
GVim Shows Python Support Error When Opening
Every time I open up gVim there is an error that says that Python is not supported. I have checked numerous websites and everything that I have tried does not seem to work. In my vimrc file, I have ...
1
vote
1answer
59 views
Combining “normal” commands in a function
Suppose I have the following two lines in a function:
execute "normal! o"
execute "normal! S"
Is there a way to combine these so it is simpler, for example:
execute "normal! o<c-o>S"
It ...
0
votes
1answer
38 views
Silently call a mapping that accepts a range
I have the following function that I'm calling to insert blank lines under the cursor:
function InsertBlankLine()
call LogOutput('*** START ***', "DEBUG", {'line': expand('<sflnum>'), '...
0
votes
0answers
19 views
How to get a (repeat) number that is passed to a vim function [duplicate]
Let's say I have a mapping such as this:
nnoremap K :call MyFunction()
And my function is:
func MyFuction()
echom ("how to get the 10 passed to me?")
endfunc
Let's say the user presses 10K on ...
1
vote
1answer
29 views
Add N blank lines below cursor
I would like to create a mapping that will add N lines below the cursor and return the cursor to where it started. For example, to add ten lines I would do:
10o<esc>10k
How could I create ...
0
votes
1answer
34 views
Uppercase marks in vim
What is the scope of uppercase marks in vim? For example, this says:
Each file has a set of marks identified by lowercase letters (a-z). In addition there is a global set of marks identified by ...
0
votes
1answer
21 views
Put to a particular line
I would like to put the current text in a register onto line 10. How I am doing it now is yanking the text, then going up to that line and then pasting the text, but I'd like to stay on the current ...
0
votes
0answers
60 views
Yank until end of line
Is there a one-letter abbreviation for yank-until end of line? For example, there is:
D delete til end of line
C change til end of line
y$ was the closest thing I can find for this (Y yanks full line)...
1
vote
1answer
90 views
Issue running file from within NeoVim
I had the following remap
autocmd filetype cpp nnoremap <F5> :w <bar> silent !g++ -ulimit -Wall -Wno-unused-result -std=c++11 -O2 % -o %:r && %:r<CR>
When I run this in ...
1
vote
2answers
80 views
JSON quotes not hiding and I *want* them to
TL;DR
What I Want:
JSON files to hide their double quotes (") until I enter insert mode on a line, in which event the quotes reappear. I had this behavior on another machine, but I cannot replicate ...
1
vote
1answer
31 views
Ways to improve a function
Perhaps this is more of a 'code-review' question, but I think this is perhaps the best (or only) place to post this question. I've been working over the past few days to understand how vim functions ...
0
votes
1answer
16 views
Bulk variable assignment
Is there anyway to combine variable assignments in vim? For example, say I have:
let q1 = ""
let q2 = ""
let q3 = ""
let q4 = ""
Is there an alternative, such as:
let q1, q2, q3, q4 = "", "", "", ""...
-1
votes
1answer
44 views
Pause execution in vim
Is it possible to do something like this in vim:
function MyFunction
echom "Part 1"
raw_input('...') # python equivalent (or input(...) in python3)
echom "Part "2"
endfunction
That is, a ...
0
votes
1answer
134 views
Execute the contents of a register
Let's say I have the following text which I highlight:
s/ /","/g
And then I yank it into the a register:
"ay
How do I then run those commands? I thought doing @a would execute those commands, but ...
0
votes
2answers
25 views
Vim get first line in a register
I have a multi-line string that I'm reading by:
let a = getreg('*')
What would be the best way to get the first line of that string? I was hoping I could do something like:
match
getbufline
But am ...
1
vote
1answer
45 views
inoremap up arrow key
It seems that the ctrl-sequence that vim sends for the <up> key is:
^[OA
This seems to work as an <up> arrow in all modes except insert mode, where it inserts in an "A" in that mode.
...
0
votes
1answer
78 views
Importing functions, variables from another file
I am trying to spread up some functions across files to make it a bit more manageable (and also to see how that works. So far I have three dummy variables/functions in one file:
# second.vim
let ...
0
votes
0answers
98 views
Understanding local (s, l, and a) variables
From the docs, local variables are defined as:
script-variable s: Local to a :source'ed Vim script.
function-argument a: Function argument (only inside a function).
local-variable l: ...
0
votes
1answer
27 views
Getting the line number and function name of a function caller
I am writing a basic log function so that I can print debug output to a file (and perhaps more-so, to practice writing a function in vim). Here is where I am at right now:
let g:log_level_map = {'...
0
votes
1answer
21 views
Passing args, kwargs in vim function
What are the possible ways to pass a variable to a function in vim? Through trial-and-error, it seems like I can do:
:call LogOutput('asdf', 'WARNING')
But not:
:call LogOutput('asdf', level='...
0
votes
1answer
10 views
Calling a function with a variable in vim
This seems like it should be the easiest thing to do, but I'm having trouble calling a vim function with a variable. For example, I have the following function:
func Run1()
echom 'Running run1'
...
0
votes
1answer
16 views
Defining a variable outside of a function in vim
I would like to use a default argument that is defined outside of the function, for example:
let DEFAULT_FUNCTION_NAME = 'Toggle3'
func Run(function_name=DEFAULT_FUNCTION_NAME)
echom ...
1
vote
1answer
14 views
Vimrc syntax move up and down a certain line continously
So I am new to Vim and I am trying to understand the language of vimrc. I have this in my vimrc:
map <F8> <C-E>: sleep 100m<CR>j<F8>
This would automatically move the cursor ...
1
vote
1answer
20 views
Convert very long execution mapping into a proper function
I commonly will have a long list of ids that I will need to convert into a tuple for a SQL query or perhaps to create a array in python/javascript. Here is the command I've written to format a list of ...
0
votes
0answers
24 views
Go back to previous cursor position (column) on same line
When I execute a function in vim, it puts my cursor back on the line at column 1. Is there a way to get back to where my cursor previously was on that line, i.e., the exact column number?
I thought ...
1
vote
1answer
25 views
Redirecting output in sub-functions
I am trying to write a wrapper that will execute the function that the cursor is over and send its output to a log file. Here is what I have so far:
nnoremap <expr> GG ExecuteCurrentFunction()
...
0
votes
2answers
29 views
Redirect echom output in a function to a log file
I would like to debug functions a bit more easily. Instead of running them and having to do:
:10 messages
To actually just have a vim.log file opened and tail -f'ed so I can see the output while it'...
0
votes
0answers
39 views
Redirect output of vim command into the vim buffer
To read a file into the vim buffer I can do something like:
:r myfile.txt
Or to grab a command's output:
:r !ls
Is there a way to run a vim command and get the output to where my cursor is? ...
0
votes
0answers
21 views
Using hlsearch and noh
I am using the following two items in my mapping:
set hlsearch
nnoremap <esc><esc> :noh<return>
When I search I normally like to see highlighting, and then once I get to 'where I ...
0
votes
0answers
8 views
Converting if to ternary not working after first execution
I have two functions, one using an if statement and one using (or trying to use) a ternary expression:
nnoremap <expr> Z Toggle1()
func Toggle1 ()
if g:colors_name == "OceanicNext"
...
1
vote
1answer
154 views
Usage of printf command in vim
I see from :h printf that there's a print function in vim:
printf({fmt}, {expr1} ...) printf()
Return a String with {fmt}, where "%" items are replaced by
...
0
votes
0answers
7 views
String concatenation/formatting similar to c [duplicate]
To combine a string I am doing something like:
echom '111 full_string: ' . full_string
Is there a way to "in-line" it, for example, something like:
echom '111 full_string: %s' % full_string
0
votes
1answer
41 views
How to 'enter' or add a carriage return in an <expr> mapping
In the following nnoremap:
nnoremap <expr> <leader>3 ToggleColors()
func ToggleColors()
if g:colors_name == "OceanicNext"
return ":colorscheme TextMate"
else
...
0
votes
1answer
22 views
Writing a vim function with string printing and concatenation
I am trying to write my (first) function which is (eventually to be) a toggle on my colorscheme. What I have now is as follows:
nnoremap <expr> <leader>3 ToggleColors()
func ToggleColors()...
0
votes
1answer
113 views
Variable vs global variable
In h: internal-variables it mentions the "global" variable which is prefixed by g:. What would be the difference between:
let g:var = "xyz"
And:
let var = "xyz"
Does the absence of a prefix mean g:...
1
vote
1answer
26 views
Let vs set syntax in vimrc
I can do the following to set the synmtaxcol:
:set synmaxcol=4
Or:
:let &synmaxcol=4
However, when doing the same with colorscheme, only this works:
colorscheme TextMate
And not:
let &...
-2
votes
1answer
38 views
autocmd vs augroup example [duplicate]
Is there any difference between the following two commands:
autocmd FileType html,htmldjango inoremap <buffer> <leader>1
And converted to an autocmd:
augroup filetype_html
...
0
votes
1answer
28 views
Remember how variable/param assignment is done
It seems quite tedious for me to remember how various settings are assigned, and so I find myself looking at :h or google or posting here to figure out how each setting is assigned (or just doing ...
0
votes
1answer
24 views
Order of when a variable is set or overriden
In some trial-and-error testing using the following two statements:
iabbrev <buffer> return NONONON
autocmd FileType python :iabbrev <buffer> return YESYESYES
It looks like regardless of ...
0
votes
1answer
31 views
Restricting filetype mappings
I have written the following mapping in my vimrc:
autocmd FileType python :iabbrev <buffer> for for item in:<left>
After I source the python file it works. However, now whenever I ...
0
votes
0answers
22 views
How to re-source a file based on filetype [duplicate]
I am trying to add the following mapping into my vimrc:
nnoremap <leader>sv :source $MYVIMRC | filetype detect<cr>
This works in command mode, however, in the mapping I get:
E475: ...
0
votes
0answers
20 views
What is required to update an autocmd?
From trial and error, to update the following command:
autocmd FileType python nnoremap r ^i#<esc>
I have to either:
(re-)open a python file; or
Run :so $MYVIMRC; then set ft=python in that ...
1
vote
1answer
41 views
Autocmds for particular filetypes
I'm trying to understand using the autocmd to modify properties for certain files. Here is a basic example I have in my vimrc:
syntax on
autocmd BufRead *.py syntax off
However, when I then open up ...
-1
votes
1answer
89 views
Setting localleader
I've tried setting localleader using:
:let localleader="]"
And it seems to be 'working':
:let localleader
localleader ]
However, when I try and run a command using localleader, it doesn'...
1
vote
1answer
100 views
Fortran Syntax Highlighting detecting apostrophes as Strings
I am using VIM 7.4 with syntax highlighting on some Fortran77 source code. One comment has a single apostrophe that never is repeated/closed (eg * Bert's bees), causing the remaining source code to ...