Skip to main content
deleted 254 characters in body
Source Link
Nate Bosch
  • 258
  • 2
  • 9

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on cwdgetcwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd()``cwd` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[0], ':p:h')
  endif
  return cwdgetcwd()
endfunction!
let g:session_default_name =FindSessionDirectory= FindSessionDirectory()

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on cwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd()` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[0], ':p:h')
  endif
  return cwd()
endfunction!
let g:session_default_name =FindSessionDirectory()

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on getcwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[0], ':p:h')
  endif
  return getcwd()
endfunction!
let g:session_default_name = FindSessionDirectory()
added 1 character in body
Source Link
Nate Bosch
  • 258
  • 2
  • 9

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on cwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd()` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[][0], ':p:h')
  endif
  return cwd()
endfunction!
let g:session_default_name =FindSessionDirectory()

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on cwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd()` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[], ':p:h')
  endif
  return cwd()
endfunction!
let g:session_default_name =FindSessionDirectory()

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on cwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd()` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[0], ':p:h')
  endif
  return cwd()
endfunction!
let g:session_default_name =FindSessionDirectory()
added 363 characters in body
Source Link
Nate Bosch
  • 258
  • 2
  • 9

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on cwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd()` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[], ':p:h')
  endif
  return cwd()
endfunction!
let g:session_default_name =FindSessionDirectory()

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

If you want to get the directory that the currently open file is in: let g:session_default_name = expand('%:p:h'). This works whether vim is opened with to a file or not, but will only do what you expect if the file has not changed since vim was opened.

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened with no arguments.

To fallback on cwd() where there were no arguments:

" Returns the directory of the first file in `argv` or `cwd()` if it's empty
function FindSessionDirectory() abort
  if len(argv()) > 0
    return fnamemodify(argv()[], ':p:h')
  endif
  return cwd()
endfunction!
let g:session_default_name =FindSessionDirectory()
Source Link
Nate Bosch
  • 258
  • 2
  • 9
Loading